For now, our GfxSurfaceType enum (and things depending on it) is tightly
coupled to cairo_surface_type_t, which is bad for encapsulation. And we're
also tightly coupled to the current, meanwhile pretty old and customized
in-tree version of cairo.

To reduce maintenance burden and as a first step towards using future
use of external cairo, decouple these types. The overhead is minimal:
gfxASurface::GetType() now uses a small switch statement (compilers have
many ways for good optimizations), and the function doesn't seem to
be a hot path.

Note that this patch also drops values that aren't used by mozilla.
Also fix the value for invalid surface type: some sites used -1, while
others used Max.

Alternative options could be:

* directly alias it to cairo_surface_t (and also for similar enums)
  pro: less code
  con: more coupled to cairo api
  * only makes sense of we do it for other enums, too
  * consequently, we could also think about the gfx layer completely
    (except some small cairo surface reference type - autoptr derivative
    which calls cairo's ref/unref functions) and just add some helpers
    that operate on cairo API directly - reduce even more own code
* store the gfxSurfaceType value in the gfxASurface instances (so the
  value mapping only has to be done once, on init)
* make GfxSurfaceType a class, that holds the cairo_surface_type_t along
  w/ other information (eg. like SurfaceMemoryReporterAttrs, ...) and use
  references instead of enum values.
---
 dom/plugins/ipc/PluginInstanceChild.cpp |  4 +--
 gfx/ipc/GfxMessageUtils.h               |  2 +-
 gfx/thebes/gfxASurface.cpp              | 57 +++++++++++++++++----------------
 gfx/thebes/gfxTypes.h                   | 18 +++--------
 4 files changed, 36 insertions(+), 45 deletions(-)

diff --git a/dom/plugins/ipc/PluginInstanceChild.cpp 
b/dom/plugins/ipc/PluginInstanceChild.cpp
index af9db9103..940687bcc 100644
--- a/dom/plugins/ipc/PluginInstanceChild.cpp
+++ b/dom/plugins/ipc/PluginInstanceChild.cpp
@@ -183,7 +183,7 @@ PluginInstanceChild::PluginInstanceChild(const 
NPPluginFuncs* aPluginIface,
 #endif
     , mAccumulatedInvalidRect(0,0,0,0)
     , mIsTransparent(false)
-    , mSurfaceType(gfxSurfaceType::Max)
+    , mSurfaceType(gfxSurfaceType::Invalid)
     , mPendingPluginCall(false)
     , mDoAlphaExtraction(false)
     , mHasPainted(false)
@@ -3395,7 +3395,7 @@ PluginInstanceChild::DoAsyncSetWindow(const 
gfxSurfaceType& aSurfaceType,
 bool
 PluginInstanceChild::CreateOptSurface(void)
 {
-    MOZ_ASSERT(mSurfaceType != gfxSurfaceType::Max,
+    MOZ_ASSERT(mSurfaceType != gfxSurfaceType::Invalid,
                "Need a valid surface type here");
     NS_ASSERTION(!mCurrentSurface, "mCurrentSurfaceActor can get out of 
sync.");
 
diff --git a/gfx/ipc/GfxMessageUtils.h b/gfx/ipc/GfxMessageUtils.h
index e45aa7040..3268b36d8 100644
--- a/gfx/ipc/GfxMessageUtils.h
+++ b/gfx/ipc/GfxMessageUtils.h
@@ -202,7 +202,7 @@ template <>
 struct ParamTraits<gfxSurfaceType>
   : public ContiguousEnumSerializer<
              gfxSurfaceType,
-             gfxSurfaceType::Image,
+             gfxSurfaceType::First,
              gfxSurfaceType::Max>
 {};
 
diff --git a/gfx/thebes/gfxASurface.cpp b/gfx/thebes/gfxASurface.cpp
index 31f185596..5020d1596 100644
--- a/gfx/thebes/gfxASurface.cpp
+++ b/gfx/thebes/gfxASurface.cpp
@@ -207,9 +207,24 @@ gfxSurfaceType
 gfxASurface::GetType() const
 {
     if (!mSurfaceValid)
-        return (gfxSurfaceType)-1;
+        return gfxSurfaceType::Invalid;
+
+    switch (cairo_surface_get_type(mSurface)) {
+        case CAIRO_SURFACE_TYPE_IMAGE:          return gfxSurfaceType::Image;
+        case CAIRO_SURFACE_TYPE_PDF:            return gfxSurfaceType::PDF;
+        case CAIRO_SURFACE_TYPE_PS:             return gfxSurfaceType::PS;
+        case CAIRO_SURFACE_TYPE_XLIB:           return gfxSurfaceType::Xlib;
+        case CAIRO_SURFACE_TYPE_XCB:            return gfxSurfaceType::Xcb;
+        case CAIRO_SURFACE_TYPE_QUARTZ:         return gfxSurfaceType::Quartz;
+        case CAIRO_SURFACE_TYPE_WIN32:          return gfxSurfaceType::Win32;
+        case CAIRO_SURFACE_TYPE_SVG:            return gfxSurfaceType::SVG;
+        case CAIRO_SURFACE_TYPE_WIN32_PRINTING: return 
gfxSurfaceType::Win32Printing;
+        case CAIRO_SURFACE_TYPE_QT:             return 
gfxSurfaceType::QPainter;
+        case CAIRO_SURFACE_TYPE_RECORDING:      return 
gfxSurfaceType::Recording;
+        case CAIRO_SURFACE_TYPE_SUBSURFACE:     return 
gfxSurfaceType::Subsurface;
+    }
 
-    return (gfxSurfaceType)cairo_surface_get_type(mSurface);
+    return gfxSurfaceType::Invalid;
 }
 
 gfxContentType
@@ -427,40 +442,26 @@ struct SurfaceMemoryReporterAttrs {
 };
 
 static const SurfaceMemoryReporterAttrs sSurfaceMemoryReporterAttrs[] = {
-    {"gfx-surface-image", nullptr},
-    {"gfx-surface-pdf", nullptr},
-    {"gfx-surface-ps", nullptr},
-    {"gfx-surface-xlib",
+    [gfxSurfaceType::Image]         = { "gfx-surface-image" },
+    [gfxSurfaceType::PDF]           = { "gfx-surface-pdf" },
+    [gfxSurfaceType::PS]            = { "gfx-surface-ps" },
+    [gfxSurfaceType::Xlib]          = { "gfx-surface-xlib",
      "Memory used by xlib surfaces to store pixmaps. This memory lives in "
      "the X server's process rather than in this application, so the bytes "
      "accounted for here aren't counted in vsize, resident, explicit, or any 
of "
      "the other measurements on this page."},
-    {"gfx-surface-xcb", nullptr},
-    {"gfx-surface-glitz???", nullptr},       // should never be used
-    {"gfx-surface-quartz", nullptr},
-    {"gfx-surface-win32", nullptr},
-    {"gfx-surface-beos", nullptr},
-    {"gfx-surface-directfb???", nullptr},    // should never be used
-    {"gfx-surface-svg", nullptr},
-    {"gfx-surface-os2", nullptr},
-    {"gfx-surface-win32printing", nullptr},
-    {"gfx-surface-quartzimage", nullptr},
-    {"gfx-surface-script", nullptr},
-    {"gfx-surface-qpainter", nullptr},
-    {"gfx-surface-recording", nullptr},
-    {"gfx-surface-vg", nullptr},
-    {"gfx-surface-gl", nullptr},
-    {"gfx-surface-drm", nullptr},
-    {"gfx-surface-tee", nullptr},
-    {"gfx-surface-xml", nullptr},
-    {"gfx-surface-skia", nullptr},
-    {"gfx-surface-subsurface", nullptr},
+    [gfxSurfaceType::Xcb]           = { "gfx-surface-xcb" },
+    [gfxSurfaceType::Quartz]        = { "gfx-surface-quartz" },
+    [gfxSurfaceType::Win32]         = { "gfx-surface-win32" },
+    [gfxSurfaceType::Win32Printing] = { "gfx-surface-win32printing" },
+    [gfxSurfaceType::SVG]           = { "gfx-surface-svg" },
+    [gfxSurfaceType::QPainter]      = { "gfx-surface-qpainter" },
+    [gfxSurfaceType::Recording]     = { "gfx-surface-recording" },
+    [gfxSurfaceType::Subsurface]    = { "gfx-surface-subsurface" },
 };
 
 static_assert(MOZ_ARRAY_LENGTH(sSurfaceMemoryReporterAttrs) ==
                  size_t(gfxSurfaceType::Max), "sSurfaceMemoryReporterAttrs 
exceeds max capacity");
-static_assert(uint32_t(CAIRO_SURFACE_TYPE_SKIA) ==
-                 uint32_t(gfxSurfaceType::Skia), "CAIRO_SURFACE_TYPE_SKIA not 
equal to gfxSurfaceType::Skia");
 
 /* Surface size memory reporting */
 
diff --git a/gfx/thebes/gfxTypes.h b/gfx/thebes/gfxTypes.h
index 976da1fef..c215aedf5 100644
--- a/gfx/thebes/gfxTypes.h
+++ b/gfx/thebes/gfxTypes.h
@@ -45,31 +45,21 @@ enum class gfxBreakPriority {
 };
 
 enum class gfxSurfaceType {
-  Image,
+  First = 0,
+  Image = First,
   PDF,
   PS,
   Xlib,
   Xcb,
-  Glitz,           // unused, but needed for cairo parity
   Quartz,
   Win32,
-  BeOS,
-  DirectFB,        // unused, but needed for cairo parity
   SVG,
-  OS2,
   Win32Printing,
-  QuartzImage,
-  Script,
   QPainter,
   Recording,
-  VG,
-  GL,
-  DRM,
-  Tee,
-  XML,
-  Skia,
   Subsurface,
-  Max
+  Max,
+  Invalid = Max
 };
 
 enum class gfxContentType {
-- 
2.11.0.rc0.7.gbe5a750

_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to