diff --git a/gfx/layers/client/CanvasClient.cpp b/gfx/layers/client/CanvasClient.cpp index 8bd9d48dcf80..87ecd1e16b33 100644 --- a/gfx/layers/client/CanvasClient.cpp +++ b/gfx/layers/client/CanvasClient.cpp @@ -22,20 +22,15 @@ namespace mozilla { namespace layers { /* static */ TemporaryRef -CanvasClient::CreateCanvasClient(CompositableType aCompositableHostType, +CanvasClient::CreateCanvasClient(CanvasClientType aType, CompositableForwarder* aForwarder, TextureFlags aFlags) { - if (aCompositableHostType == BUFFER_IMAGE_SINGLE) { - return new CanvasClient2D(aForwarder, aFlags); + if (aType == CanvasClientGLContext && + aForwarder->GetCompositorBackendType() == LAYERS_OPENGL) { + return new CanvasClientSurfaceStream(aForwarder, aFlags); } - if (aCompositableHostType == BUFFER_IMAGE_BUFFERED) { - if (aForwarder->GetCompositorBackendType() == LAYERS_OPENGL) { - return new CanvasClientWebGL(aForwarder, aFlags); - } - return new CanvasClient2D(aForwarder, aFlags); - } - return nullptr; + return new CanvasClient2D(aForwarder, aFlags); } void @@ -72,28 +67,32 @@ CanvasClient2D::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) } void -CanvasClientWebGL::Updated() +CanvasClientSurfaceStream::Updated() { - mForwarder->UpdateTextureNoSwap(this, 1, mDeprecatedTextureClient->GetDescriptor()); + if (mNeedsUpdate) { + mForwarder->UpdateTextureNoSwap(this, 1, mDeprecatedTextureClient->GetDescriptor()); + mNeedsUpdate = false; + } } -CanvasClientWebGL::CanvasClientWebGL(CompositableForwarder* aFwd, - TextureFlags aFlags) +CanvasClientSurfaceStream::CanvasClientSurfaceStream(CompositableForwarder* aFwd, + TextureFlags aFlags) : CanvasClient(aFwd, aFlags) +, mNeedsUpdate(false) { - mTextureInfo.mCompositableType = BUFFER_IMAGE_BUFFERED; + mTextureInfo.mCompositableType = BUFFER_IMAGE_SINGLE; } void -CanvasClientWebGL::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) +CanvasClientSurfaceStream::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) { if (!mDeprecatedTextureClient) { mDeprecatedTextureClient = CreateDeprecatedTextureClient(TEXTURE_STREAM_GL); MOZ_ASSERT(mDeprecatedTextureClient, "Failed to create texture client"); } - NS_ASSERTION(aLayer->mGLContext, "CanvasClientWebGL should only be used with GL canvases"); + NS_ASSERTION(aLayer->mGLContext, "CanvasClientSurfaceStream should only be used with GL canvases"); // the content type won't be used mDeprecatedTextureClient->EnsureAllocated(aSize, gfxASurface::CONTENT_COLOR); @@ -122,15 +121,21 @@ CanvasClientWebGL::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) printf_stderr("isCrossProcess, but not MOZ_WIDGET_GONK! Someone needs to write some code!"); MOZ_ASSERT(false); #endif + mNeedsUpdate = true; } else { SurfaceStreamHandle handle = stream->GetShareHandle(); - mDeprecatedTextureClient->SetDescriptor(SurfaceStreamDescriptor(handle, false)); + SurfaceDescriptor *desc = mDeprecatedTextureClient->GetDescriptor(); + if (desc->type() != SurfaceDescriptor::TSurfaceStreamDescriptor || + desc->get_SurfaceStreamDescriptor().handle() != handle) { + *desc = SurfaceStreamDescriptor(handle, false); - // Bug 894405 - // - // Ref this so the SurfaceStream doesn't disappear unexpectedly. The - // Compositor will need to unref it when finished. - aLayer->mGLContext->AddRef(); + // Bug 894405 + // + // Ref this so the SurfaceStream doesn't disappear unexpectedly. The + // Compositor will need to unref it when finished. + aLayer->mGLContext->AddRef(); + mNeedsUpdate = true; + } } aLayer->Painted(); diff --git a/gfx/layers/client/CanvasClient.h b/gfx/layers/client/CanvasClient.h index ac34008a4d38..4fc13f8cf193 100644 --- a/gfx/layers/client/CanvasClient.h +++ b/gfx/layers/client/CanvasClient.h @@ -26,7 +26,11 @@ public: * message will be sent to the compositor to create a corresponding image * host. */ - static TemporaryRef CreateCanvasClient(CompositableType aImageHostType, + enum CanvasClientType { + CanvasClientSurface, + CanvasClientGLContext, + }; + static TemporaryRef CreateCanvasClient(CanvasClientType aType, CompositableForwarder* aFwd, TextureFlags aFlags); @@ -69,11 +73,11 @@ public: // Used for GL canvases where we don't need to do any readback, i.e., with a // GL backend. -class CanvasClientWebGL : public CanvasClient +class CanvasClientSurfaceStream : public CanvasClient { public: - CanvasClientWebGL(CompositableForwarder* aFwd, - TextureFlags aFlags); + CanvasClientSurfaceStream(CompositableForwarder* aFwd, + TextureFlags aFlags); TextureInfo GetTextureInfo() const MOZ_OVERRIDE { @@ -82,6 +86,9 @@ public: virtual void Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer); virtual void Updated() MOZ_OVERRIDE; + +private: + bool mNeedsUpdate; }; } diff --git a/gfx/layers/client/ClientCanvasLayer.cpp b/gfx/layers/client/ClientCanvasLayer.cpp index a6d3e73e2e9b..0524770b556d 100644 --- a/gfx/layers/client/ClientCanvasLayer.cpp +++ b/gfx/layers/client/ClientCanvasLayer.cpp @@ -94,7 +94,7 @@ ClientCanvasLayer::RenderLayer() flags |= TEXTURE_DEALLOCATE_CLIENT; } } - mCanvasClient = CanvasClient::CreateCanvasClient(GetCompositableClientType(), + mCanvasClient = CanvasClient::CreateCanvasClient(GetCanvasClientType(), ClientManager(), flags); if (!mCanvasClient) { return; diff --git a/gfx/layers/client/ClientCanvasLayer.h b/gfx/layers/client/ClientCanvasLayer.h index 08e42d632e53..ed2e8c6bb6a1 100644 --- a/gfx/layers/client/ClientCanvasLayer.h +++ b/gfx/layers/client/ClientCanvasLayer.h @@ -25,6 +25,7 @@ class CanvasClientWebGL; class ClientCanvasLayer : public CopyableCanvasLayer, public ClientLayer { + typedef CanvasClient::CanvasClientType CanvasClientType; public: ClientCanvasLayer(ClientLayerManager* aLayerManager) : CopyableCanvasLayer(aLayerManager, static_cast(this)) @@ -75,18 +76,18 @@ protected: return static_cast(mManager); } - CompositableType GetCompositableClientType() + CanvasClientType GetCanvasClientType() { if (mGLContext) { - return BUFFER_IMAGE_BUFFERED; + return CanvasClient::CanvasClientGLContext; } - return BUFFER_IMAGE_SINGLE; + return CanvasClient::CanvasClientSurface; } RefPtr mCanvasClient; friend class CanvasClient2D; - friend class CanvasClientWebGL; + friend class CanvasClientSurfaceStream; }; } } diff --git a/gfx/layers/opengl/TextureHostOGL.cpp b/gfx/layers/opengl/TextureHostOGL.cpp index 61703eb4c757..13feb39c8e5b 100644 --- a/gfx/layers/opengl/TextureHostOGL.cpp +++ b/gfx/layers/opengl/TextureHostOGL.cpp @@ -592,27 +592,23 @@ SurfaceStreamHostOGL::DeleteTextures() } void -SurfaceStreamHostOGL::SwapTexturesImpl(const SurfaceDescriptor& aImage, - nsIntRegion* aRegion) +SurfaceStreamHostOGL::UpdateImpl(const SurfaceDescriptor& aImage, + nsIntRegion* aRegion, + nsIntPoint* aOffset) { MOZ_ASSERT(aImage.type() == SurfaceDescriptor::TSurfaceStreamDescriptor, "Invalid descriptor"); - mStreamGL = nullptr; + // Bug 894405 + // + // The SurfaceStream's GLContext was refed before being passed up to us, so + // we need to ensure it gets unrefed when we are finished. + const SurfaceStreamDescriptor& streamDesc = + aImage.get_SurfaceStreamDescriptor(); - if (aImage.type() == SurfaceDescriptor::TSurfaceStreamDescriptor) { - // Bug 894405 - // - // The SurfaceStream's GLContext was refed before being passed up to us, so - // we need to ensure it gets unrefed when we are finished. - const SurfaceStreamDescriptor& streamDesc = - aImage.get_SurfaceStreamDescriptor(); - - SurfaceStream* surfStream = SurfaceStream::FromHandle(streamDesc.handle()); - if (surfStream) { - mStreamGL = dont_AddRef(surfStream->GLContext()); - } - } + mStream = SurfaceStream::FromHandle(streamDesc.handle()); + MOZ_ASSERT(mStream); + mStreamGL = dont_AddRef(mStream->GLContext()); } void @@ -626,15 +622,8 @@ bool SurfaceStreamHostOGL::Lock() { mGL->MakeCurrent(); - SurfaceStream* surfStream = nullptr; - SharedSurface* sharedSurf = nullptr; - const SurfaceStreamDescriptor& streamDesc = - mBuffer->get_SurfaceStreamDescriptor(); - surfStream = SurfaceStream::FromHandle(streamDesc.handle()); - MOZ_ASSERT(surfStream); - - sharedSurf = surfStream->SwapConsumer(); + SharedSurface* sharedSurf = mStream->SwapConsumer(); if (!sharedSurf) { // We don't have a valid surf to show yet. return false; diff --git a/gfx/layers/opengl/TextureHostOGL.h b/gfx/layers/opengl/TextureHostOGL.h index 865c10aa01d3..009043537a0b 100644 --- a/gfx/layers/opengl/TextureHostOGL.h +++ b/gfx/layers/opengl/TextureHostOGL.h @@ -652,7 +652,6 @@ public: virtual ~SurfaceStreamHostOGL() { DeleteTextures(); - *mBuffer = SurfaceDescriptor(); } virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE; @@ -672,8 +671,9 @@ public: bool IsValid() const MOZ_OVERRIDE { return true; } // override from DeprecatedTextureHost - virtual void SwapTexturesImpl(const SurfaceDescriptor& aImage, - nsIntRegion* aRegion = nullptr) MOZ_OVERRIDE; + virtual void UpdateImpl(const SurfaceDescriptor& aImage, + nsIntRegion* aRegion, + nsIntPoint* aOffset); virtual bool Lock() MOZ_OVERRIDE; virtual void Unlock() MOZ_OVERRIDE; @@ -720,6 +720,7 @@ public: , mTextureTarget(LOCAL_GL_TEXTURE_2D) , mUploadTexture(0) , mWrapMode(LOCAL_GL_CLAMP_TO_EDGE) + , mStream(nullptr) {} protected: @@ -732,6 +733,7 @@ protected: GLuint mUploadTexture; GLenum mWrapMode; nsRefPtr mStreamGL; + gfx::SurfaceStream *mStream; }; class TiledDeprecatedTextureHostOGL : public DeprecatedTextureHost