Bug 1075616 - Do partial uploads of non-D2D SourceSurfaces when we have a sampling rect. r=Bas
authorMatt Woodrow <mwoodrow@mozilla.com>
Wed, 24 Sep 2014 13:23:15 -0400
changeset 208507 1b49657fad19bdf715df159e26ad1950b75eaa23
parent 208506 31b722e8e85d107b3c741d43301c1954fe2b8df1
child 208508 dd427eeb18eea0920ecdc30578a6f8af625e05e4
push id27585
push useremorley@mozilla.com
push dateFri, 03 Oct 2014 13:26:33 +0000
treeherderautoland@e4f5e843a370 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBas
bugs1075616
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1075616 - Do partial uploads of non-D2D SourceSurfaces when we have a sampling rect. r=Bas
gfx/2d/DrawTargetD2D.cpp
gfx/2d/HelpersD2D.h
--- a/gfx/2d/DrawTargetD2D.cpp
+++ b/gfx/2d/DrawTargetD2D.cpp
@@ -2362,17 +2362,19 @@ DrawTargetD2D::CreateBrushForPattern(con
     }
 
     RefPtr<ID2D1Bitmap> bitmap;
 
     Matrix mat = pat->mMatrix;
 
     RefPtr<SourceSurface> source = pat->mSurface;
 
-    if (!pat->mSamplingRect.IsEmpty()) {
+    if (!pat->mSamplingRect.IsEmpty() &&
+        (source->GetType() == SurfaceType::D2D1_BITMAP ||
+         source->GetType() == SurfaceType::D2D1_DRAWTARGET)) {
       IntRect samplingRect = pat->mSamplingRect;
 
       RefPtr<DrawTargetD2D> dt = new DrawTargetD2D();
       if (!dt->Init(samplingRect.Size(),
                     source->GetFormat())) {
         MOZ_ASSERT("Invalid sampling rect size!");
         return nullptr;
       }
@@ -2406,17 +2408,22 @@ DrawTargetD2D::CreateBrushForPattern(con
     default:
       {
         RefPtr<DataSourceSurface> dataSurf = source->GetDataSurface();
         if (!dataSurf) {
           gfxWarning() << "Invalid surface type.";
           return nullptr;
         }
 
-        bitmap = CreatePartialBitmapForSurface(dataSurf, mTransform, mSize, pat->mExtendMode, mat, mRT); 
+        IntRect sourceRect = pat->mSamplingRect;
+        if (sourceRect.IsEmpty()) {
+          sourceRect = IntRect(0, 0, source->GetSize().width, source->GetSize().height);
+        }
+
+        bitmap = CreatePartialBitmapForSurface(dataSurf, mTransform, mSize, pat->mExtendMode, mat, mRT, &sourceRect);
         if (!bitmap) {
           return nullptr;
         }
       }
       break;
     }
     
     mRT->CreateBitmapBrush(bitmap,
--- a/gfx/2d/HelpersD2D.h
+++ b/gfx/2d/HelpersD2D.h
@@ -508,17 +508,18 @@ CreateStrokeStyleForOptions(const Stroke
 }
 
 // This creates a (partially) uploaded bitmap for a DataSourceSurface. It
 // uploads the minimum requirement and possibly downscales. It adjusts the
 // input Matrix to compensate.
 static TemporaryRef<ID2D1Bitmap>
 CreatePartialBitmapForSurface(DataSourceSurface *aSurface, const Matrix &aDestinationTransform,
                               const IntSize &aDestinationSize, ExtendMode aExtendMode,
-                              Matrix &aSourceTransform, ID2D1RenderTarget *aRT)
+                              Matrix &aSourceTransform, ID2D1RenderTarget *aRT,
+                              const IntRect* aSourceRect = nullptr)
 {
   RefPtr<ID2D1Bitmap> bitmap;
 
   // This is where things get complicated. The source surface was
   // created for a surface that was too large to fit in a texture.
   // We'll need to figure out if we can work with a partial upload
   // or downsample in software.
 
@@ -533,16 +534,19 @@ CreatePartialBitmapForSurface(DataSource
 
   // Calculate the rectangle of the source mapped to our surface.
   rect = invTransform.TransformBounds(rect);
   rect.RoundOut();
 
   IntSize size = aSurface->GetSize();
 
   Rect uploadRect(0, 0, Float(size.width), Float(size.height));
+  if (aSourceRect) {
+    uploadRect = Rect(aSourceRect->x, aSourceRect->y, aSourceRect->width, aSourceRect->height);
+  }
 
   // Limit the uploadRect as much as possible without supporting discontiguous uploads 
   //
   //                               region we will paint from
   //   uploadRect
   //   .---------------.              .---------------.         resulting uploadRect
   //   |               |rect          |               |
   //   |          .---------.         .----.     .----.          .---------------.