diff --git a/gfx/layers/ThebesLayerBuffer.cpp b/gfx/layers/ThebesLayerBuffer.cpp index 7764943bab7..3d65f99c905 100644 --- a/gfx/layers/ThebesLayerBuffer.cpp +++ b/gfx/layers/ThebesLayerBuffer.cpp @@ -424,6 +424,10 @@ ThebesLayerBuffer::IsAzureBuffer() if (mBuffer) { return false; } + if (mBufferProvider) { + return gfxPlatform::GetPlatform()->SupportsAzureContentForType( + mBufferProvider->BackendType()); + } return SupportsAzureContent(); } @@ -651,13 +655,9 @@ ThebesLayerBuffer::BeginPaint(ThebesLayer* aLayer, ContentType aContentType, // We can't do a real self-copy because the buffer is rotated. // So allocate a new buffer for the destination. destBufferRect = ComputeBufferRect(neededRegion.GetBounds()); - if (IsAzureBuffer()) { - MOZ_ASSERT(!mBuffer); - destDTBuffer = CreateDTBuffer(contentType, destBufferRect, bufferFlags, &destDTBufferOnWhite); - } else { - MOZ_ASSERT(!mDTBuffer); - destBuffer = CreateBuffer(contentType, destBufferRect, bufferFlags, getter_AddRefs(destBufferOnWhite)); - } + CreateBuffer(contentType, destBufferRect, bufferFlags, + getter_AddRefs(destBuffer), getter_AddRefs(destBufferOnWhite), + &destDTBuffer, &destDTBufferOnWhite); if (!destBuffer && !destDTBuffer) return result; } @@ -674,13 +674,9 @@ ThebesLayerBuffer::BeginPaint(ThebesLayer* aLayer, ContentType aContentType, } } else { // The buffer's not big enough, so allocate a new one - if (IsAzureBuffer()) { - MOZ_ASSERT(!mBuffer); - destDTBuffer = CreateDTBuffer(contentType, destBufferRect, bufferFlags, &destDTBufferOnWhite); - } else { - MOZ_ASSERT(!mDTBuffer); - destBuffer = CreateBuffer(contentType, destBufferRect, bufferFlags, getter_AddRefs(destBufferOnWhite)); - } + CreateBuffer(contentType, destBufferRect, bufferFlags, + getter_AddRefs(destBuffer), getter_AddRefs(destBufferOnWhite), + &destDTBuffer, &destDTBufferOnWhite); if (!destBuffer && !destDTBuffer) return result; } diff --git a/gfx/layers/ThebesLayerBuffer.h b/gfx/layers/ThebesLayerBuffer.h index 5725e9bc2c1..f578bd1cf0a 100644 --- a/gfx/layers/ThebesLayerBuffer.h +++ b/gfx/layers/ThebesLayerBuffer.h @@ -245,12 +245,14 @@ public: * Return a new surface of |aSize| and |aType|. * @param aFlags if ALLOW_REPEAT is set, then the buffer should be configured * to allow repeat-mode, otherwise it should be in pad (clamp) mode + * If the created buffer supports azure content, then the result(s) will + * be returned in aBlackDT/aWhiteDT, otherwise aBlackSurface/aWhiteSurface + * will be used. */ - virtual already_AddRefed - CreateBuffer(ContentType aType, const nsIntRect& aRect, uint32_t aFlags, gfxASurface** aWhiteSurface) = 0; - virtual TemporaryRef - CreateDTBuffer(ContentType aType, const nsIntRect& aRect, uint32_t aFlags, RefPtr* aWhiteDT) - { NS_RUNTIMEABORT("CreateDTBuffer not implemented on this platform!"); return nullptr; } + virtual void + CreateBuffer(ContentType aType, const nsIntRect& aRect, uint32_t aFlags, + gfxASurface** aBlackSurface, gfxASurface** aWhiteSurface, + RefPtr* aBlackDT, RefPtr* aWhiteDT) = 0; virtual bool SupportsAzureContent() const { return false; } diff --git a/gfx/layers/client/ContentClient.cpp b/gfx/layers/client/ContentClient.cpp index 1e8d85343e2..605ef8fe37c 100644 --- a/gfx/layers/client/ContentClient.cpp +++ b/gfx/layers/client/ContentClient.cpp @@ -77,13 +77,26 @@ ContentClientBasic::ContentClientBasic(CompositableForwarder* aForwarder, : ContentClient(aForwarder), ThebesLayerBuffer(ContainsVisibleBounds), mManager(aManager) {} -already_AddRefed +void ContentClientBasic::CreateBuffer(ContentType aType, const nsIntRect& aRect, uint32_t aFlags, - gfxASurface**) + gfxASurface** aBlackSurface, + gfxASurface** aWhiteSurface, + RefPtr* aBlackDT, + RefPtr* aWhiteDT) { MOZ_ASSERT(!(aFlags & BUFFER_COMPONENT_ALPHA)); + if (gfxPlatform::GetPlatform()->SupportsAzureContent()) { + gfxASurface::gfxImageFormat format = + gfxPlatform::GetPlatform()->OptimalFormatForContent(aType); + + *aBlackDT = gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget( + IntSize(aRect.width, aRect.height), + ImageFormatToSurfaceFormat(format)); + return; + } + nsRefPtr referenceSurface = GetBuffer(); if (!referenceSurface) { gfxContext* defaultTarget = mManager->GetDefaultTarget(); @@ -96,23 +109,9 @@ ContentClientBasic::CreateBuffer(ContentType aType, } } } - return referenceSurface->CreateSimilarSurface( + nsRefPtr ret = referenceSurface->CreateSimilarSurface( aType, gfxIntSize(aRect.width, aRect.height)); -} - -TemporaryRef -ContentClientBasic::CreateDTBuffer(ContentType aType, - const nsIntRect& aRect, - uint32_t aFlags, - RefPtr* aWhiteDT) -{ - MOZ_ASSERT(!(aFlags & BUFFER_COMPONENT_ALPHA)); - gfxASurface::gfxImageFormat format = - gfxPlatform::GetPlatform()->OptimalFormatForContent(aType); - - return gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget( - IntSize(aRect.width, aRect.height), - ImageFormatToSurfaceFormat(format)); + *aBlackSurface = ret.forget().get(); } void @@ -225,46 +224,37 @@ ContentClientBasic::SupportsAzureContent() const bool ContentClientRemoteBuffer::SupportsAzureContent() const { - if (!mDeprecatedTextureClient) { - // Hopefully we don't call this method before we have a texture client. But if - // we do, then we have no idea if we can support Azure for whatever surface the - // texture client might come up with. - return false; - } + MOZ_ASSERT(mDeprecatedTextureClient); return gfxPlatform::GetPlatform()->SupportsAzureContentForType( mDeprecatedTextureClient->BackendType()); } -TemporaryRef -ContentClientRemoteBuffer::CreateDTBuffer(ContentType aType, - const nsIntRect& aRect, - uint32_t aFlags, - RefPtr* aWhiteDT) -{ - BuildDeprecatedTextureClients(aType, aRect, aFlags); - - RefPtr ret = mDeprecatedTextureClient->LockDrawTarget(); - if (aFlags & BUFFER_COMPONENT_ALPHA) { - *aWhiteDT = mDeprecatedTextureClientOnWhite->LockDrawTarget(); - } - return ret.forget(); -} - -already_AddRefed +void ContentClientRemoteBuffer::CreateBuffer(ContentType aType, const nsIntRect& aRect, uint32_t aFlags, - gfxASurface** aWhiteSurface) + gfxASurface** aBlackSurface, + gfxASurface** aWhiteSurface, + RefPtr* aBlackDT, + RefPtr* aWhiteDT) { BuildDeprecatedTextureClients(aType, aRect, aFlags); - nsRefPtr ret = mDeprecatedTextureClient->LockSurface(); - if (aFlags & BUFFER_COMPONENT_ALPHA) { - nsRefPtr retWhite = mDeprecatedTextureClientOnWhite->LockSurface(); - *aWhiteSurface = retWhite.forget().get(); + if (gfxPlatform::GetPlatform()->SupportsAzureContentForType( + mDeprecatedTextureClient->BackendType())) { + *aBlackDT = mDeprecatedTextureClient->LockDrawTarget(); + if (aFlags & BUFFER_COMPONENT_ALPHA) { + *aWhiteDT = mDeprecatedTextureClientOnWhite->LockDrawTarget(); + } + } else { + nsRefPtr ret = mDeprecatedTextureClient->LockSurface(); + *aBlackSurface = ret.forget().get(); + if (aFlags & BUFFER_COMPONENT_ALPHA) { + nsRefPtr retWhite = mDeprecatedTextureClientOnWhite->LockSurface(); + *aWhiteSurface = retWhite.forget().get(); + } } - return ret.forget(); } nsIntRegion diff --git a/gfx/layers/client/ContentClient.h b/gfx/layers/client/ContentClient.h index fd73a872f45..e6116e31340 100644 --- a/gfx/layers/client/ContentClient.h +++ b/gfx/layers/client/ContentClient.h @@ -152,14 +152,9 @@ public: ThebesLayerBuffer::DrawTo(aLayer, aTarget, aOpacity, aMask, aMaskTransform); } - virtual already_AddRefed CreateBuffer(ContentType aType, - const nsIntRect& aRect, - uint32_t aFlags, - gfxASurface**) MOZ_OVERRIDE; - virtual TemporaryRef CreateDTBuffer(ContentType aType, - const nsIntRect& aRect, - uint32_t aFlags, - RefPtr* aWhiteDT); + virtual void CreateBuffer(ContentType aType, const nsIntRect& aRect, uint32_t aFlags, + gfxASurface** aBlackSurface, gfxASurface** aWhiteSurface, + RefPtr* aBlackDT, RefPtr* aWhiteDT) MOZ_OVERRIDE; virtual bool SupportsAzureContent() const; virtual TextureInfo GetTextureInfo() const MOZ_OVERRIDE @@ -238,14 +233,9 @@ public: return ThebesLayerBuffer::BufferRotation(); } - virtual already_AddRefed CreateBuffer(ContentType aType, - const nsIntRect& aRect, - uint32_t aFlags, - gfxASurface** aWhiteSurface) MOZ_OVERRIDE; - virtual TemporaryRef CreateDTBuffer(ContentType aType, - const nsIntRect& aRect, - uint32_t aFlags, - RefPtr* aWhiteDT) MOZ_OVERRIDE; + virtual void CreateBuffer(ContentType aType, const nsIntRect& aRect, uint32_t aFlags, + gfxASurface** aBlackSurface, gfxASurface** aWhiteSurface, + RefPtr* aBlackDT, RefPtr* aWhiteDT) MOZ_OVERRIDE; virtual bool SupportsAzureContent() const MOZ_OVERRIDE; diff --git a/gfx/layers/opengl/ThebesLayerOGL.cpp b/gfx/layers/opengl/ThebesLayerOGL.cpp index 2c7c4c91283..7f0f198879c 100644 --- a/gfx/layers/opengl/ThebesLayerOGL.cpp +++ b/gfx/layers/opengl/ThebesLayerOGL.cpp @@ -355,13 +355,16 @@ public: } // ThebesLayerBuffer interface - virtual already_AddRefed - CreateBuffer(ContentType aType, const nsIntRect& aRect, uint32_t aFlags, gfxASurface**) + void + CreateBuffer(ContentType aType, const nsIntRect& aRect, uint32_t aFlags, + gfxASurface** aBlackSurface, gfxASurface** aWhiteSurface, + RefPtr* aBlackDT, RefPtr* aWhiteDT) MOZ_OVERRIDE { NS_ASSERTION(gfxASurface::CONTENT_ALPHA != aType,"ThebesBuffer has color"); mTexImage = CreateClampOrRepeatTextureImage(gl(), aRect.Size(), aType, aFlags); - return mTexImage ? mTexImage->GetBackingSurface() : nullptr; + nsRefPtr ret = mTexImage ? mTexImage->GetBackingSurface() : nullptr; + *aBlackSurface = ret.forget().get(); } virtual nsIntPoint GetOriginOffset() {