Bug 862952, Re-enable Composer2D after layers refactoring. r=bjacob,f=diego
authorNicholas Cameron <ncameron@mozilla.com>
Thu, 06 Jun 2013 10:14:51 +1200
changeset 134529 8634a682e6469d40b218fa52ee36ffecfcd13a8c
parent 134528 12cdc8931e48dd8210b1a6d7eed5ad5701ed9708
child 134530 d4b12367230188751eaf82db1d44e2ab14a8548c
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersbjacob
bugs862952
milestone24.0a1
Bug 862952, Re-enable Composer2D after layers refactoring. r=bjacob,f=diego
gfx/layers/LayersTypes.h
gfx/layers/client/CompositableClient.h
gfx/layers/composite/ContentHost.h
gfx/layers/composite/ImageHost.h
gfx/layers/composite/ImageLayerComposite.cpp
gfx/layers/composite/LayerManagerComposite.cpp
gfx/layers/composite/TextureHost.h
gfx/layers/ipc/LayerTransactionParent.cpp
gfx/layers/opengl/LayerManagerOGL.h
gfx/layers/opengl/TextureHostOGL.cpp
gfx/layers/opengl/TextureHostOGL.h
widget/gonk/HwcComposer2D.cpp
--- a/gfx/layers/LayersTypes.h
+++ b/gfx/layers/LayersTypes.h
@@ -2,37 +2,42 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_LAYERSTYPES_H
 #define GFX_LAYERSTYPES_H
 
 #include "nsPoint.h"
-
+#ifdef MOZ_WIDGET_GONK
+#include <ui/GraphicBuffer.h>
+#endif
 #if defined(DEBUG) || defined(PR_LOGGING)
 #  include <stdio.h>            // FILE
 #  include "prlog.h"
 #  ifndef MOZ_LAYERS_HAVE_LOG
 #    define MOZ_LAYERS_HAVE_LOG
 #  endif
 #  define MOZ_LAYERS_LOG(_args)                             \
   PR_LOG(LayerManager::GetLog(), PR_LOG_DEBUG, _args)
 #  define MOZ_LAYERS_LOG_IF_SHADOWABLE(layer, _args)         \
   do { if (layer->AsShadowableLayer()) { PR_LOG(LayerManager::GetLog(), PR_LOG_DEBUG, _args); } } while (0)
 #else
 struct PRLogModuleInfo;
 #  define MOZ_LAYERS_LOG(_args)
 #  define MOZ_LAYERS_LOG_IF_SHADOWABLE(layer, _args)
 #endif  // if defined(DEBUG) || defined(PR_LOGGING)
 
+namespace android {
+class GraphicBuffer;
+}
+
 namespace mozilla {
 namespace layers {
 
-class SurfaceDescriptor;
 
 typedef uint32_t TextureFlags;
 
 enum LayersBackend {
   LAYERS_NONE = 0,
   LAYERS_BASIC,
   LAYERS_OPENGL,
   LAYERS_D3D9,
@@ -52,46 +57,65 @@ enum BufferMode {
 enum MaskType {
   MaskNone = 0,   // no mask layer
   Mask2d,         // mask layer for layers with 2D transforms
   Mask3d,         // mask layer for layers with 3D transforms
   NumMaskTypes
 };
 
 // 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
 };
 
+// The 'ifdef MOZ_WIDGET_GONK' sadness here is because we don't want to include
+// android::sp unless we have to.
 struct LayerRenderState {
-  LayerRenderState() : mSurface(nullptr), mFlags(0), mHasOwnOffset(false)
+  LayerRenderState()
+#ifdef MOZ_WIDGET_GONK
+    : mSurface(nullptr), mFlags(0), mHasOwnOffset(false)
+#endif
   {}
 
-  LayerRenderState(SurfaceDescriptor* aSurface, uint32_t aFlags = 0)
+#ifdef MOZ_WIDGET_GONK
+  LayerRenderState(android::GraphicBuffer* aSurface,
+                   const nsIntSize& aSize,
+                   uint32_t aFlags)
     : mSurface(aSurface)
+    , mSize(aSize)
     , mFlags(aFlags)
     , mHasOwnOffset(false)
   {}
 
-  LayerRenderState(SurfaceDescriptor* aSurface, nsIntPoint aOffset, uint32_t aFlags = 0)
-    : mSurface(aSurface)
-    , mFlags(aFlags)
-    , mOffset(aOffset)
-    , mHasOwnOffset(true)
-  {}
-
   bool YFlipped() const
   { return mFlags & LAYER_RENDER_STATE_Y_FLIPPED; }
 
   bool BufferRotated() const
   { return mFlags & LAYER_RENDER_STATE_BUFFER_ROTATION; }
+#endif
 
-  SurfaceDescriptor* mSurface;
+  void SetOffset(const nsIntPoint& aOffset)
+  {
+    mOffset = aOffset;
+    mHasOwnOffset = true;
+  }
+
+#ifdef MOZ_WIDGET_GONK
+  // surface to render
+  android::sp<android::GraphicBuffer> mSurface;
+  // size of mSurface 
+  nsIntSize mSize;
+#endif
+  // see LayerRenderStateFlags
   uint32_t mFlags;
+  // the location of the layer's origin on mSurface
   nsIntPoint mOffset;
+  // true if mOffset is applicable
   bool mHasOwnOffset;
 };
 
 } // namespace
 } // namespace
 
 #endif /* GFX_LAYERSTYPES_H */
--- a/gfx/layers/client/CompositableClient.h
+++ b/gfx/layers/client/CompositableClient.h
@@ -15,16 +15,17 @@ namespace layers {
 
 class CompositableChild;
 class CompositableClient;
 class TextureClient;
 class ImageBridgeChild;
 class ShadowableLayer;
 class CompositableForwarder;
 class CompositableChild;
+class SurfaceDescriptor;
 
 /**
  * CompositableClient manages the texture-specific logic for composite layers,
  * independently of the layer. It is the content side of a ConmpositableClient/
  * CompositableHost pair.
  *
  * CompositableClient's purpose is to send texture data to the compositor side
  * along with any extra information about how the texture is to be composited.
--- a/gfx/layers/composite/ContentHost.h
+++ b/gfx/layers/composite/ContentHost.h
@@ -78,16 +78,17 @@ public:
   }
 
   virtual LayerRenderState GetRenderState() MOZ_OVERRIDE
   {
     LayerRenderState result = mTextureHost->GetRenderState();
 
     result.mFlags = (mBufferRotation != nsIntPoint()) ?
                     LAYER_RENDER_STATE_BUFFER_ROTATION : 0;
+    result.SetOffset(GetOriginOffset());
     return result;
   }
 
   virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
 
 #ifdef MOZ_DUMP_PAINTING
   virtual already_AddRefed<gfxImageSurface> GetAsSurface()
   {
--- a/gfx/layers/composite/ImageHost.h
+++ b/gfx/layers/composite/ImageHost.h
@@ -73,17 +73,20 @@ public:
   virtual void SetPictureRect(const nsIntRect& aPictureRect) MOZ_OVERRIDE
   {
     mPictureRect = aPictureRect;
     mHasPictureRect = true;
   }
 
   virtual LayerRenderState GetRenderState() MOZ_OVERRIDE
   {
-    return mTextureHost->GetRenderState();
+    if (mTextureHost) {
+      return mTextureHost->GetRenderState();
+    }
+    return LayerRenderState();
   }
 
   virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
 
   virtual void Dump(FILE* aFile=NULL,
                     const char* aPrefix="",
                     bool aDumpHtml=false) MOZ_OVERRIDE;
 
--- a/gfx/layers/composite/ImageLayerComposite.cpp
+++ b/gfx/layers/composite/ImageLayerComposite.cpp
@@ -49,20 +49,20 @@ void
 ImageLayerComposite::Disconnect()
 {
   Destroy();
 }
 
 LayerRenderState
 ImageLayerComposite::GetRenderState()
 {
-  if (!mImageHost) {
-    return LayerRenderState();
+  if (mImageHost) {
+    return mImageHost->GetRenderState();
   }
-  return mImageHost->GetRenderState();
+  return LayerRenderState();
 }
 
 Layer*
 ImageLayerComposite::GetLayer()
 {
   return this;
 }
 
--- a/gfx/layers/composite/LayerManagerComposite.cpp
+++ b/gfx/layers/composite/LayerManagerComposite.cpp
@@ -92,18 +92,19 @@ LayerManagerComposite::~LayerManagerComp
 {
   Destroy();
 }
 
 
 bool
 LayerManagerComposite::Initialize()
 {
+  bool result = mCompositor->Initialize();
   mComposer2D = mCompositor->GetWidget()->GetComposer2D();
-  return mCompositor->Initialize();
+  return result;
 }
 
 void
 LayerManagerComposite::Destroy()
 {
   if (!mDestroyed) {
     mCompositor->GetWidget()->CleanupWindowEffects();
     if (mRoot) {
--- a/gfx/layers/composite/TextureHost.h
+++ b/gfx/layers/composite/TextureHost.h
@@ -233,20 +233,19 @@ public:
   {
     return GetIdentifier() == o.GetIdentifier();
   }
   bool operator!= (const TextureHost& o) const
   {
     return GetIdentifier() != o.GetIdentifier();
   }
 
-  LayerRenderState GetRenderState()
+  virtual LayerRenderState GetRenderState()
   {
-    return LayerRenderState(mBuffer,
-                            mFlags & NeedsYFlip ? LAYER_RENDER_STATE_Y_FLIPPED : 0);
+    return LayerRenderState();
   }
 
   virtual already_AddRefed<gfxImageSurface> GetAsSurface() = 0;
 
 #ifdef MOZ_LAYERS_HAVE_LOG
   virtual const char *Name() = 0;
   virtual void PrintInfo(nsACString& aTo, const char* aPrefix);
 #endif
--- a/gfx/layers/ipc/LayerTransactionParent.cpp
+++ b/gfx/layers/ipc/LayerTransactionParent.cpp
@@ -486,24 +486,23 @@ LayerTransactionParent::RecvGetTransform
   return true;
 }
 
 void
 LayerTransactionParent::Attach(ShadowLayerParent* aLayerParent, CompositableParent* aCompositable)
 {
   LayerComposite* layer = aLayerParent->AsLayer()->AsLayerComposite();
   MOZ_ASSERT(layer);
-  LayerComposite* layerComposite = aLayerParent->AsLayer()->AsLayerComposite();
 
   Compositor* compositor
     = static_cast<LayerManagerComposite*>(aLayerParent->AsLayer()->Manager())->GetCompositor();
 
   CompositableHost* compositable = aCompositable->GetCompositableHost();
   MOZ_ASSERT(compositable);
-  layerComposite->SetCompositableHost(compositable);
+  layer->SetCompositableHost(compositable);
   compositable->Attach(aLayerParent->AsLayer(), compositor);
 }
 
 bool
 LayerTransactionParent::RecvClearCachedResources()
 {
   if (mRoot) {
     // NB: |mRoot| here is the *child* context's root.  In this parent
--- a/gfx/layers/opengl/LayerManagerOGL.h
+++ b/gfx/layers/opengl/LayerManagerOGL.h
@@ -445,18 +445,16 @@ public:
 
   /* Do NOT call this from the generic LayerOGL destructor.  Only from the
    * concrete class destructor
    */
   virtual void Destroy() = 0;
 
   virtual Layer* GetLayer() = 0;
 
-  virtual LayerRenderState GetRenderState() { return LayerRenderState(); }
-
   virtual void RenderLayer(int aPreviousFrameBuffer,
                            const nsIntPoint& aOffset) = 0;
 
   typedef mozilla::gl::GLContext GLContext;
 
   LayerManagerOGL* OGLManager() const { return mOGLManager; }
   GLContext *gl() const { return mOGLManager->gl(); }
   virtual void CleanupResources() = 0;
--- a/gfx/layers/opengl/TextureHostOGL.cpp
+++ b/gfx/layers/opengl/TextureHostOGL.cpp
@@ -851,16 +851,27 @@ GrallocTextureHostOGL::SetBuffer(Surface
   mBuffer = aBuffer;
   mDeAllocator = aAllocator;
 
   // only done for hacky fix in gecko 23 for bug 862324.
   // Doing this in SwapTextures is not enough, as the crash could occur right after SetBuffer.
   RegisterTextureHostAtGrallocBufferActor(this, *mBuffer);
 }
 
+LayerRenderState
+GrallocTextureHostOGL::GetRenderState()
+{
+  if (mBuffer && IsSurfaceDescriptorValid(*mBuffer)) {
+    return LayerRenderState(mGraphicBuffer.get(),
+                            mBuffer->get_SurfaceDescriptorGralloc().size(),
+                            mFlags & NeedsYFlip ? LAYER_RENDER_STATE_Y_FLIPPED : 0);
+  }
+
+  return LayerRenderState();
+}
 #endif // MOZ_WIDGET_GONK
 
 already_AddRefed<gfxImageSurface>
 TextureImageTextureHostOGL::GetAsSurface() {
   nsRefPtr<gfxImageSurface> surf = IsValid() ?
     mGL->GetTexImage(mTexture->GetTextureID(),
                      false,
                      mTexture->GetShaderProgramType())
--- a/gfx/layers/opengl/TextureHostOGL.h
+++ b/gfx/layers/opengl/TextureHostOGL.h
@@ -636,16 +636,18 @@ public:
       delete mBuffer;
       mBuffer = nullptr;
     }
 
     mGraphicBuffer = nullptr;
     DeleteTextures();
   }
 
+  virtual LayerRenderState GetRenderState() MOZ_OVERRIDE;
+
 private:
   gl::GLContext* gl() const;
 
   void DeleteTextures();
 
   RefPtr<CompositorOGL> mCompositor;
   android::sp<android::GraphicBuffer> mGraphicBuffer;
   GLenum mTextureTarget;
--- a/widget/gonk/HwcComposer2D.cpp
+++ b/widget/gonk/HwcComposer2D.cpp
@@ -15,17 +15,17 @@
  */
 
 #include <android/log.h>
 #include <string.h>
 
 #include "libdisplay/GonkDisplay.h"
 #include "Framebuffer.h"
 #include "HwcComposer2D.h"
-#include "LayerManagerOGL.h"
+#include "mozilla/layers/LayerManagerComposite.h"
 #include "mozilla/layers/PLayerTransaction.h"
 #include "mozilla/layers/ShadowLayerUtilsGralloc.h"
 #include "mozilla/StaticPtr.h"
 #include "cutils/properties.h"
 #include "gfxUtils.h"
 
 #define LOG_TAG "HWComposer"
 
@@ -335,25 +335,22 @@ HwcComposer2D::PrepareLayerList(Layer* a
         for (uint32_t i = 0; i < children.Length(); i++) {
             if (!PrepareLayerList(children[i], clip, transform, aGLWorldTransform)) {
                 return false;
             }
         }
         return true;
     }
 
-    LayerOGL* layerGL = static_cast<LayerOGL*>(aLayer->ImplData());
-    LayerRenderState state = layerGL->GetRenderState();
+    LayerRenderState state = aLayer->GetRenderState();
     nsIntSize surfaceSize;
 
-    if (state.mSurface &&
-        state.mSurface->type() == SurfaceDescriptor::TSurfaceDescriptorGralloc) {
-        surfaceSize = state.mSurface->get_SurfaceDescriptorGralloc().size();
-    }
-    else {
+    if (state.mSurface.get()) {
+        surfaceSize = state.mSize;
+    } else {
         if (aLayer->AsColorLayer() && mColorFill) {
             fillColor = true;
         } else {
             LOGD("Layer doesn't have a gralloc buffer");
             return false;
         }
     }
     if (state.BufferRotated()) {
@@ -367,46 +364,44 @@ HwcComposer2D::PrepareLayerList(Layer* a
     int current = mList ? mList->numHwLayers : 0;
     if (!mList || current >= mMaxLayerCount) {
         if (!ReallocLayerList() || current >= mMaxLayerCount) {
             LOGE("PrepareLayerList failed! Could not increase the maximum layer count");
             return false;
         }
     }
 
-    sp<GraphicBuffer> buffer = fillColor ? nullptr : GrallocBufferActor::GetFrom(*state.mSurface);
-
     nsIntRect visibleRect = visibleRegion.GetBounds();
 
     nsIntRect bufferRect;
     if (fillColor) {
         bufferRect = nsIntRect(visibleRect);
     } else {
         if(state.mHasOwnOffset) {
             bufferRect = nsIntRect(state.mOffset.x, state.mOffset.y,
-                surfaceSize.width, surfaceSize.height);
+                                   state.mSize.width, state.mSize.height);
         } else {
             bufferRect = nsIntRect(visibleRect.x, visibleRect.y,
-                surfaceSize.width, surfaceSize.height);
+                                   state.mSize.width, state.mSize.height);
         }
     }
 
     hwc_layer_t& hwcLayer = mList->hwLayers[current];
 
     if(!PrepareLayerRects(visibleRect,
                           transform * aGLWorldTransform,
                           clip,
                           bufferRect,
                           &(hwcLayer.sourceCrop),
                           &(hwcLayer.displayFrame)))
     {
         return true;
     }
 
-    buffer_handle_t handle = fillColor ? nullptr : buffer->getNativeBuffer()->handle;
+    buffer_handle_t handle = fillColor ? nullptr : state.mSurface->getNativeBuffer()->handle;
     hwcLayer.handle = handle;
 
     hwcLayer.flags = 0;
     hwcLayer.hints = 0;
     hwcLayer.blending = HWC_BLENDING_PREMULT;
     hwcLayer.compositionType = HWC_USE_COPYBIT;
 
     if (!fillColor) {