Bug 989027 - 1/2 - Make LayerRenderStateFlags a typed enum, manual changes - r=nical
☠☠ backed out by 0ecc4193e630 ☠ ☠
authorBenoit Jacob <bjacob@mozilla.com>
Fri, 25 Apr 2014 22:34:05 -0400
changeset 180724 4a67f5144ea432a299a7d6f2024065601c5a9707
parent 180723 62ba0a377450f00babdc2cd707d453df600c570f
child 180725 27f338fbc835acced577668d60b4831738f27d9f
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersnical
bugs989027
milestone31.0a1
Bug 989027 - 1/2 - Make LayerRenderStateFlags a typed enum, manual changes - r=nical
gfx/layers/LayersTypes.h
gfx/layers/opengl/GrallocTextureHost.cpp
--- a/gfx/layers/LayersTypes.h
+++ b/gfx/layers/LayersTypes.h
@@ -6,16 +6,17 @@
 #ifndef GFX_LAYERSTYPES_H
 #define GFX_LAYERSTYPES_H
 
 #include <stdint.h>                     // for uint32_t
 #include "nsPoint.h"                    // for nsIntPoint
 #include "nsRegion.h"
 
 #include "mozilla/TypedEnum.h"
+#include "mozilla/TypedEnumBits.h"
 
 #ifdef MOZ_WIDGET_GONK
 #include <ui/GraphicBuffer.h>
 #endif
 #if defined(DEBUG) || defined(PR_LOGGING)
 #  include <stdio.h>            // FILE
 #  include "prlog.h"            // for PR_LOG
 #  ifndef MOZ_LAYERS_HAVE_LOG
@@ -70,73 +71,78 @@ MOZ_BEGIN_ENUM_CLASS(SurfaceMode, int8_t
   SURFACE_OPAQUE,
   SURFACE_SINGLE_CHANNEL_ALPHA,
   SURFACE_COMPONENT_ALPHA
 MOZ_END_ENUM_CLASS(SurfaceMode)
 
 // LayerRenderState for Composer2D
 // We currently only support Composer2D using gralloc. If we want to be backed
 // by other surfaces we will need a more generic LayerRenderState.
-enum LayerRenderStateFlags {
-  LAYER_RENDER_STATE_Y_FLIPPED = 1 << 0,
-  LAYER_RENDER_STATE_BUFFER_ROTATION = 1 << 1,
+MOZ_BEGIN_ENUM_CLASS(LayerRenderStateFlags, int8_t)
+  LAYER_RENDER_STATE_DEFAULT = 0,
+  Y_FLIPPED = 1 << 0,
+  BUFFER_ROTATION = 1 << 1,
   // Notify Composer2D to swap the RB pixels of gralloc buffer
-  LAYER_RENDER_STATE_FORMAT_RB_SWAP = 1 << 2
-};
+  FORMAT_RB_SWAP = 1 << 2
+MOZ_END_ENUM_CLASS(LayerRenderStateFlags)
+MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(LayerRenderStateFlags)
 
 // The 'ifdef MOZ_WIDGET_GONK' sadness here is because we don't want to include
 // android::sp unless we have to.
 struct LayerRenderState {
   LayerRenderState()
 #ifdef MOZ_WIDGET_GONK
-    : mSurface(nullptr), mTexture(nullptr), mFlags(0), mHasOwnOffset(false)
+    : mFlags(LayerRenderStateFlags::LAYER_RENDER_STATE_DEFAULT)
+    , mHasOwnOffset(false)
+    , mSurface(nullptr)
+    , mTexture(nullptr)
 #endif
   {}
 
 #ifdef MOZ_WIDGET_GONK
   LayerRenderState(android::GraphicBuffer* aSurface,
                    const nsIntSize& aSize,
-                   uint32_t aFlags,
+                   LayerRenderStateFlags aFlags,
                    TextureHost* aTexture)
-    : mSurface(aSurface)
+    : mFlags(aFlags)
+    , mHasOwnOffset(false)
+    , mSurface(aSurface)
     , mSize(aSize)
     , mTexture(aTexture)
-    , mFlags(aFlags)
-    , mHasOwnOffset(false)
   {}
 
   bool YFlipped() const
-  { return mFlags & LAYER_RENDER_STATE_Y_FLIPPED; }
+  { return bool(mFlags & LayerRenderStateFlags::Y_FLIPPED); }
 
   bool BufferRotated() const
-  { return mFlags & LAYER_RENDER_STATE_BUFFER_ROTATION; }
+  { return bool(mFlags & LayerRenderStateFlags::BUFFER_ROTATION); }
 
   bool FormatRBSwapped() const
-  { return mFlags & LAYER_RENDER_STATE_FORMAT_RB_SWAP; }
+  { return bool(mFlags & LayerRenderStateFlags::FORMAT_RB_SWAP); }
 #endif
 
   void SetOffset(const nsIntPoint& aOffset)
   {
     mOffset = aOffset;
     mHasOwnOffset = true;
   }
 
+  // see LayerRenderStateFlags
+  LayerRenderStateFlags mFlags;
+  // true if mOffset is applicable
+  bool mHasOwnOffset;
+  // the location of the layer's origin on mSurface
+  nsIntPoint mOffset;
 #ifdef MOZ_WIDGET_GONK
   // surface to render
   android::sp<android::GraphicBuffer> mSurface;
   // size of mSurface 
   nsIntSize mSize;
   TextureHost* mTexture;
 #endif
-  // see LayerRenderStateFlags
-  uint32_t mFlags;
-  // the location of the layer's origin on mSurface
-  nsIntPoint mOffset;
-  // true if mOffset is applicable
-  bool mHasOwnOffset;
 };
 
 MOZ_BEGIN_ENUM_CLASS(ScaleMode, int8_t)
   SCALE_NONE,
   STRETCH,
   SENTINEL
 // Unimplemented - PRESERVE_ASPECT_RATIO_CONTAIN
 MOZ_END_ENUM_CLASS(ScaleMode)
--- a/gfx/layers/opengl/GrallocTextureHost.cpp
+++ b/gfx/layers/opengl/GrallocTextureHost.cpp
@@ -365,17 +365,17 @@ GrallocTextureHostOGL::DeallocateDeviceD
 {
   mTextureSource->DeallocateDeviceData();
 }
 
 LayerRenderState
 GrallocTextureHostOGL::GetRenderState()
 {
   if (IsValid()) {
-    uint32_t flags = 0;
+    LayerRenderStateFlags flags = LayerRenderStateFlags::LAYER_RENDER_STATE_DEFAULT;
     if (mFlags & TextureFlags::NEEDS_Y_FLIP) {
       flags |= LAYER_RENDER_STATE_Y_FLIPPED;
     }
     if (mFlags & TextureFlags::RB_SWAPPED) {
       flags |= LAYER_RENDER_STATE_FORMAT_RB_SWAP;
     }
     return LayerRenderState(mTextureSource->mGraphicBuffer.get(),
                             gfx::ThebesIntSize(mSize),