Bug 579276. Part 6: Add gfxASurface::GetTextQualityInTransparentSurfaces API. r=jrmuizel,sr=vlad
authorRobert O'Callahan <robert@ocallahan.org>
Thu, 02 Sep 2010 21:18:41 +1200
changeset 51880 60c348050159e364b68cf162820c7e3701655563
parent 51879 3e9ab38cc2518d9269379f13c18ccc96f1be53d3
child 51881 671d64fcf6ac2f3a910e21d3d6f707ff9ac17bbf
push idunknown
push userunknown
push dateunknown
reviewersjrmuizel, vlad
bugs579276
milestone2.0b6pre
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 579276. Part 6: Add gfxASurface::GetTextQualityInTransparentSurfaces API. r=jrmuizel,sr=vlad
gfx/thebes/gfxASurface.h
gfx/thebes/gfxD2DSurface.h
gfx/thebes/gfxQuartzSurface.h
gfx/thebes/gfxWindowsSurface.h
gfx/thebes/gfxXlibSurface.h
--- a/gfx/thebes/gfxASurface.h
+++ b/gfx/thebes/gfxASurface.h
@@ -148,17 +148,50 @@ public:
      * false if they don't (i.e. the surface returned by
      * CreateOffscreenSurface is always as if you passed
      * CONTENT_COLOR_ALPHA). Knowing this can be useful to avoid
      * recreating a surface just because it changed from opaque to
      * transparent.
      */
     virtual PRBool AreSimilarSurfacesSensitiveToContentType()
     {
-      return PR_TRUE;
+        return PR_TRUE;
+    }
+
+    enum TextQuality {
+        /**
+         * TEXT_QUALITY_OK means that text is always rendered to a
+         * transparent surface just as well as it would be rendered to an
+         * opaque surface. This would normally only be true if
+         * subpixel antialiasing is disabled or if the platform's
+         * transparent surfaces support component alpha.
+         */
+        TEXT_QUALITY_OK,
+        /**
+         * TEXT_QUALITY_OK_OVER_OPAQUE_PIXELS means that text is rendered
+         * to a transparent surface just as well as it would be rendered to an
+         * opaque surface, but only if all the pixels the text is drawn
+         * over already have opaque alpha values.
+         */
+        TEXT_QUALITY_OK_OVER_OPAQUE_PIXELS,
+        /**
+         * TEXT_QUALITY_BAD means that text is rendered
+         * to a transparent surface worse than it would be rendered to an
+         * opaque surface, even if all the pixels the text is drawn
+         * over already have opaque alpha values.
+         */
+        TEXT_QUALITY_BAD
+    };
+    /**
+     * Determine how well text would be rendered in transparent surfaces that
+     * are similar to this surface.
+     */
+    virtual TextQuality GetTextQualityInTransparentSurfaces()
+    {
+        return TEXT_QUALITY_BAD;
     }
 
     int CairoStatus();
 
     /* Make sure that the given dimensions don't overflow a 32-bit signed int
      * using 4 bytes per pixel; optionally, make sure that either dimension
      * doesn't exceed the given limit.
      */
--- a/gfx/thebes/gfxD2DSurface.h
+++ b/gfx/thebes/gfxD2DSurface.h
@@ -52,16 +52,22 @@ public:
                   gfxImageFormat imageFormat = ImageFormatRGB24);
 
     gfxD2DSurface(HANDLE handle, gfxContentType aContent);
 
     gfxD2DSurface(cairo_surface_t *csurf);
 
     virtual ~gfxD2DSurface();
 
+    virtual TextQuality GetTextQualityInTransparentSurfaces()
+    {
+      // D2D always draws text in transparent surfaces with grayscale-AA,
+      // even if the text is over opaque pixels.
+      return TEXT_QUALITY_BAD;
+    }
 
     void Present();
     void Scroll(const nsIntPoint &aDelta, const nsIntRect &aClip);
 
     HDC GetDC(PRBool aRetainContents);
     void ReleaseDC(const nsIntRect *aUpdatedRect);
 };
 
--- a/gfx/thebes/gfxQuartzSurface.h
+++ b/gfx/thebes/gfxQuartzSurface.h
@@ -55,16 +55,20 @@ public:
     virtual ~gfxQuartzSurface();
 
     virtual already_AddRefed<gfxASurface> CreateSimilarSurface(gfxContentType aType,
                                                                const gfxIntSize& aSize);
     virtual PRBool AreSimilarSurfacesSensitiveToContentType()
     {
       return PR_FALSE;
     }
+    virtual TextQuality GetTextQualityInTransparentSurfaces()
+    {
+      return TEXT_QUALITY_OK_OVER_OPAQUE_PIXELS;
+    }
 
     const gfxSize& GetSize() const { return mSize; }
 
     CGContextRef GetCGContext() { return mCGContext; }
 
     CGContextRef GetCGContextWithClip(gfxContext *ctx);
 
     virtual PRInt32 GetDefaultContextFlags() const;
--- a/gfx/thebes/gfxWindowsSurface.h
+++ b/gfx/thebes/gfxWindowsSurface.h
@@ -76,16 +76,21 @@ public:
     HDC GetDCWithClip(gfxContext *);
 
     already_AddRefed<gfxImageSurface> GetImageSurface();
 
     already_AddRefed<gfxWindowsSurface> OptimizeToDDB(HDC dc,
                                                       const gfxIntSize& size,
                                                       gfxImageFormat format);
 
+    virtual TextQuality GetTextQualityInTransparentSurfaces()
+    {
+      return TEXT_QUALITY_OK_OVER_OPAQUE_PIXELS;
+    }
+
     nsresult BeginPrinting(const nsAString& aTitle, const nsAString& aPrintToFileName);
     nsresult EndPrinting();
     nsresult AbortPrinting();
     nsresult BeginPage();
     nsresult EndPage();
 
     virtual PRInt32 GetDefaultContextFlags() const;
 
--- a/gfx/thebes/gfxXlibSurface.h
+++ b/gfx/thebes/gfxXlibSurface.h
@@ -72,16 +72,21 @@ public:
     Create(Screen* screen, XRenderPictFormat *format, const gfxIntSize& size,
            Drawable relatedDrawable = None);
 
     virtual ~gfxXlibSurface();
 
     virtual already_AddRefed<gfxASurface>
     CreateSimilarSurface(gfxContentType aType, const gfxIntSize& aSize);
 
+    virtual TextQuality GetTextQualityInTransparentSurfaces()
+    {
+      return TEXT_QUALITY_OK_OVER_OPAQUE_PIXELS;
+    }
+
     const gfxIntSize& GetSize() { return mSize; }
 
     Display* XDisplay() { return mDisplay; }
     Drawable XDrawable() { return mDrawable; }
 
     static int DepthOfVisual(const Screen* screen, const Visual* visual);
     static Visual* FindVisual(Screen* screen, gfxImageFormat format);
     static XRenderPictFormat *FindRenderFormat(Display *dpy, gfxImageFormat format);