Bug 1316750, part 2 - Add CairoContentToCairoFormat helper to HelpersCairo.h. r=edwin
☠☠ backed out by 91b1add28ef6 ☠ ☠
authorJonathan Watt <jwatt@jwatt.org>
Mon, 14 Nov 2016 17:32:17 +0000
changeset 438645 e222819961af854aed85dfccc346b03e3de0d477
parent 438644 888f093ce01504fb472d0646d29c08bcc5ef7b75
child 438646 c0d0caa11f5a56edbede98532513861c61f7de34
push id35794
push usersledru@mozilla.com
push dateMon, 14 Nov 2016 22:18:09 +0000
reviewersedwin
bugs1316750
milestone52.0a1
Bug 1316750, part 2 - Add CairoContentToCairoFormat helper to HelpersCairo.h. r=edwin
gfx/2d/HelpersCairo.h
--- a/gfx/2d/HelpersCairo.h
+++ b/gfx/2d/HelpersCairo.h
@@ -160,16 +160,33 @@ GfxFormatToCairoFormat(SurfaceFormat for
     case SurfaceFormat::R5G6B5_UINT16:
       return CAIRO_FORMAT_RGB16_565;
     default:
       gfxCriticalError() << "Unknown image format " << (int)format;
       return CAIRO_FORMAT_ARGB32;
   }
 }
 
+static inline cairo_format_t
+CairoContentToCairoFormat(cairo_content_t content)
+{
+  switch (content)
+  {
+    case CAIRO_CONTENT_COLOR:
+      return CAIRO_FORMAT_RGB24;
+    case CAIRO_CONTENT_ALPHA:
+      return CAIRO_FORMAT_A8;
+    case CAIRO_CONTENT_COLOR_ALPHA:
+      return CAIRO_FORMAT_ARGB32;
+    default:
+      gfxCriticalError() << "Unknown cairo content type " << (int)content;
+      return CAIRO_FORMAT_A8; // least likely to cause OOB reads
+  }
+}
+
 static inline cairo_content_t
 GfxFormatToCairoContent(SurfaceFormat format)
 {
   switch (format)
   {
     case SurfaceFormat::A8R8G8B8_UINT32:
       return CAIRO_CONTENT_COLOR_ALPHA;
     case SurfaceFormat::X8R8G8B8_UINT32: