Bug 1316750 - Add special case handling for CAIRO_SURFACE_TYPE_WIN32 and CAIRO_SURFACE_TYPE_QUARTZ in PrintTarget::GetReferenceDrawTarget. r=edwin
☠☠ backed out by 91b1add28ef6 ☠ ☠
authorJonathan Watt <jwatt@jwatt.org>
Thu, 03 Nov 2016 09:47:19 +0000
changeset 438637 9508c116ecd7df49d5380d1a7478e9994ca47a15
parent 438636 3b7efab71fda5053f5ca508fcf88999853cdb3b7
child 438638 ac5ea2dc6c60ba42d900b81051161110232c9949
push id35794
push usersledru@mozilla.com
push dateMon, 14 Nov 2016 22:18:09 +0000
reviewersedwin
bugs1316750
milestone52.0a1
Bug 1316750 - Add special case handling for CAIRO_SURFACE_TYPE_WIN32 and CAIRO_SURFACE_TYPE_QUARTZ in PrintTarget::GetReferenceDrawTarget. r=edwin
gfx/thebes/PrintTarget.cpp
--- a/gfx/thebes/PrintTarget.cpp
+++ b/gfx/thebes/PrintTarget.cpp
@@ -1,16 +1,22 @@
 /* -*- 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 "PrintTarget.h"
 
 #include "cairo.h"
+#ifdef CAIRO_HAS_QUARTZ_SURFACE
+#include "cairo-quartz.h"
+#endif
+#ifdef CAIRO_HAS_WIN32_SURFACE
+#include "cairo-win32.h"
+#endif
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/Logging.h"
 
 namespace mozilla {
 namespace gfx {
 
 PrintTarget::PrintTarget(cairo_surface_t* aCairoSurface, const IntSize& aSize)
   : mCairoSurface(aCairoSurface)
@@ -82,32 +88,50 @@ PrintTarget::MakeDrawTarget(const IntSiz
 
   return dt.forget();
 }
 
 already_AddRefed<DrawTarget>
 PrintTarget::GetReferenceDrawTarget()
 {
   if (!mRefDT) {
-    IntSize size(1, 1);
+    const IntSize size(1, 1);
 
-    cairo_surface_t* surface =
-      cairo_surface_create_similar(mCairoSurface,
-                                   cairo_surface_get_content(mCairoSurface),
-                                   size.width, size.height);
+    cairo_surface_t* similar;
+    switch (cairo_surface_get_type(mCairoSurface)) {
+#ifdef CAIRO_HAS_WIN32_SURFACE
+    case CAIRO_SURFACE_TYPE_WIN32:
+      similar = cairo_win32_surface_create_with_dib(
+                  cairo_surface_get_content(mCairoSurface),
+                  size.width, size.height);
+      break;
+#endif
+#ifdef CAIRO_HAS_QUARTZ_SURFACE
+    case CAIRO_SURFACE_TYPE_QUARTZ:
+      similar = cairo_quartz_surface_create_cg_layer(
+                  mCairoSurface, cairo_surface_get_content(mCairoSurface),
+                  size.width, size.height);
+      break;
+#endif
+    default:
+      similar = cairo_surface_create_similar(
+                  mCairoSurface, cairo_surface_get_content(mCairoSurface),
+                  size.width, size.height);
+      break;
+    }
 
-    if (cairo_surface_status(surface)) {
+    if (cairo_surface_status(similar)) {
       return nullptr;
     }
 
     RefPtr<DrawTarget> dt =
-      Factory::CreateDrawTargetForCairoSurface(surface, size);
+      Factory::CreateDrawTargetForCairoSurface(similar, size);
 
     // The DT addrefs the surface, so we need drop our own reference to it:
-    cairo_surface_destroy(surface);
+    cairo_surface_destroy(similar);
 
     if (!dt || !dt->IsValid()) {
       return nullptr;
     }
 
     mRefDT = dt.forget();
   }
   return do_AddRef(mRefDT);