Bug 924679. Part 3: Make gfxXlibNativeRenderer::DrawWithXlib callback take a cairo_surface_t instead of a gfxXlibSurface. r=karlt
authorRobert O'Callahan <robert@ocallahan.org>
Fri, 25 Oct 2013 23:25:40 +0200
changeset 152581 28e1e608cfe3f3b440d13dc0513c6f6705c938fa
parent 152580 87b489625999c8107423a3c8d1bd48616e823847
child 152582 4c3c13fc333c330118b25f261f2dd51dcbc7f10a
push id25552
push usercbook@mozilla.com
push dateTue, 29 Oct 2013 12:21:45 +0000
treeherdermozilla-central@cd94525c17a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs924679
milestone28.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 924679. Part 3: Make gfxXlibNativeRenderer::DrawWithXlib callback take a cairo_surface_t instead of a gfxXlibSurface. r=karlt
dom/plugins/base/nsPluginInstanceOwner.cpp
dom/plugins/base/nsPluginInstanceOwner.h
gfx/thebes/gfxGdkNativeRenderer.cpp
gfx/thebes/gfxGdkNativeRenderer.h
gfx/thebes/gfxPlatformGtk.cpp
gfx/thebes/gfxPlatformGtk.h
gfx/thebes/gfxXlibNativeRenderer.cpp
gfx/thebes/gfxXlibNativeRenderer.h
--- a/dom/plugins/base/nsPluginInstanceOwner.cpp
+++ b/dom/plugins/base/nsPluginInstanceOwner.cpp
@@ -2793,25 +2793,25 @@ void nsPluginInstanceOwner::Paint(gfxCon
   Display* dpy = mozilla::DefaultXDisplay();
   Screen* screen = DefaultScreenOfDisplay(dpy);
   Visual* visual = DefaultVisualOfScreen(screen);
 
   renderer.Draw(aContext, nsIntSize(window->width, window->height),
                 rendererFlags, screen, visual, nullptr);
 }
 nsresult
