Bug 1594114 - Add SurfaceFormat::OS_RGBA and OS_RGBX to define preferred format. r=jrmuizel
authorAndrew Osmond <aosmond@mozilla.com>
Wed, 06 Nov 2019 16:37:53 +0000
changeset 500891 de6cf4a44c019805eebace8a1c08488dc4f3677a
parent 500890 4ee2e15986b6115c94c803d807178c2e282c17bc
child 500892 8fe301759bc7130ca2df03e954a81a07de3d3a50
push id36778
push userapavel@mozilla.com
push dateThu, 07 Nov 2019 09:49:05 +0000
treeherdermozilla-central@d271c572a9bc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1594114
milestone72.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 1594114 - Add SurfaceFormat::OS_RGBA and OS_RGBX to define preferred format. r=jrmuizel OS_RGBA and OS_RGBX are defined as the preferred surface format for the platform and architecture, fixed at compile time. Today this will be initially defined as B8G8R8A8. The future intent is that once all parts of the system support all configurations, then we can use R8G8B8A8 on certain platforms (e.g. Android, Linux, Mac) and invert it on big-endian architectures. Differential Revision: https://phabricator.services.mozilla.com/D52006
gfx/2d/Types.h
--- a/gfx/2d/Types.h
+++ b/gfx/2d/Types.h
@@ -83,25 +83,73 @@ enum class SurfaceFormat : int8_t {
   // This represents the unknown format.
   UNKNOWN,
 
 // The following values are endian-independent synonyms. The _UINT32 suffix
 // indicates that the name reflects the layout when viewed as a uint32_t
 // value.
 #if MOZ_LITTLE_ENDIAN
   A8R8G8B8_UINT32 = B8G8R8A8,  // 0xAARRGGBB
-  X8R8G8B8_UINT32 = B8G8R8X8   // 0x00RRGGBB
+  X8R8G8B8_UINT32 = B8G8R8X8,  // 0x00RRGGBB
 #elif MOZ_BIG_ENDIAN
   A8R8G8B8_UINT32 = A8R8G8B8,  // 0xAARRGGBB
-  X8R8G8B8_UINT32 = X8R8G8B8   // 0x00RRGGBB
+  X8R8G8B8_UINT32 = X8R8G8B8,  // 0x00RRGGBB
 #else
 #  error "bad endianness"
 #endif
+
+  // The following values are OS and endian-independent synonyms.
+  //
+  // TODO(aosmond): When everything blocking bug 1581828 has been resolved, we
+  // can make this use R8B8G8A8 and R8B8G8X8 for non-Windows platforms.
+  OS_RGBA = A8R8G8B8_UINT32,
+  OS_RGBX = X8R8G8B8_UINT32
 };
 
+// Represents the bit-shifts required to access color channels when the layout
+// is viewed as a uint32_t value.
+enum class SurfaceFormatBit : uint32_t {
+#if MOZ_LITTLE_ENDIAN
+  R8G8B8A8_R = 0,
+  R8G8B8A8_G = 8,
+  R8G8B8A8_B = 16,
+  R8G8B8A8_A = 24,
+#elif MOZ_BIG_ENDIAN
+  R8G8B8A8_A = 0,
+  R8G8B8A8_B = 8,
+  R8G8B8A8_G = 16,
+  R8G8B8A8_R = 24,
+#else
+#  error "bad endianness"
+#endif
+
+  // The following values are endian-independent for A8R8G8B8_UINT32.
+  A8R8G8B8_UINT32_B = 0,
+  A8R8G8B8_UINT32_G = 8,
+  A8R8G8B8_UINT32_R = 16,
+  A8R8G8B8_UINT32_A = 24,
+
+  // The following values are OS and endian-independent.
+  //
+  // TODO(aosmond): When everything blocking bug 1581828 has been resolved, we
+  // can make this use R8G8B8A8_X for non-Windows platforms.
+  OS_R = A8R8G8B8_UINT32_R,
+  OS_G = A8R8G8B8_UINT32_G,
+  OS_B = A8R8G8B8_UINT32_B,
+  OS_A = A8R8G8B8_UINT32_A,
+};
+
+inline uint32_t operator<<(uint8_t a, SurfaceFormatBit b) {
+  return a << static_cast<uint32_t>(b);
+}
+
+inline uint32_t operator>>(uint32_t a, SurfaceFormatBit b) {
+  return a >> static_cast<uint32_t>(b);
+}
+
 static inline int BytesPerPixel(SurfaceFormat aFormat) {
   switch (aFormat) {
     case SurfaceFormat::A8:
       return 1;
     case SurfaceFormat::R5G6B5_UINT16:
     case SurfaceFormat::A16:
       return 2;
     case SurfaceFormat::R8G8B8: