Bug 1294586 - Remove dependency on gfxPlatform from CreateDrawTargetFromData. r=dvander
authorRyan Hunt <rhunt@mozilla.com>
Thu, 11 Aug 2016 14:54:08 -0700
changeset 335035 d1bcccf544c4e1e3cc7cba663e2c7d23a6918299
parent 335034 2fff8cb618fc6ced1558334f7e73d2a8799b172c
child 335036 2d9db497958da73d5b3f06ded571d233f6ba7575
push id10033
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:50:26 +0000
treeherdermozilla-aurora@5dddbefdf759 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdvander
bugs1294586
milestone51.0a1
Bug 1294586 - Remove dependency on gfxPlatform from CreateDrawTargetFromData. r=dvander MozReview-Commit-ID: A355fBJKWP6
gfx/layers/basic/BasicImages.cpp
gfx/layers/d3d9/TextureD3D9.cpp
gfx/layers/opengl/GrallocTextureClient.cpp
gfx/thebes/gfxBlur.cpp
gfx/thebes/gfxPlatform.cpp
gfx/thebes/gfxPlatform.h
image/imgFrame.cpp
widget/gtk/WindowSurfaceX11Image.cpp
widget/gtk/nsDragService.cpp
widget/gtk/nsWindow.cpp
widget/nsShmImage.cpp
--- a/gfx/layers/basic/BasicImages.cpp
+++ b/gfx/layers/basic/BasicImages.cpp
@@ -141,20 +141,20 @@ BasicPlanarYCbCrImage::GetAsSourceSurfac
   gfxImageFormat format = GetOffscreenFormat();
 
   RefPtr<gfx::SourceSurface> surface;
   {
     // Create a DrawTarget so that we can own the data inside mDecodeBuffer.
     // We create the target out of mDecodedBuffer, and get a snapshot from it.
     // The draw target is destroyed on scope exit and the surface owns the data.
     RefPtr<gfx::DrawTarget> drawTarget
-      = gfxPlatform::GetPlatform()->CreateDrawTargetForData(mDecodedBuffer.get(),
-                                                            mSize,
-                                                            mStride,
-                                                            gfx::ImageFormatToSurfaceFormat(format));
+      = gfxPlatform::CreateDrawTargetForData(mDecodedBuffer.get(),
+                                             mSize,
+                                             mStride,
+                                             gfx::ImageFormatToSurfaceFormat(format));
     if (!drawTarget) {
       return nullptr;
     }
 
     surface = drawTarget->Snapshot();
   }
 
   mRecycleBin->RecycleBuffer(Move(mDecodedBuffer), mSize.height * mStride);
--- a/gfx/layers/d3d9/TextureD3D9.cpp
+++ b/gfx/layers/d3d9/TextureD3D9.cpp
@@ -670,17 +670,17 @@ D3D9TextureData::BorrowDrawTarget()
     // windows surface optimization.
     // Instead we have to use a gfxImageSurface and fallback for font drawing.
     D3DLOCKED_RECT rect;
     HRESULT hr = mD3D9Surface->LockRect(&rect, nullptr, 0);
     if (FAILED(hr) || !rect.pBits) {
       gfxCriticalError() << "Failed to lock rect borrowing the target in D3D9 (BDT) " << hexa(hr);
       return nullptr;
     }
-    dt = gfxPlatform::GetPlatform()->CreateDrawTargetForData((uint8_t*)rect.pBits, mSize,
+    dt = gfxPlatform::CreateDrawTargetForData((uint8_t*)rect.pBits, mSize,
                                                              rect.Pitch, mFormat);
     if (!dt) {
       return nullptr;
     }
 
      mLockRect = true;
   }
 
