Bug 1031553 - Create GrallocTextureSourceOGL only when GrallocTextureHostOGL has a gralloc buffer r=nical
authorSotaro Ikeda <sikeda@mozilla.com>
Fri, 04 Jul 2014 06:16:13 -0700
changeset 192418 b7f8089105b216ecfe8167e2a6f5dfd703dab935
parent 192417 ae88c59d32847f545f2d0d0f15c68d19c9fbe6f1
child 192419 2ec73f026a68e49843701dc92fa423b770171ad4
push id27086
push userttaubert@mozilla.com
push dateSun, 06 Jul 2014 16:11:25 +0000
treeherdermozilla-central@9f59e39f70a5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical
bugs1031553
milestone33.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 1031553 - Create GrallocTextureSourceOGL only when GrallocTextureHostOGL has a gralloc buffer r=nical
gfx/layers/client/CompositableClient.cpp
gfx/layers/opengl/GrallocTextureHost.cpp
--- a/gfx/layers/client/CompositableClient.cpp
+++ b/gfx/layers/client/CompositableClient.cpp
@@ -200,16 +200,19 @@ CompositableClient::CreateTextureClientF
                                                       aTextureFlags | mTextureFlags,
                                                       aMoz2DBackend,
                                                       aSizeHint);
 }
 
 bool
 CompositableClient::AddTextureClient(TextureClient* aClient)
 {
+  if(!aClient || !aClient->IsAllocated()) {
+    return false;
+  }
   return aClient->InitIPDLActor(mForwarder);
 }
 
 void
 CompositableClient::OnTransaction()
 {
 }
 
--- a/gfx/layers/opengl/GrallocTextureHost.cpp
+++ b/gfx/layers/opengl/GrallocTextureHost.cpp
@@ -300,34 +300,36 @@ GrallocTextureHostOGL::GrallocTextureHos
   android::GraphicBuffer* graphicBuffer = GetGraphicBufferFromDesc(mGrallocHandle).get();
   MOZ_ASSERT(graphicBuffer);
 
   mSize = aDescriptor.size();
   if (graphicBuffer) {
     format =
       SurfaceFormatForAndroidPixelFormat(graphicBuffer->getPixelFormat(),
                                          aFlags & TextureFlags::RB_SWAPPED);
+    mTextureSource = new GrallocTextureSourceOGL(nullptr,
+                                                 this,
+                                                 graphicBuffer,
+                                                 format);
   } else {
-    NS_WARNING("gralloc buffer is nullptr");
+    printf_stderr("gralloc buffer is nullptr");
   }
-  mTextureSource = new GrallocTextureSourceOGL(nullptr,
-                                               this,
-                                               graphicBuffer,
-                                               format);
 }
 
 GrallocTextureHostOGL::~GrallocTextureHostOGL()
 {
   mTextureSource = nullptr;
 }
 
 void
 GrallocTextureHostOGL::SetCompositor(Compositor* aCompositor)
 {
-  mTextureSource->SetCompositor(static_cast<CompositorOGL*>(aCompositor));
+  if (mTextureSource) {
+    mTextureSource->SetCompositor(static_cast<CompositorOGL*>(aCompositor));
+  }
 }
 
 bool
 GrallocTextureHostOGL::Lock()
 {
   if (IsValid()) {
     mTextureSource->Lock();
     return true;
@@ -339,30 +341,37 @@ void
 GrallocTextureHostOGL::Unlock()
 {
   // Unlock is done internally by binding the texture to another gralloc buffer
 }
 
 bool
 GrallocTextureHostOGL::IsValid() const
 {
+  if (!mTextureSource) {
+    return false;
+  }
   return mTextureSource->IsValid();
 }
 
 gfx::SurfaceFormat
 GrallocTextureHostOGL::GetFormat() const
 {
+  if (!mTextureSource) {
+    return gfx::SurfaceFormat::UNKNOWN;
+  }
   return mTextureSource->GetFormat();
 }
 
 void
 GrallocTextureHostOGL::DeallocateSharedData()
 {
   if (mTextureSource) {
     mTextureSource->ForgetBuffer();
+    mTextureSource = nullptr;
   }
   if (mGrallocHandle.buffer().type() != SurfaceDescriptor::Tnull_t) {
     MaybeMagicGrallocBufferHandle handle = mGrallocHandle.buffer();
     base::ProcessId owner;
     if (handle.type() == MaybeMagicGrallocBufferHandle::TGrallocBufferRef) {
       owner = handle.get_GrallocBufferRef().mOwner;
     }
     else {
@@ -373,23 +382,26 @@ GrallocTextureHostOGL::DeallocateSharedD
   }
 }
 
 void
 GrallocTextureHostOGL::ForgetSharedData()
 {
   if (mTextureSource) {
     mTextureSource->ForgetBuffer();
+    mTextureSource = nullptr;
   }
 }
 
 void
 GrallocTextureHostOGL::DeallocateDeviceData()
 {
-  mTextureSource->DeallocateDeviceData();
+  if (mTextureSource) {
+    mTextureSource->DeallocateDeviceData();
+  }
 }
 
 LayerRenderState
 GrallocTextureHostOGL::GetRenderState()
 {
   if (IsValid()) {
     LayerRenderStateFlags flags = LayerRenderStateFlags::LAYER_RENDER_STATE_DEFAULT;
     if (mFlags & TextureFlags::NEEDS_Y_FLIP) {