Bug 1279628, part 2 - Switch all but one of the gfxASurface::CheckSurfaceSize calls to call Factory::CheckSurfaceSize. r=mstange
authorJonathan Watt <jwatt@jwatt.org>
Fri, 10 Jun 2016 13:32:01 +0100
changeset 341658 56154813d29d7b56d2039fc3a3c80f27c0a4571f
parent 341657 a643f56f7523bf90d726c354aa714a6372aed92d
child 341659 47c5f6b6fc0f3c6cefca9d04e9181ab08ed6dbc7
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1279628
milestone50.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 1279628, part 2 - Switch all but one of the gfxASurface::CheckSurfaceSize calls to call Factory::CheckSurfaceSize. r=mstange
dom/canvas/CanvasRenderingContext2D.cpp
dom/canvas/CanvasRenderingContext2D.h
dom/canvas/nsICanvasRenderingContextInternal.h
gfx/thebes/gfxBaseSharedMemorySurface.h
gfx/thebes/gfxImageSurface.cpp
gfx/thebes/gfxQuartzSurface.cpp
gfx/thebes/gfxWindowsSurface.cpp
gfx/thebes/gfxXlibSurface.cpp
layout/svg/nsSVGUtils.cpp
layout/svg/nsSVGUtils.h
widget/gtk/nsDragService.cpp
widget/gtk/nsWindow.h
widget/nsIDeviceContextSpec.h
widget/uikit/nsWindow.h
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -5109,17 +5109,17 @@ CanvasRenderingContext2D::AsyncDrawXULEl
     }
 
     return DrawWindow(window->GetCurrentInnerWindow(), aX, aY, aW, aH,
                       aBgColor, aFlags);
   }
 
   // protect against too-large surfaces that will cause allocation
   // or overflow issues
