Bug 900133 - Recreate the TextureClient for an ImageClient if the image size changes. r=nical
authorMatt Woodrow <mwoodrow@mozilla.com>
Sat, 03 Aug 2013 13:29:18 -0400
changeset 148879 779afd60e5206c21a0844c0cb111cee536dbe426
parent 148878 2d80e7cf6e09fa5ffc15c6ee63a2540ff13c388b
child 148880 a525086d0bf298fa8d0d4f751eebb5c9273c6187
push idunknown
push userunknown
push dateunknown
reviewersnical
bugs900133
milestone25.0a1
Bug 900133 - Recreate the TextureClient for an ImageClient if the image size changes. r=nical
gfx/layers/client/ImageClient.cpp
gfx/layers/client/TextureClient.cpp
gfx/layers/client/TextureClient.h
gfx/layers/opengl/TextureClientOGL.h
--- a/gfx/layers/client/ImageClient.cpp
+++ b/gfx/layers/client/ImageClient.cpp
@@ -141,26 +141,28 @@ ImageClientSingle::UpdateImage(ImageCont
       MOZ_ASSERT(false);
       return false;
     }
 
   } else {
     nsRefPtr<gfxASurface> surface = image->GetAsSurface();
     MOZ_ASSERT(surface);
 
-    if (mFrontBuffer && mFrontBuffer->IsImmutable()) {
+    gfx::IntSize size = gfx::IntSize(image->GetSize().width, image->GetSize().height);
+
+    if (mFrontBuffer &&
+        (mFrontBuffer->IsImmutable() || mFrontBuffer->GetSize() != size)) {
       RemoveTextureClient(mFrontBuffer);
       mFrontBuffer = nullptr;
     }
 
     if (!mFrontBuffer) {
       gfxASurface::gfxImageFormat format
         = gfxPlatform::GetPlatform()->OptimalFormatForContent(surface->GetContentType());
       mFrontBuffer = CreateBufferTextureClient(gfx::ImageFormatToSurfaceFormat(format));
-      gfx::IntSize size = gfx::IntSize(image->GetSize().width, image->GetSize().height);
       MOZ_ASSERT(mFrontBuffer->AsTextureClientSurface());
       mFrontBuffer->AsTextureClientSurface()->AllocateForSurface(size);
 
       AddTextureClient(mFrontBuffer);
     }
 
     if (!mFrontBuffer->Lock(OPEN_READ_WRITE)) {
       return false;
--- a/gfx/layers/client/TextureClient.cpp
+++ b/gfx/layers/client/TextureClient.cpp
@@ -182,16 +182,17 @@ BufferTextureClient::AllocateForSurface(
 
   int bufSize
     = ImageDataSerializer::ComputeMinBufferSize(aSize, mFormat);
   if (!Allocate(bufSize)) {
     return false;
   }
   ImageDataSerializer serializer(GetBuffer());
   serializer.InitializeBufferInfo(aSize, mFormat);
+  mSize = aSize;
   return true;
 }
 
 bool
 BufferTextureClient::UpdateYCbCr(const PlanarYCbCrImage::Data& aData)
 {
   MOZ_ASSERT(mFormat == gfx::FORMAT_YUV, "This textureClient can only use YCbCr data");
   MOZ_ASSERT(!IsImmutable());
@@ -215,16 +216,17 @@ BufferTextureClient::AllocateForYCbCr(gf
   size_t bufSize = YCbCrImageDataSerializer::ComputeMinBufferSize(aYSize,
                                                                   aCbCrSize);
   if (!Allocate(bufSize)) {
     return false;
   }
   YCbCrImageDataSerializer serializer(GetBuffer());
   serializer.InitializeBufferInfo(aYSize,
                                   aCbCrSize);
+  mSize = aYSize;
   return true;
 }
 
 
 
 
 
 
--- a/gfx/layers/client/TextureClient.h
+++ b/gfx/layers/client/TextureClient.h
@@ -119,16 +119,18 @@ public:
   {
     return mNextSibling;
   }
 
   virtual bool IsAllocated() const = 0;
 
   virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aDescriptor) = 0;
 
+  virtual gfx::IntSize GetSize() const = 0;
+
   void SetFlags(TextureFlags aFlags)
   {
     MOZ_ASSERT(!IsSharedWithCompositor());
     mFlags = aFlags;
   }
 
   void AddFlags(TextureFlags  aFlags)
   {
@@ -188,16 +190,18 @@ public:
   virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aDescriptor) = 0;
 
   virtual bool Allocate(uint32_t aSize) = 0;
 
   virtual uint8_t* GetBuffer() const = 0;
 
   virtual size_t GetBufferSize() const = 0;
 
+  virtual gfx::IntSize GetSize() const { return mSize; }
+
   // TextureClientSurface
 
   virtual TextureClientSurface* AsTextureClientSurface() MOZ_OVERRIDE { return this; }
 
   virtual bool UpdateSurface(gfxASurface* aSurface) MOZ_OVERRIDE;
 
   virtual bool AllocateForSurface(gfx::IntSize aSize) MOZ_OVERRIDE;
 
@@ -209,16 +213,17 @@ public:
 
   virtual bool AllocateForYCbCr(gfx::IntSize aYSize, gfx::IntSize aCbCrSize) MOZ_OVERRIDE;
 
   gfx::SurfaceFormat GetFormat() const { return mFormat; }
 
 protected:
   CompositableClient* mCompositable;
   gfx::SurfaceFormat mFormat;
+  gfx::IntSize mSize;
 };
 
 /**
  * TextureClient that wraps shared memory.
  * the corresponding texture on the host side is ShmemTextureHost.
  */
 class ShmemTextureClient : public BufferTextureClient
 {
--- a/gfx/layers/opengl/TextureClientOGL.h
+++ b/gfx/layers/opengl/TextureClientOGL.h
@@ -34,17 +34,17 @@ public:
 
   virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) MOZ_OVERRIDE;
 
   void InitWith(gl::SharedTextureHandle aHandle,
                 gfx::IntSize aSize,
                 bool aIsCrossProcess = false,
                 bool aInverted = false);
 
-  gfx::IntSize GetSize() const { return mSize; }
+  virtual gfx::IntSize GetSize() const { return mSize; }
 
 protected:
   gfx::IntSize mSize;
   gl::SharedTextureHandle mHandle;
   bool mIsCrossProcess;
   bool mInverted;
 };