--- a/gfx/layers/opengl/GrallocTextureClient.cpp
+++ b/gfx/layers/opengl/GrallocTextureClient.cpp
@@ -219,18 +219,18 @@ GrallocTextureData::Unlock()
 already_AddRefed<gfx::DrawTarget>
 GrallocTextureData::BorrowDrawTarget()
 {
   MOZ_ASSERT(mMappedBuffer);
   if (!mMappedBuffer) {
     return nullptr;
   }
   long byteStride = mGraphicBuffer->getStride() * BytesPerPixel(mFormat);
-  return gfxPlatform::GetPlatform()->CreateDrawTargetForData(mMappedBuffer, mSize,
-                                                             byteStride, mFormat);
+  return gfxPlatform::CreateDrawTargetForData(mMappedBuffer, mSize,
+                                              byteStride, mFormat);
 }
 
 bool
 GrallocTextureData::BorrowMappedData(MappedTextureData& aMap)
 {
   if (mFormat == gfx::SurfaceFormat::YUV || !mMappedBuffer) {
     return false;
   }
--- a/gfx/thebes/gfxBlur.cpp
+++ b/gfx/thebes/gfxBlur.cpp
@@ -66,19 +66,19 @@ gfxAlphaBoxBlur::Init(const gfxRect& aRe
     // everything is drawn to create a blur effect.
     mData = MakeUniqueFallible<unsigned char[]>(blurDataSize);
     if (!mData) {
         return nullptr;
     }
     memset(mData.get(), 0, blurDataSize);
 
     RefPtr<DrawTarget> dt =
-        gfxPlatform::GetPlatform()->CreateDrawTargetForData(mData.get(), size,
-                                                            mBlur->GetStride(),
-                                                            SurfaceFormat::A8);
+        gfxPlatform::CreateDrawTargetForData(mData.get(), size,
+                                             mBlur->GetStride(),
+                                             SurfaceFormat::A8);
     if (!dt || !dt->IsValid()) {
         return nullptr;
     }
 
     IntRect irect = mBlur->GetRect();
     gfxPoint topleft(irect.TopLeft().x, irect.TopLeft().y);
 
     mContext = gfxContext::CreateOrNull(dt);
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -1421,24 +1421,23 @@ gfxPlatform::CreateSimilarSoftwareDrawTa
     dt = aDT->CreateSimilarDrawTarget(aSize, aFormat);
   } else {
     dt = Factory::CreateDrawTarget(BackendType::SKIA, aSize, aFormat);
   }
 
   return dt.forget();
 }
 
-already_AddRefed<DrawTarget>
+/* static */ already_AddRefed<DrawTarget>
 gfxPlatform::CreateDrawTargetForData(unsigned char* aData, const IntSize& aSize, int32_t aStride, SurfaceFormat aFormat)
 {
-  NS_ASSERTION(mContentBackend != BackendType::NONE, "No backend.");
+  BackendType backendType = gfxVars::ContentBackend();
+  NS_ASSERTION(backendType != BackendType::NONE, "No backend.");
 
-  BackendType backendType = mContentBackend;
-
-  if (!Factory::DoesBackendSupportDataDrawtarget(mContentBackend)) {
+  if (!Factory::DoesBackendSupportDataDrawtarget(backendType)) {
     backendType = BackendType::CAIRO;
   }
 
   RefPtr<DrawTarget> dt = Factory::CreateDrawTargetForData(backendType,
                                                            aData, aSize,
                                                            aStride, aFormat);
 
   return dt.forget();
--- a/gfx/thebes/gfxPlatform.h
+++ b/gfx/thebes/gfxPlatform.h
@@ -231,17 +231,17 @@ public:
       CreateOffscreenContentDrawTarget(const mozilla::gfx::IntSize& aSize, mozilla::gfx::SurfaceFormat aFormat);
 
     already_AddRefed<DrawTarget>
       CreateOffscreenCanvasDrawTarget(const mozilla::gfx::IntSize& aSize, mozilla::gfx::SurfaceFormat aFormat);
 
     already_AddRefed<DrawTarget>
       CreateSimilarSoftwareDrawTarget(DrawTarget* aDT, const IntSize &aSize, mozilla::gfx::SurfaceFormat aFormat);
 
-    virtual already_AddRefed<DrawTarget>
+    static already_AddRefed<DrawTarget>
       CreateDrawTargetForData(unsigned char* aData, const mozilla::gfx::IntSize& aSize, 
                               int32_t aStride, mozilla::gfx::SurfaceFormat aFormat);
 
     /**
      * Returns true if rendering to data surfaces produces the same results as
      * rendering to offscreen surfaces on this platform, making it safe to
      * render content to data surfaces. This is generally false on platforms
      * which use different backends for each type of DrawTarget.
--- a/image/imgFrame.cpp
+++ b/image/imgFrame.cpp
@@ -319,18 +319,21 @@ imgFrame::InitWithDrawable(gfxDrawable* 
     }
 
     if (!ClearSurface(mVBuf, mFrameRect.Size(), mFormat)) {
       NS_WARNING("Could not clear allocated buffer");
       mAborted = true;
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
-    target = gfxPlatform::GetPlatform()->
-      CreateDrawTargetForData(ptr, mFrameRect.Size(), stride, mFormat);
+    target = gfxPlatform::CreateDrawTargetForData(
+                            ptr,
+                            mFrameRect.Size(),
+                            stride,
+                            mFormat);
   } else {
     // We can't use data surfaces for content, so we'll create an offscreen
     // surface instead.  This means if someone later calls RawAccessRef(), we
     // may have to do an expensive readback, but we warned callers about that in
     // the documentation for this method.
     MOZ_ASSERT(!mOptSurface, "Called imgFrame::InitWithDrawable() twice?");
 
     target = gfxPlatform::GetPlatform()->
--- a/widget/gtk/WindowSurfaceX11Image.cpp
+++ b/widget/gtk/WindowSurfaceX11Image.cpp
@@ -47,20 +47,20 @@ WindowSurfaceX11Image::Lock(const Layout
                           data, size.width, size.height,
                           8 * gfx::BytesPerPixel(mFormat), stride);
   }
 
   if (!mImage)
     return nullptr;
 
   unsigned char* data = (unsigned char*) mImage->data;
-  return gfxPlatform::GetPlatform()->CreateDrawTargetForData(data,
-                                                             size,
-                                                             mImage->bytes_per_line,
-                                                             mFormat);
+  return gfxPlatform::CreateDrawTargetForData(data,
+                                              size,
+                                              mImage->bytes_per_line,
+                                              mFormat);
 }
 
 void
 WindowSurfaceX11Image::CommitToDrawable(Drawable aDest, GC aGC,
                                         const LayoutDeviceIntRegion& aInvalidRegion)
 {
   MOZ_ASSERT(mImage, "Attempted to commit invalid surface!");
 
--- a/widget/gtk/nsDragService.cpp
+++ b/widget/gtk/nsDragService.cpp
@@ -474,18 +474,18 @@ nsDragService::SetAlphaPixmap(SourceSurf
 
     // TODO: grab X11 pixmap or image data instead of expensive readback.
     cairo_surface_t *surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
                                                        dragRect.width,
                                                        dragRect.height);
     if (!surf)
         return false;
 
-    RefPtr<DrawTarget> dt = gfxPlatform::GetPlatform()->
-        CreateDrawTargetForData(cairo_image_surface_get_data(surf),
+    RefPtr<DrawTarget> dt = gfxPlatform::CreateDrawTargetForData(
+                                cairo_image_surface_get_data(surf),
                                 dragRect.Size(),
                                 cairo_image_surface_get_stride(surf),
                                 SurfaceFormat::B8G8R8A8);
     if (!dt)
         return false;
 
     dt->ClearRect(Rect(0, 0, dragRect.width, dragRect.height));
     dt->DrawSurface(aSurface,
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -2384,19 +2384,20 @@ nsWindow::UpdateAlpha(SourceSurface* aSo
 {
     // We need to create our own buffer to force the stride to match the
     // expected stride.
     int32_t stride = GetAlignedStride<4>(BytesPerPixel(SurfaceFormat::A8) *
                                          aBoundsRect.width);
     int32_t bufferSize = stride * aBoundsRect.height;
     auto imageBuffer = MakeUniqueFallible<uint8_t[]>(bufferSize);
     {
-        RefPtr<DrawTarget> drawTarget = gfxPlatform::GetPlatform()->
-            CreateDrawTargetForData(imageBuffer.get(), aBoundsRect.Size(),
-                                    stride, SurfaceFormat::A8);
+        RefPtr<DrawTarget> drawTarget = gfxPlatform::CreateDrawTargetForData(
+                                              imageBuffer.get(),
+                                              aBoundsRect.Size(),
+                                              stride, SurfaceFormat::A8);
 
         if (drawTarget) {
             drawTarget->DrawSurface(aSourceSurface, Rect(0, 0, aBoundsRect.width, aBoundsRect.height),
                                     Rect(0, 0, aSourceSurface->GetSize().width, aSourceSurface->GetSize().height),
                                     DrawSurfaceOptions(SamplingFilter::POINT),
                                     DrawOptions(1.0f, CompositionOp::OP_SOURCE));
         }
     }
--- a/widget/nsShmImage.cpp
+++ b/widget/nsShmImage.cpp
@@ -269,17 +269,17 @@ nsShmImage::CreateDrawTarget(const mozil
   IntSize size(bounds.XMost(), bounds.YMost());
   if (size.width > mSize.width || size.height > mSize.height) {
     DestroyImage();
     if (!CreateImage(size)) {
       return nullptr;
     }
   }
 
-  return gfxPlatform::GetPlatform()->CreateDrawTargetForData(
+  return gfxPlatform::CreateDrawTargetForData(
     reinterpret_cast<unsigned char*>(mShmAddr)
       + BytesPerPixel(mFormat) * (bounds.y * mSize.width + bounds.x),
     bounds.Size(),
     BytesPerPixel(mFormat) * mSize.width,
     mFormat);
 }
 
 void