-  if (!gfxASurface::CheckSurfaceSize(gfx::IntSize(aW, aH), 0xffff)) {
+  if (!Factory::CheckSurfaceSize(IntSize(aW, aH), 0xffff)) {
     aError.Throw(NS_ERROR_FAILURE);
     return;
   }
 
   bool flush =
     (aFlags & nsIDOMCanvasRenderingContext2D::DRAWWINDOW_DO_NOT_FLUSH) == 0;
 
   uint32_t renderDocFlags = nsIPresShell::RENDER_IGNORE_VIEWPORT_SCROLLING;
--- a/dom/canvas/CanvasRenderingContext2D.h
+++ b/dom/canvas/CanvasRenderingContext2D.h
@@ -756,20 +756,16 @@ protected:
 
   /**
    * Flag to avoid unnecessary surface copies to FrameCaptureListeners in the
    * case when the canvas is not currently being drawn into and not rendered
    * but canvas capturing is still ongoing.
    */
   bool mIsCapturedFrameInvalid;
 
-  // This is stored after GetThebesSurface has been called once to avoid
-  // excessive ThebesSurface initialization overhead.
-  RefPtr<gfxASurface> mThebesSurface;
-
   /**
     * We also have a device space pathbuilder. The reason for this is as
     * follows, when a path is being built, but the transform changes, we
     * can no longer keep a single path in userspace, considering there's
     * several 'user spaces' now. We therefore transform the current path
     * into device space, and add all operations to this path in device
     * space.
     *
--- a/dom/canvas/nsICanvasRenderingContextInternal.h
+++ b/dom/canvas/nsICanvasRenderingContextInternal.h
@@ -15,17 +15,16 @@
 #include "mozilla/dom/OffscreenCanvas.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/UniquePtr.h"
 
 #define NS_ICANVASRENDERINGCONTEXTINTERNAL_IID \
 { 0xb84f2fed, 0x9d4b, 0x430b, \
   { 0xbd, 0xfb, 0x85, 0x57, 0x8a, 0xc2, 0xb4, 0x4b } }
 
-class gfxASurface;
 class nsDisplayListBuilder;
 
 namespace mozilla {
 namespace layers {
 class CanvasLayer;
 class Layer;
 class LayerManager;
 } // namespace layers
--- a/gfx/thebes/gfxBaseSharedMemorySurface.h
+++ b/gfx/thebes/gfxBaseSharedMemorySurface.h
@@ -2,16 +2,17 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_SHARED_MEMORYSURFACE_H
 #define GFX_SHARED_MEMORYSURFACE_H
 
+#include "mozilla/gfx/2D.h"
 #include "mozilla/ipc/Shmem.h"
 #include "mozilla/ipc/SharedMemory.h"
 
 #include "gfxASurface.h"
 #include "gfxImageSurface.h"
 #include "pratom.h"
 
 typedef struct _cairo_user_data_key cairo_user_data_key_t;
@@ -69,17 +70,17 @@ public:
      * if an attempt is made to wrap any other shmem segment.  Null is
      * returned if creating the surface failed.
      */
     static already_AddRefed<Sub>
     Open(const Shmem& aShmem)
     {
         SharedImageInfo* shmInfo = GetShmInfoPtr(aShmem);
         mozilla::gfx::IntSize size(shmInfo->width, shmInfo->height);
-        if (!gfxASurface::CheckSurfaceSize(size))
+        if (!mozilla::gfx::Factory::CheckSurfaceSize(size))
             return nullptr;
 
         gfxImageFormat format = shmInfo->format;
         long stride = gfxImageSurface::ComputeStride(size, format);
 
         RefPtr<Sub> s =
             new Sub(size,
                     stride,
@@ -159,17 +160,17 @@ private:
 
     template<class ShmemAllocator, bool Unsafe>
     static already_AddRefed<Sub>
     Create(ShmemAllocator* aAllocator,
            const mozilla::gfx::IntSize& aSize,
            gfxImageFormat aFormat,
            SharedMemory::SharedMemoryType aShmType)
     {
-        if (!gfxASurface::CheckSurfaceSize(aSize))
+        if (!mozilla::gfx::Factory::CheckSurfaceSize(aSize))
             return nullptr;
 
         Shmem shmem;
         long stride = gfxImageSurface::ComputeStride(aSize, aFormat);
         size_t size = GetAlignedSize(aSize, stride);
         if (!Unsafe) {
             if (!aAllocator->AllocShmem(size, aShmType, &shmem))
                 return nullptr;
--- a/gfx/thebes/gfxImageSurface.cpp
+++ b/gfx/thebes/gfxImageSurface.cpp
@@ -64,17 +64,17 @@ gfxImageSurface::InitWithData(unsigned c
                               long aStride, gfxImageFormat aFormat)
 {
     mSize = aSize;
     mOwnsData = false;
     mData = aData;
     mFormat = aFormat;
     mStride = aStride;
 
-    if (!CheckSurfaceSize(aSize))
+    if (!Factory::CheckSurfaceSize(aSize))
         MakeInvalid();
 
     cairo_format_t cformat = GfxFormatToCairoFormat(mFormat);
     cairo_surface_t *surface =
         cairo_image_surface_create_for_data((unsigned char*)mData,
                                             cformat,
                                             mSize.width,
                                             mSize.height,
@@ -120,17 +120,17 @@ gfxImageSurface::AllocateAndInit(long aS
     MOZ_ASSERT(!mData);
     mData = nullptr;
     mOwnsData = false;
 
     mStride = aStride > 0 ? aStride : ComputeStride();
     if (aMinimalAllocation < mSize.height * mStride)
         aMinimalAllocation = mSize.height * mStride;
 
-    if (!CheckSurfaceSize(mSize))
+    if (!Factory::CheckSurfaceSize(mSize))
         MakeInvalid();
 
     // if we have a zero-sized surface, just leave mData nullptr
     if (mSize.height * mStride > 0) {
 
         // This can fail to allocate memory aligned as we requested,
         // or it can fail to allocate any memory at all.
         mData = (unsigned char *) TryAllocAlignedBytes(aMinimalAllocation);
--- a/gfx/thebes/gfxQuartzSurface.cpp
+++ b/gfx/thebes/gfxQuartzSurface.cpp
@@ -1,31 +1,32 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "gfxQuartzSurface.h"
 #include "gfxContext.h"
 #include "gfxImageSurface.h"
+#include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/HelpersCairo.h"
 
 #include "cairo-quartz.h"
 
 void
 gfxQuartzSurface::MakeInvalid()
 {
     mSize = mozilla::gfx::IntSize(-1, -1);
 }
 
 gfxQuartzSurface::gfxQuartzSurface(const mozilla::gfx::IntSize& desiredSize,
                                    gfxImageFormat format)
     : mCGContext(nullptr), mSize(desiredSize)
 {
-    if (!CheckSurfaceSize(desiredSize))
+    if (!mozilla::gfx::Factory::CheckSurfaceSize(desiredSize))
         MakeInvalid();
 
     unsigned int width = static_cast<unsigned int>(mSize.width);
     unsigned int height = static_cast<unsigned int>(mSize.height);
 
     cairo_format_t cformat = GfxFormatToCairoFormat(format);
     cairo_surface_t *surf = cairo_quartz_surface_create(cformat, width, height);
 
@@ -38,17 +39,17 @@ gfxQuartzSurface::gfxQuartzSurface(const
       RecordMemoryUsed(mSize.height * 4 + sizeof(gfxQuartzSurface));
     }
 }
 
 gfxQuartzSurface::gfxQuartzSurface(CGContextRef context,
                                    const mozilla::gfx::IntSize& size)
     : mCGContext(context), mSize(size)
 {
-    if (!CheckSurfaceSize(size))
+    if (!mozilla::gfx::Factory::CheckSurfaceSize(size))
         MakeInvalid();
 
     unsigned int width = static_cast<unsigned int>(mSize.width);
     unsigned int height = static_cast<unsigned int>(mSize.height);
 
     cairo_surface_t *surf = 
         cairo_quartz_surface_create_for_cg_context(context,
                                                    width, height);
@@ -72,17 +73,17 @@ gfxQuartzSurface::gfxQuartzSurface(cairo
 }
 
 gfxQuartzSurface::gfxQuartzSurface(unsigned char *data,
                                    const mozilla::gfx::IntSize& aSize,
                                    long stride,
                                    gfxImageFormat format)
     : mCGContext(nullptr), mSize(aSize.width, aSize.height)
 {
-    if (!CheckSurfaceSize(aSize))
+    if (!mozilla::gfx::Factory::CheckSurfaceSize(aSize))
         MakeInvalid();
 
     cairo_format_t cformat = GfxFormatToCairoFormat(format);
     cairo_surface_t *surf = cairo_quartz_surface_create_for_data
         (data, cformat, aSize.width, aSize.height, stride);
 
     mCGContext = cairo_quartz_surface_get_cg_context (surf);
 
--- a/gfx/thebes/gfxWindowsSurface.cpp
+++ b/gfx/thebes/gfxWindowsSurface.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "gfxWindowsSurface.h"
 #include "gfxContext.h"
 #include "gfxPlatform.h"
+#include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/HelpersCairo.h"
 #include "mozilla/gfx/Logging.h"
 
 #include "cairo.h"
 #include "cairo-win32.h"
 
 #include "nsString.h"
 
@@ -45,17 +46,17 @@ gfxWindowsSurface::MakeInvalid(mozilla::
 {
     size = mozilla::gfx::IntSize(-1, -1);
 }
 
 gfxWindowsSurface::gfxWindowsSurface(const mozilla::gfx::IntSize& realSize, gfxImageFormat imageFormat) :
     mOwnsDC(false), mForPrinting(false), mWnd(nullptr)
 {
     mozilla::gfx::IntSize size(realSize);
-    if (!CheckSurfaceSize(size))
+    if (!mozilla::gfx::Factory::CheckSurfaceSize(size))
         MakeInvalid(size);
 
     cairo_format_t cformat = GfxFormatToCairoFormat(imageFormat);
     cairo_surface_t *surf =
         cairo_win32_surface_create_with_dib(cformat, size.width, size.height);
 
     Init(surf);
 
--- a/gfx/thebes/gfxXlibSurface.cpp
+++ b/gfx/thebes/gfxXlibSurface.cpp
@@ -9,21 +9,23 @@
 #include "cairo-xlib.h"
 #include "cairo-xlib-xrender.h"
 #include <X11/Xlibint.h>  /* For XESetCloseDisplay */
 #undef max // Xlibint.h defines this and it breaks std::max
 #undef min // Xlibint.h defines this and it breaks std::min
 
 #include "nsTArray.h"
 #include "nsAlgorithm.h"
+#include "mozilla/gfx/2D.h"
 #include "mozilla/Preferences.h"
 #include <algorithm>
 #include "mozilla/CheckedInt.h"
 
 using namespace mozilla;
+using namespace mozilla::gfx;
 
 gfxXlibSurface::gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual)
     : mPixmapTaken(false), mDisplay(dpy), mDrawable(drawable)
 #if defined(GL_PROVIDER_GLX)
     , mGLXPixmap(None)
 #endif
 {
     const gfx::IntSize size = DoSizeQuery();
@@ -32,32 +34,32 @@ gfxXlibSurface::gfxXlibSurface(Display *
 }
 
 gfxXlibSurface::gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual, const gfx::IntSize& size)
     : mPixmapTaken(false), mDisplay(dpy), mDrawable(drawable)
 #if defined(GL_PROVIDER_GLX)
     , mGLXPixmap(None)
 #endif
 {
-    NS_ASSERTION(CheckSurfaceSize(size, XLIB_IMAGE_SIDE_SIZE_LIMIT),
+    NS_ASSERTION(Factory::CheckSurfaceSize(size, XLIB_IMAGE_SIDE_SIZE_LIMIT),
                  "Bad size");
 
     cairo_surface_t *surf = cairo_xlib_surface_create(dpy, drawable, visual, size.width, size.height);
     Init(surf);
 }
 
 gfxXlibSurface::gfxXlibSurface(Screen *screen, Drawable drawable, XRenderPictFormat *format,
                                const gfx::IntSize& size)
     : mPixmapTaken(false), mDisplay(DisplayOfScreen(screen)),
       mDrawable(drawable)
 #if defined(GL_PROVIDER_GLX)
       , mGLXPixmap(None)
 #endif
 {
-    NS_ASSERTION(CheckSurfaceSize(size, XLIB_IMAGE_SIDE_SIZE_LIMIT),
+    NS_ASSERTION(Factory::CheckSurfaceSize(size, XLIB_IMAGE_SIDE_SIZE_LIMIT),
                  "Bad Size");
 
     cairo_surface_t *surf =
         cairo_xlib_surface_create_with_xrender_format(mDisplay, drawable,
                                                       screen, format,
                                                       size.width, size.height);
     Init(surf);
 }
@@ -89,17 +91,17 @@ gfxXlibSurface::~gfxXlibSurface()
         XFreePixmap (mDisplay, mDrawable);
     }
 }
 
 static Drawable
 CreatePixmap(Screen *screen, const gfx::IntSize& size, unsigned int depth,
              Drawable relatedDrawable)
 {
-    if (!gfxASurface::CheckSurfaceSize(size, XLIB_IMAGE_SIDE_SIZE_LIMIT))
+    if (!Factory::CheckSurfaceSize(size, XLIB_IMAGE_SIDE_SIZE_LIMIT))
         return None;
 
     if (relatedDrawable == None) {
         relatedDrawable = RootWindowOfScreen(screen);
     }
     Display *dpy = DisplayOfScreen(screen);
     // X gives us a fatal error if we try to create a pixmap of width
     // or height 0
--- a/layout/svg/nsSVGUtils.cpp
+++ b/layout/svg/nsSVGUtils.cpp
@@ -847,17 +847,17 @@ IntSize
 nsSVGUtils::ConvertToSurfaceSize(const gfxSize& aSize,
                                  bool *aResultOverflows)
 {
   IntSize surfaceSize(ClampToInt(ceil(aSize.width)), ClampToInt(ceil(aSize.height)));
 
   *aResultOverflows = surfaceSize.width != ceil(aSize.width) ||
     surfaceSize.height != ceil(aSize.height);
 
-  if (!gfxASurface::CheckSurfaceSize(surfaceSize)) {
+  if (!Factory::CheckSurfaceSize(surfaceSize)) {
     surfaceSize.width = std::min(NS_SVG_OFFSCREEN_MAX_DIMENSION,
                                surfaceSize.width);
     surfaceSize.height = std::min(NS_SVG_OFFSCREEN_MAX_DIMENSION,
                                 surfaceSize.height);
     *aResultOverflows = true;
   }
 
   return surfaceSize;
--- a/layout/svg/nsSVGUtils.h
+++ b/layout/svg/nsSVGUtils.h
@@ -55,17 +55,17 @@ class UserSpaceMetrics;
 namespace gfx {
 class DrawTarget;
 class GeneralPattern;
 } // namespace gfx
 } // namespace mozilla
 
 // maximum dimension of an offscreen surface - choose so that
 // the surface size doesn't overflow a 32-bit signed int using
-// 4 bytes per pixel; in line with gfxASurface::CheckSurfaceSize
+// 4 bytes per pixel; in line with Factory::CheckSurfaceSize
 // In fact Macs can't even manage that
 #define NS_SVG_OFFSCREEN_MAX_DIMENSION 4096
 
 #define SVG_HIT_TEST_FILL        0x01
 #define SVG_HIT_TEST_STROKE      0x02
 #define SVG_HIT_TEST_CHECK_MRECT 0x04
 
 
--- a/widget/gtk/nsDragService.cpp
+++ b/widget/gtk/nsDragService.cpp
@@ -21,17 +21,16 @@
 #include "prthread.h"
 #include <dlfcn.h>
 #include <gtk/gtk.h>
 #include <gdk/gdkx.h>
 #include "nsCRT.h"
 #include "mozilla/BasicEvents.h"
 #include "mozilla/Services.h"
 
-#include "gfxASurface.h"
 #include "gfxXlibSurface.h"
 #include "gfxContext.h"
 #include "nsImageToPixbuf.h"
 #include "nsPresContext.h"
 #include "nsIContent.h"
 #include "nsIDocument.h"
 #include "nsISelection.h"
 #include "nsViewManager.h"
--- a/widget/gtk/nsWindow.h
+++ b/widget/gtk/nsWindow.h
@@ -55,17 +55,16 @@ extern PRLogModuleInfo *gWidgetDrawLog;
 
 #define LOG(args)
 #define LOGFOCUS(args)
 #define LOGDRAG(args)
 #define LOGDRAW(args)
 
 #endif /* MOZ_LOGGING */
 
-class gfxASurface;
 class gfxPattern;
 class nsPluginNativeWindowGtk;
 
 namespace mozilla {
 class TimeStamp;
 class CurrentX11TimeGetter;
 }
 
--- a/widget/nsIDeviceContextSpec.h
+++ b/widget/nsIDeviceContextSpec.h
@@ -5,17 +5,16 @@
 
 #ifndef nsIDeviceContextSpec_h___
 #define nsIDeviceContextSpec_h___
 
 #include "nsISupports.h"
 
 class nsIWidget;
 class nsIPrintSettings;
-class gfxASurface;
 
 namespace mozilla {
 namespace gfx{
 class DrawEventRecorder;
 class PrintTarget;
 }
 }
 
--- a/widget/uikit/nsWindow.h
+++ b/widget/uikit/nsWindow.h
@@ -9,17 +9,16 @@
 #include "nsBaseWidget.h"
 #include "gfxPoint.h"
 
 #include "nsTArray.h"
 
 @class UIWindow;
 @class UIView;
 @class ChildView;
-class gfxASurface;
 
 class nsWindow :
     public nsBaseWidget
 {
     typedef nsBaseWidget Inherited;
 
 public:
     nsWindow();