Bug 700179 - Add GetSize() support for the windows surfaces. r=Bas
authorMatt Woodrow <mwoodrow@mozilla.com>
Fri, 18 Nov 2011 17:00:37 +1300
changeset 80411 36b377464b44dce09299a5c896a2a6f892066113
parent 80410 215593486382ba9710ee70056a94f44b1ab846c7
child 80412 c625d6aedcc29a2254a49a1f6ec5d83cbda19569
push id3443
push usermwoodrow@mozilla.com
push dateFri, 18 Nov 2011 04:01:12 +0000
treeherdermozilla-inbound@4af4c72eafa7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBas
bugs700179
milestone11.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 700179 - Add GetSize() support for the windows surfaces. r=Bas
gfx/cairo/cairo/src/cairo-d2d-surface.cpp
gfx/cairo/cairo/src/cairo-win32-surface.c
gfx/cairo/cairo/src/cairo-win32.h
gfx/thebes/gfxD2DSurface.cpp
gfx/thebes/gfxD2DSurface.h
gfx/thebes/gfxWindowsSurface.cpp
gfx/thebes/gfxWindowsSurface.h
--- a/gfx/cairo/cairo/src/cairo-d2d-surface.cpp
+++ b/gfx/cairo/cairo/src/cairo-d2d-surface.cpp
@@ -4792,8 +4792,34 @@ cairo_d2d_get_image_surface_cache_usage(
 }
 
 int
 cairo_d2d_get_surface_vram_usage(cairo_device_t *device)
 {
     cairo_d2d_device_t *d2d_device = reinterpret_cast<cairo_d2d_device_t*>(device);
     return d2d_device->mVRAMUsage;
 }
+
+int
+cairo_d2d_surface_get_width(cairo_surface_t *surface)
+{
+    if (surface->backend != &cairo_d2d_surface_backend) {
+	    _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
+	    return 0;
+    }
+
+    cairo_d2d_surface_t *d2dsurf = reinterpret_cast<cairo_d2d_surface_t*>(surface);
+    D2D1_SIZE_U size = d2dsurf->rt->GetPixelSize();
+    return size.width;
+}
+
+int
+cairo_d2d_surface_get_height(cairo_surface_t *surface)
+{
+    if (surface->backend != &cairo_d2d_surface_backend) {
+	    _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
+	    return 0;
+    }
+
+    cairo_d2d_surface_t *d2dsurf = reinterpret_cast<cairo_d2d_surface_t*>(surface);
+    D2D1_SIZE_U size = d2dsurf->rt->GetPixelSize();
+    return size.height;
+}
--- a/gfx/cairo/cairo/src/cairo-win32-surface.c
+++ b/gfx/cairo/cairo/src/cairo-win32-surface.c
@@ -3905,8 +3905,28 @@ cairo_win32_surface_get_can_convert_to_d
 {
     cairo_win32_surface_t *surface = (cairo_win32_surface_t*) asurface;
     if (surface->base.type != CAIRO_SURFACE_TYPE_WIN32)
 	return CAIRO_STATUS_SURFACE_TYPE_MISMATCH;
 
     *can_convert = ((surface->flags & CAIRO_WIN32_SURFACE_CAN_CONVERT_TO_DIB) != 0);
     return CAIRO_STATUS_SUCCESS;
 }
