Bug 1306670: Properly disable cleartype when the underlying surface indicates it may not be opaque. r=jrmuizel
authorBas Schouten <bschouten@mozilla.com>
Mon, 03 Oct 2016 18:21:54 +0200
changeset 316415 df26b07efb46d767397e45dcc93a7132fbbeff3a
parent 316414 3fff88de2f2d5194bc940ad67ca2187498d00243
child 316416 5962dad680d46f59733ecd4d085ec9a0af389d86
push id30770
push userkwierso@gmail.com
push dateWed, 05 Oct 2016 00:00:48 +0000
treeherdermozilla-central@3470e326025c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1306670
milestone52.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 1306670: Properly disable cleartype when the underlying surface indicates it may not be opaque. r=jrmuizel MozReview-Commit-ID: LWzwbeG6JeL
gfx/cairo/cairo/src/cairo-dwrite-font.cpp
gfx/cairo/cairo/src/cairo-dwrite-private.h
--- a/gfx/cairo/cairo/src/cairo-dwrite-font.cpp
+++ b/gfx/cairo/cairo/src/cairo-dwrite-font.cpp
@@ -1139,37 +1139,45 @@ cairo_int_status_t
     IDWriteGdiInterop *gdiInterop;
     DWriteFactory::Instance()->GetGdiInterop(&gdiInterop);
     IDWriteBitmapRenderTarget *rt;
     HRESULT rv;
 
     cairo_d2d_surface_t::TextRenderingState renderingState =
       scaled_font->rendering_mode;
 
-    if ((renderingState == cairo_d2d_surface_t::TEXT_RENDERING_NORMAL ||
-         renderingState == cairo_d2d_surface_t::TEXT_RENDERING_GDI_CLASSIC) &&
-        !surface->base.permit_subpixel_antialiasing) {
-      renderingState = cairo_d2d_surface_t::TEXT_RENDERING_NO_CLEARTYPE;
-    }
-
-    IDWriteRenderingParams *params =
-        DWriteFactory::RenderingParams(renderingState);
-
     rv = gdiInterop->CreateBitmapRenderTarget(surface->dc,
 					      area.right - area.left,
 					      area.bottom - area.top,
 					      &rt);
+
     if (FAILED(rv)) {
 	if (rv == E_OUTOFMEMORY) {
 	    return (cairo_int_status_t)CAIRO_STATUS_NO_MEMORY;
 	} else {
 	    return CAIRO_INT_STATUS_UNSUPPORTED;
 	}
     }
 
+    if ((renderingState == cairo_d2d_surface_t::TEXT_RENDERING_NORMAL ||
+         renderingState == cairo_d2d_surface_t::TEXT_RENDERING_GDI_CLASSIC) &&
+        !surface->base.permit_subpixel_antialiasing) {
+      renderingState = cairo_d2d_surface_t::TEXT_RENDERING_NO_CLEARTYPE;
+      IDWriteBitmapRenderTarget1* rt1;
+      rv = rt->QueryInterface(&rt1);
+      
+      if (SUCCEEDED(rv) && rt1) {
+        rt1->SetTextAntialiasMode(DWRITE_TEXT_ANTIALIAS_MODE_GRAYSCALE);
+        rt1->Release();
+      }
+    }
+
+    IDWriteRenderingParams *params =
+        DWriteFactory::RenderingParams(renderingState);
+
     /**
      * We set the number of pixels per DIP to 1.0. This is because we always want
      * to draw in device pixels, and not device independent pixels. On high DPI
      * systems this value will be higher than 1.0 and automatically upscale
      * fonts, we don't want this since we do our own upscaling for various reasons.
      */
     rt->SetPixelsPerDip(1.0);
 
@@ -1442,21 +1450,22 @@ cairo_int_status_t
     if (status == (cairo_status_t)CAIRO_INT_STATUS_UNSUPPORTED) {
 #endif
 	status = _dwrite_draw_glyphs_to_gdi_surface_gdi(dst,
 							mat,
 							&run,
 							color,
 							dwritesf,
 							fontArea);
+
 #ifdef CAIRO_TRY_D2D_TO_GDI
     }
 #endif
 
-    return CAIRO_INT_STATUS_SUCCESS;
+    return status;
 }
 
 #define ENHANCED_CONTRAST_REGISTRY_KEY \
     HKEY_CURRENT_USER, "Software\\Microsoft\\Avalon.Graphics\\DISPLAY1\\EnhancedContrastLevel"
 
 void
 DWriteFactory::CreateRenderingParams()
 {
--- a/gfx/cairo/cairo/src/cairo-dwrite-private.h
+++ b/gfx/cairo/cairo/src/cairo-dwrite-private.h
@@ -28,17 +28,17 @@
  *
  * The Original Code is the cairo graphics library.
  *
  * The Initial Developer of the Original Code is the Mozilla Foundation
  *
  * Contributor(s):
  *	Bas Schouten <bschouten@mozilla.com>
  */
-#include <dwrite.h>
+#include <dwrite_1.h>
 #include <d2d1.h>
 
 // DirectWrite is not available on all platforms.
 typedef HRESULT (WINAPI*DWriteCreateFactoryFunc)(
   DWRITE_FACTORY_TYPE factoryType,
   REFIID iid,
   IUnknown **factory
 );