diff --git a/gfx/2d/DrawTargetD2D1.cpp b/gfx/2d/DrawTargetD2D1.cpp index 4a402cc6c886..b543bb0f94f7 100644 --- a/gfx/2d/DrawTargetD2D1.cpp +++ b/gfx/2d/DrawTargetD2D1.cpp @@ -1453,29 +1453,46 @@ DrawTargetD2D1::CreateBrushForPattern(const Pattern &aPattern, Float aAlpha) 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 imageBrush; RefPtr 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 bitmap; + image->QueryInterface((ID2D1Bitmap**)byRef(bitmap)); + if (bitmap) { + RefPtr 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 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),