Bug 1160070 - Used BitmapBrush instead of ImageBrush when no sampling bounds. r=bas a=sledru
authorKyle Fung <kfung@mozilla.com>
Fri, 12 Jun 2015 17:28:25 -0400
changeset 275070 0af869625d14ccda1696e214f7e8224cc06f2f50
parent 275069 d5061d388ddc1977ae9f9e5c6dc70fb553f5f326
child 275071 624c93de3cd3cf2728df9a9bccbb6a82b18724f4
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbas, sledru
bugs1160070
milestone40.0a2
Bug 1160070 - Used BitmapBrush instead of ImageBrush when no sampling bounds. r=bas a=sledru
gfx/2d/DrawTargetD2D1.cpp
--- a/gfx/2d/DrawTargetD2D1.cpp
+++ b/gfx/2d/DrawTargetD2D1.cpp
@@ -1430,39 +1430,56 @@ DrawTargetD2D1::CreateBrushForPattern(co
     if (!pat->mSurface) {
       gfxDebug() << "No source surface specified for surface pattern";
       return CreateTransparentBlackBrush();
     }
 
     D2D1_RECT_F samplingBounds;
     Matrix mat = pat->mMatrix;
 
-    bool useSamplingRect = false;
-    if (!pat->mSamplingRect.IsEmpty() &&
-        (pat->mSurface->GetType() == SurfaceType::D2D1_1_IMAGE)) {
-      samplingBounds = D2DRect(pat->mSamplingRect);
-      mat.PreTranslate(pat->mSamplingRect.x, pat->mSamplingRect.y);
-    } else if (!pat->mSamplingRect.IsEmpty()) {
-      // We will do a partial upload of the sampling restricted area from GetImageForSurface.
-      samplingBounds = D2D1::RectF(0, 0, pat->mSamplingRect.width, pat->mSamplingRect.height);
-    } else {
-      samplingBounds = D2D1::RectF(0, 0,
-                                   Float(pat->mSurface->GetSize().width),
-                                   Float(pat->mSurface->GetSize().height));
-    }
-
     MOZ_ASSERT(pat->mSurface->IsValid());
 
-    RefPtr<ID2D1ImageBrush> imageBrush;
     RefPtr<ID2D1Image> image = GetImageForSurface(pat->mSurface, mat, pat->mExtendMode, !pat->mSamplingRect.IsEmpty() ? &pat->mSamplingRect : nullptr);
 
     if (!image) {
       return CreateTransparentBlackBrush();
     }
 
+    bool useSamplingRect = false;
+    if (pat->mSamplingRect.IsEmpty()) {
+      RefPtr<ID2D1Bitmap> bitmap;
+      image->QueryInterface((ID2D1Bitmap**)byRef(bitmap));
+      if (bitmap) {
+        RefPtr<ID2D1BitmapBrush> bitmapBrush;
+        mDC->CreateBitmapBrush(bitmap,
+                               D2D1::BitmapBrushProperties(D2DExtend(pat->mExtendMode),
+                                                           D2DExtend(pat->mExtendMode),
+                                                           D2DFilter(pat->mFilter)),
+                               D2D1::BrushProperties(aAlpha, D2DMatrix(mat)),
+                               byRef(bitmapBrush));
+        if (!bitmapBrush) {
+          gfxWarning() << "Couldn't create bitmap brush!";
+          return CreateTransparentBlackBrush();
+        }
+        return bitmapBrush.forget();
+      }
+    }
+
+    RefPtr<ID2D1ImageBrush> imageBrush;
+    if (pat->mSamplingRect.IsEmpty()) {
+      samplingBounds = D2D1::RectF(0, 0,
+                                   Float(pat->mSurface->GetSize().width),
+                                   Float(pat->mSurface->GetSize().height));
+    } else if (pat->mSurface->GetType() == SurfaceType::D2D1_1_IMAGE) {
+      samplingBounds = D2DRect(pat->mSamplingRect);
+      mat.PreTranslate(pat->mSamplingRect.x, pat->mSamplingRect.y);
+    } else {
+      // We will do a partial upload of the sampling restricted area from GetImageForSurface.
+      samplingBounds = D2D1::RectF(0, 0, pat->mSamplingRect.width, pat->mSamplingRect.height);
+    }
     mDC->CreateImageBrush(image,
                           D2D1::ImageBrushProperties(samplingBounds,
                                                      D2DExtend(pat->mExtendMode),
                                                      D2DExtend(pat->mExtendMode),
                                                      D2DInterpolationMode(pat->mFilter)),
                           D2D1::BrushProperties(aAlpha, D2DMatrix(mat)),
                           byRef(imageBrush));