+
+int
+cairo_win32_surface_get_width (cairo_surface_t *asurface)
+{
+    cairo_win32_surface_t *surface = (cairo_win32_surface_t*) asurface;
+    if (surface->base.type != CAIRO_SURFACE_TYPE_WIN32)
+	return CAIRO_STATUS_SURFACE_TYPE_MISMATCH;
+
+    return surface->extents.width;
+}
+
+int
+cairo_win32_surface_get_height (cairo_surface_t *asurface)
+{
+    cairo_win32_surface_t *surface = (cairo_win32_surface_t*) asurface;
+    if (surface->base.type != CAIRO_SURFACE_TYPE_WIN32)
+	return CAIRO_STATUS_SURFACE_TYPE_MISMATCH;
+
+    return surface->extents.height;
+}
--- a/gfx/cairo/cairo/src/cairo-win32.h
+++ b/gfx/cairo/cairo/src/cairo-win32.h
@@ -77,16 +77,22 @@ cairo_win32_surface_get_image (cairo_sur
 cairo_public cairo_status_t
 cairo_win32_surface_set_can_convert_to_dib (cairo_surface_t *surface, cairo_bool_t can_convert);
 
 cairo_public cairo_status_t
 cairo_win32_surface_get_can_convert_to_dib (cairo_surface_t *surface, cairo_bool_t *can_convert);
 
 BYTE cairo_win32_get_system_text_quality (void);
 
+cairo_public int
+cairo_win32_surface_get_width (cairo_surface_t *surface);
+
+cairo_public int
+cairo_win32_surface_get_height (cairo_surface_t *surface);
+
 #if CAIRO_HAS_WIN32_FONT
 
 /*
  * Win32 font support
  */
 
 cairo_public cairo_font_face_t *
 cairo_win32_font_face_create_for_logfontw (LOGFONTW *logfont);
@@ -304,16 +310,26 @@ void cairo_d2d_release_dc(cairo_surface_
 int cairo_d2d_get_image_surface_cache_usage();
 
 /**
  * Get an estimate of the amount of VRAM which is currently used by the d2d
  * surfaces for a device. This does -not- include the internal image surface
  * cache.
  */
 int cairo_d2d_get_surface_vram_usage(cairo_device_t *device);
+
+/**
+ * Get the width of the surface.
+ */
+int cairo_d2d_surface_get_width(cairo_surface_t *surface);
+
+/**
+ * Get the height of the surface.
+ */
+int cairo_d2d_surface_get_height(cairo_surface_t *surface);
 #endif
 
 CAIRO_END_DECLS
 
 #else  /* CAIRO_HAS_WIN32_SURFACE */
 # error Cairo was not compiled with support for the win32 backend
 #endif /* CAIRO_HAS_WIN32_SURFACE */
 
--- a/gfx/thebes/gfxD2DSurface.cpp
+++ b/gfx/thebes/gfxD2DSurface.cpp
@@ -118,8 +118,14 @@ gfxD2DSurface::ReleaseDC(const nsIntRect
 
     cairo_rectangle_int_t rect;
     rect.x = aUpdatedRect->x;
     rect.y = aUpdatedRect->y;
     rect.width = aUpdatedRect->width;
     rect.height = aUpdatedRect->height;
     cairo_d2d_release_dc(CairoSurface(), &rect);
 }
+
+const gfxIntSize gfxD2DSurface::GetSize() const
+{ 
+    return gfxIntSize(cairo_d2d_surface_get_width(mSurface),
+                      cairo_d2d_surface_get_height(mSurface));
+}
\ No newline at end of file
--- a/gfx/thebes/gfxD2DSurface.h
+++ b/gfx/thebes/gfxD2DSurface.h
@@ -65,15 +65,17 @@ public:
         FastMovePixels(aSourceRect, aDestTopLeft);
     }
 
     virtual ~gfxD2DSurface();
 
     void Present();
     void Scroll(const nsIntPoint &aDelta, const nsIntRect &aClip);
 
+    virtual const gfxIntSize GetSize() const;
+
     ID3D10Texture2D *GetTexture();
 
     HDC GetDC(bool aRetainContents);
     void ReleaseDC(const nsIntRect *aUpdatedRect);
 };
 
 #endif /* GFX_D2DSURFACE_H */
--- a/gfx/thebes/gfxWindowsSurface.cpp
+++ b/gfx/thebes/gfxWindowsSurface.cpp
@@ -332,13 +332,27 @@ gfxWindowsSurface::GetDefaultContextFlag
     if (mForPrinting)
         return gfxContext::FLAG_SIMPLIFY_OPERATORS |
                gfxContext::FLAG_DISABLE_SNAPPING |
                gfxContext::FLAG_DISABLE_COPY_BACKGROUND;
 
     return 0;
 }
 
+const gfxIntSize 
+gfxWindowsSurface::GetSize() const
+{
+    if (!mSurfaceValid) {
+        NS_WARNING ("GetImageSurface on an invalid (null) surface; who's calling this without checking for surface errors?");
+        return gfxIntSize(-1, -1);
+    }
+
+    NS_ASSERTION(mSurface != nsnull, "CairoSurface() shouldn't be nsnull when mSurfaceValid is TRUE!");
+
+    return gfxIntSize(cairo_win32_surface_get_width(mSurface),
+                      cairo_win32_surface_get_height(mSurface));
+}
+
 gfxASurface::MemoryLocation
 gfxWindowsSurface::GetMemoryLocation() const
 {
     return MEMORY_IN_PROCESS_NONHEAP;
 }
--- a/gfx/thebes/gfxWindowsSurface.h
+++ b/gfx/thebes/gfxWindowsSurface.h
@@ -87,16 +87,18 @@ public:
     nsresult BeginPrinting(const nsAString& aTitle, const nsAString& aPrintToFileName);
     nsresult EndPrinting();
     nsresult AbortPrinting();
     nsresult BeginPage();
     nsresult EndPage();
 
     virtual PRInt32 GetDefaultContextFlags() const;
 
+    const gfxIntSize GetSize() const;
+
     void MovePixels(const nsIntRect& aSourceRect,
                     const nsIntPoint& aDestTopLeft)
     {
         FastMovePixels(aSourceRect, aDestTopLeft);
     }
 
     // The memory used by this surface lives in this process's address space,
     // but not in the heap.