-nsPluginInstanceOwner::Renderer::DrawWithXlib(gfxXlibSurface* xsurface, 
+nsPluginInstanceOwner::Renderer::DrawWithXlib(cairo_surface_t* xsurface,
                                               nsIntPoint offset,
                                               nsIntRect *clipRects, 
                                               uint32_t numClipRects)
 {
-  Screen *screen = cairo_xlib_surface_get_screen(xsurface->CairoSurface());
+  Screen *screen = cairo_xlib_surface_get_screen(xsurface);
   Colormap colormap;
   Visual* visual;
-  if (!xsurface->GetColormapAndVisual(&colormap, &visual)) {
+  if (!gfxXlibSurface::GetColormapAndVisual(xsurface, &colormap, &visual)) {
     NS_ERROR("Failed to get visual and colormap");
     return NS_ERROR_UNEXPECTED;
   }
 
   nsNPAPIPluginInstance *instance = mInstanceOwner->mInstance;
   if (!instance)
     return NS_ERROR_FAILURE;
 
@@ -2845,20 +2845,20 @@ nsPluginInstanceOwner::Renderer::DrawWit
   }
   else {
     clipRect.x = offset.x;
     clipRect.y = offset.y;
     clipRect.width  = mWindow->width;
     clipRect.height = mWindow->height;
     // Don't ask the plugin to draw outside the drawable.
     // This also ensures that the unsigned clip rectangle offsets won't be -ve.
-    gfxIntSize surfaceSize = xsurface->GetSize();
     clipRect.IntersectRect(clipRect,
                            nsIntRect(0, 0,
-                                     surfaceSize.width, surfaceSize.height));
+                                     cairo_xlib_surface_get_width(xsurface),
+                                     cairo_xlib_surface_get_height(xsurface)));
   }
 
   NPRect newClipRect;
   newClipRect.left = clipRect.x;
   newClipRect.top = clipRect.y;
   newClipRect.right = clipRect.XMost();
   newClipRect.bottom = clipRect.YMost();
   if (mWindow->clipRect.left    != newClipRect.left   ||
@@ -2901,17 +2901,17 @@ nsPluginInstanceOwner::Renderer::DrawWit
     return NS_OK;
 
   {
     XEvent pluginEvent = XEvent();
     XGraphicsExposeEvent& exposeEvent = pluginEvent.xgraphicsexpose;
     // set the drawing info
     exposeEvent.type = GraphicsExpose;
     exposeEvent.display = DisplayOfScreen(screen);
-    exposeEvent.drawable = xsurface->XDrawable();
+    exposeEvent.drawable = cairo_xlib_surface_get_drawable(xsurface);
     exposeEvent.x = dirtyRect.x;
     exposeEvent.y = dirtyRect.y;
     exposeEvent.width  = dirtyRect.width;
     exposeEvent.height = dirtyRect.height;
     exposeEvent.count = 0;
     // information not set:
     exposeEvent.serial = 0;
     exposeEvent.send_event = False;
--- a/dom/plugins/base/nsPluginInstanceOwner.h
+++ b/dom/plugins/base/nsPluginInstanceOwner.h
@@ -334,18 +334,19 @@ private:
 #endif
   {
   public:
     Renderer(NPWindow* aWindow, nsPluginInstanceOwner* aInstanceOwner,
              const nsIntSize& aPluginSize, const nsIntRect& aDirtyRect)
     : mWindow(aWindow), mInstanceOwner(aInstanceOwner),
     mPluginSize(aPluginSize), mDirtyRect(aDirtyRect)
     {}
-    virtual nsresult DrawWithXlib(gfxXlibSurface* surface, nsIntPoint offset, 
-                                  nsIntRect* clipRects, uint32_t numClipRects);
+    virtual nsresult DrawWithXlib(cairo_surface_t* surface,
+                                  nsIntPoint offset,
+                                  nsIntRect* clipRects, uint32_t numClipRects) MOZ_OVERRIDE;
   private:
     NPWindow* mWindow;
     nsPluginInstanceOwner* mInstanceOwner;
     const nsIntSize& mPluginSize;
     const nsIntRect& mDirtyRect;
   };
 #endif
 
--- a/gfx/thebes/gfxGdkNativeRenderer.cpp
+++ b/gfx/thebes/gfxGdkNativeRenderer.cpp
@@ -9,28 +9,29 @@
 
 #ifdef MOZ_X11
 #include <gdk/gdkx.h>
 #include "cairo-xlib.h"
 #include "gfxXlibSurface.h"
 
 #if (MOZ_WIDGET_GTK == 2)
 nsresult
-gfxGdkNativeRenderer::DrawWithXlib(gfxXlibSurface* surface,
+gfxGdkNativeRenderer::DrawWithXlib(cairo_surface_t* surface,
                                    nsIntPoint offset,
                                    nsIntRect* clipRects, uint32_t numClipRects)
 {
     GdkDrawable *drawable = gfxPlatformGtk::GetGdkDrawable(surface);
     if (!drawable) {
-        gfxIntSize size = surface->GetSize();
-        int depth = cairo_xlib_surface_get_depth(surface->CairoSurface());
+        int depth = cairo_xlib_surface_get_depth(surface);
         GdkScreen* screen = gdk_colormap_get_screen(mColormap);
         drawable =
-            gdk_pixmap_foreign_new_for_screen(screen, surface->XDrawable(),
-                                              size.width, size.height, depth);
+            gdk_pixmap_foreign_new_for_screen(screen, cairo_xlib_surface_get_drawable(surface),
+                                              cairo_xlib_surface_get_width(surface),
+                                              cairo_xlib_surface_get_height(surface),
+                                              depth);
         if (!drawable)
             return NS_ERROR_FAILURE;
 
         gdk_drawable_set_colormap(drawable, mColormap);
         gfxPlatformGtk::SetGdkDrawable(surface, drawable);
         g_object_unref(drawable); // The drawable now belongs to |surface|.
     }
     
--- a/gfx/thebes/gfxGdkNativeRenderer.h
+++ b/gfx/thebes/gfxGdkNativeRenderer.h
@@ -71,19 +71,19 @@ public:
 #if (MOZ_WIDGET_GTK == 2)
     void Draw(gfxContext* ctx, nsIntSize size,
               uint32_t flags, GdkColormap* colormap);
 #endif
 
 private:
 #ifdef MOZ_X11
     // for gfxXlibNativeRenderer:
-    virtual nsresult DrawWithXlib(gfxXlibSurface* surface,
+    virtual nsresult DrawWithXlib(cairo_surface_t* surface,
                                   nsIntPoint offset,
-                                  nsIntRect* clipRects, uint32_t numClipRects);
+                                  nsIntRect* clipRects, uint32_t numClipRects) MOZ_OVERRIDE;
 
 #if (MOZ_WIDGET_GTK == 2)
     GdkColormap *mColormap;
 #endif
 #endif
 };
 
 #endif /*GFXGDKNATIVERENDER_H_*/
--- a/gfx/thebes/gfxPlatformGtk.cpp
+++ b/gfx/thebes/gfxPlatformGtk.cpp
@@ -717,51 +717,49 @@ void
 gfxPlatformGtk::SetPrefFontEntries(const nsCString& aKey, nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList)
 {
     gPrefFonts->Put(aKey, aFontEntryList);
 }
 #endif
 
 #if (MOZ_WIDGET_GTK == 2)
 void
-gfxPlatformGtk::SetGdkDrawable(gfxASurface *target,
+gfxPlatformGtk::SetGdkDrawable(cairo_surface_t *target,
                                GdkDrawable *drawable)
 {
-    if (target->CairoStatus())
+    if (cairo_surface_status(target))
         return;
 
     g_object_ref(drawable);
 
-    cairo_surface_set_user_data (target->CairoSurface(),
+    cairo_surface_set_user_data (target,
                                  &cairo_gdk_drawable_key,
                                  drawable,
                                  g_object_unref);
 }
 
 GdkDrawable *
-gfxPlatformGtk::GetGdkDrawable(gfxASurface *target)
+gfxPlatformGtk::GetGdkDrawable(cairo_surface_t *target)
 {
-    if (target->CairoStatus())
+    if (cairo_surface_status(target))
         return nullptr;
 
     GdkDrawable *result;
 
-    result = (GdkDrawable*) cairo_surface_get_user_data (target->CairoSurface(),
+    result = (GdkDrawable*) cairo_surface_get_user_data (target,
                                                          &cairo_gdk_drawable_key);
     if (result)
         return result;
 
 #ifdef MOZ_X11
-    if (target->GetType() != gfxSurfaceTypeXlib)
+    if (cairo_surface_get_type(target) != CAIRO_SURFACE_TYPE_XLIB)
         return nullptr;
 
-    gfxXlibSurface *xs = static_cast<gfxXlibSurface*>(target);
-
     // try looking it up in gdk's table
-    result = (GdkDrawable*) gdk_xid_table_lookup(xs->XDrawable());
+    result = (GdkDrawable*) gdk_xid_table_lookup(cairo_xlib_surface_get_drawable(target));
     if (result) {
         SetGdkDrawable(target, result);
         return result;
     }
 #endif
 
     return nullptr;
 }
--- a/gfx/thebes/gfxPlatformGtk.h
+++ b/gfx/thebes/gfxPlatformGtk.h
@@ -86,19 +86,19 @@ public:
     void SetPrefFontEntries(const nsCString& aLangGroup, nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList);
 #endif
 
 #ifndef MOZ_PANGO
     FT_Library GetFTLibrary();
 #endif
 
 #if (MOZ_WIDGET_GTK == 2)
-    static void SetGdkDrawable(gfxASurface *target,
+    static void SetGdkDrawable(cairo_surface_t *target,
                                GdkDrawable *drawable);
-    static GdkDrawable *GetGdkDrawable(gfxASurface *target);
+    static GdkDrawable *GetGdkDrawable(cairo_surface_t *target);
 #endif
 
     static int32_t GetDPI();
 
     bool UseXRender() {
 #if defined(MOZ_X11)
         if (GetContentBackend() != mozilla::gfx::BACKEND_NONE &&
             GetContentBackend() != mozilla::gfx::BACKEND_CAIRO)
--- a/gfx/thebes/gfxXlibNativeRenderer.cpp
+++ b/gfx/thebes/gfxXlibNativeRenderer.cpp
@@ -250,18 +250,17 @@ gfxXlibNativeRenderer::DrawCairo(cairo_t
             NATIVE_DRAWING_NOTE("FALLBACK: unsupported Visual");
             return false;
         }
     }
 
     /* we're good to go! */
     NATIVE_DRAWING_NOTE("TAKING FAST PATH\n");
     cairo_surface_flush (target);
-    nsRefPtr<gfxASurface> surface = gfxASurface::Wrap(target);
-    nsresult rv = DrawWithXlib(static_cast<gfxXlibSurface*>(surface.get()),
+    nsresult rv = DrawWithXlib(target,
                                offset, rectangles,
                                needs_clip ? rect_count : 0);
     if (NS_SUCCEEDED(rv)) {
         cairo_surface_mark_dirty (target);
         return true;
     }
     return false;
 }
@@ -439,17 +438,17 @@ CreateTempXlibSurface (gfxASurface *dest
 
 bool
 gfxXlibNativeRenderer::DrawOntoTempSurface(gfxXlibSurface *tempXlibSurface,
                                            nsIntPoint offset)
 {
     tempXlibSurface->Flush();
     /* no clipping is needed because the callback can't draw outside the native
        surface anyway */
-    nsresult rv = DrawWithXlib(tempXlibSurface, offset, nullptr, 0);
+    nsresult rv = DrawWithXlib(tempXlibSurface->CairoSurface(), offset, nullptr, 0);
     tempXlibSurface->MarkDirty();
     return NS_SUCCEEDED(rv);
 }
 
 static already_AddRefed<gfxImageSurface>
 CopyXlibSurfaceToImage(gfxXlibSurface *tempXlibSurface,
                        gfxImageFormat format)
 {
--- a/gfx/thebes/gfxXlibNativeRenderer.h
+++ b/gfx/thebes/gfxXlibNativeRenderer.h
@@ -29,29 +29,28 @@ typedef struct _cairo cairo_t;
  * use it to draw into any Thebes context. The user should subclass this class,
  * override DrawWithXib, and then call Draw(). The drawing will be subjected
  * to all Thebes transformations, clipping etc.
  */
 class gfxXlibNativeRenderer {
 public:
     /**
      * Perform the native drawing.
-     * @param surface the drawable for drawing.
+     * @param surface the cairo_surface_t for drawing. Must be a cairo_xlib_surface_t.
      *                The extents of this surface do not necessarily cover the
      *                entire rectangle with size provided to Draw().
-     * @param offsetX draw at this offset into the given drawable
-     * @param offsetY draw at this offset into the given drawable
+     * @param offset  draw at this offset into the given drawable
      * @param clipRects an array of rectangles; clip to the union.
      *                  Any rectangles provided will be contained by the
      *                  rectangle with size provided to Draw and by the
      *                  surface extents.
      * @param numClipRects the number of rects in the array, or zero if
      *                     no clipping is required.
      */
-    virtual nsresult DrawWithXlib(gfxXlibSurface* surface,
+    virtual nsresult DrawWithXlib(cairo_surface_t* surface,
                                   nsIntPoint offset,
                                   nsIntRect* clipRects, uint32_t numClipRects) = 0;
   
     enum {
         // If set, then Draw() is opaque, i.e., every pixel in the intersection
         // of the clipRect and (offset.x,offset.y,bounds.width,bounds.height)
         // will be set and there is no dependence on what the existing pixels
         // in the drawable are set to.