зеркало из https://github.com/mozilla/gecko-dev.git
Bug 893302 - Implement CanvasClient2D on top of NewTextures. r=nical
This commit is contained in:
Родитель
9738905b69
Коммит
75e8427d57
|
@ -30,7 +30,50 @@ CanvasClient::CreateCanvasClient(CanvasClientType aType,
|
||||||
aForwarder->GetCompositorBackendType() == LAYERS_OPENGL) {
|
aForwarder->GetCompositorBackendType() == LAYERS_OPENGL) {
|
||||||
return new DeprecatedCanvasClientSurfaceStream(aForwarder, aFlags);
|
return new DeprecatedCanvasClientSurfaceStream(aForwarder, aFlags);
|
||||||
}
|
}
|
||||||
return new DeprecatedCanvasClient2D(aForwarder, aFlags);
|
if (gfxPlatform::GetPlatform()->UseDeprecatedTextures()) {
|
||||||
|
return new DeprecatedCanvasClient2D(aForwarder, aFlags);
|
||||||
|
}
|
||||||
|
return new CanvasClient2D(aForwarder, aFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CanvasClient2D::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer)
|
||||||
|
{
|
||||||
|
if (mBuffer &&
|
||||||
|
(mBuffer->IsImmutable() || mBuffer->GetSize() != aSize)) {
|
||||||
|
RemoveTextureClient(mBuffer);
|
||||||
|
mBuffer = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mBuffer) {
|
||||||
|
bool isOpaque = (aLayer->GetContentFlags() & Layer::CONTENT_OPAQUE);
|
||||||
|
gfxASurface::gfxContentType contentType = isOpaque
|
||||||
|
? gfxASurface::CONTENT_COLOR
|
||||||
|
: gfxASurface::CONTENT_COLOR_ALPHA;
|
||||||
|
gfxASurface::gfxImageFormat format
|
||||||
|
= gfxPlatform::GetPlatform()->OptimalFormatForContent(contentType);
|
||||||
|
mBuffer = CreateBufferTextureClient(gfx::ImageFormatToSurfaceFormat(format));
|
||||||
|
MOZ_ASSERT(mBuffer->AsTextureClientSurface());
|
||||||
|
mBuffer->AsTextureClientSurface()->AllocateForSurface(aSize);
|
||||||
|
|
||||||
|
AddTextureClient(mBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mBuffer->Lock(OPEN_READ_WRITE)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsRefPtr<gfxASurface> surface = mBuffer->AsTextureClientSurface()->GetAsSurface();
|
||||||
|
if (surface) {
|
||||||
|
aLayer->UpdateSurface(surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
mBuffer->Unlock();
|
||||||
|
|
||||||
|
if (surface) {
|
||||||
|
GetForwarder()->UpdatedTexture(this, mBuffer, nullptr);
|
||||||
|
GetForwarder()->UseTexture(this, mBuffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -51,6 +51,36 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
// Used for 2D canvases and WebGL canvas on non-GL systems where readback is requried.
|
// Used for 2D canvases and WebGL canvas on non-GL systems where readback is requried.
|
||||||
|
class CanvasClient2D : public CanvasClient
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CanvasClient2D(CompositableForwarder* aLayerForwarder,
|
||||||
|
TextureFlags aFlags)
|
||||||
|
: CanvasClient(aLayerForwarder, aFlags)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
TextureInfo GetTextureInfo() const
|
||||||
|
{
|
||||||
|
return TextureInfo(COMPOSITABLE_IMAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) MOZ_OVERRIDE;
|
||||||
|
|
||||||
|
virtual void AddTextureClient(TextureClient* aTexture) MOZ_OVERRIDE
|
||||||
|
{
|
||||||
|
aTexture->AddFlags(mTextureInfo.mTextureFlags);
|
||||||
|
CompositableClient::AddTextureClient(aTexture);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void Detach() MOZ_OVERRIDE
|
||||||
|
{
|
||||||
|
mBuffer = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
RefPtr<TextureClient> mBuffer;
|
||||||
|
};
|
||||||
class DeprecatedCanvasClient2D : public CanvasClient
|
class DeprecatedCanvasClient2D : public CanvasClient
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -87,6 +87,7 @@ protected:
|
||||||
RefPtr<CanvasClient> mCanvasClient;
|
RefPtr<CanvasClient> mCanvasClient;
|
||||||
|
|
||||||
friend class DeprecatedCanvasClient2D;
|
friend class DeprecatedCanvasClient2D;
|
||||||
|
friend class CanvasClient2D;
|
||||||
friend class DeprecatedCanvasClientSurfaceStream;
|
friend class DeprecatedCanvasClientSurfaceStream;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,6 +175,19 @@ BufferTextureClient::UpdateSurface(gfxASurface* aSurface)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
already_AddRefed<gfxASurface>
|
||||||
|
BufferTextureClient::GetAsSurface()
|
||||||
|
{
|
||||||
|
ImageDataSerializer serializer(GetBuffer());
|
||||||
|
if (!serializer.IsValid()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
RefPtr<gfxImageSurface> surf = serializer.GetAsThebesSurface();
|
||||||
|
nsRefPtr<gfxASurface> result = surf.get();
|
||||||
|
return result.forget();
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BufferTextureClient::AllocateForSurface(gfx::IntSize aSize)
|
BufferTextureClient::AllocateForSurface(gfx::IntSize aSize)
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,6 +44,7 @@ class TextureClientSurface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual bool UpdateSurface(gfxASurface* aSurface) = 0;
|
virtual bool UpdateSurface(gfxASurface* aSurface) = 0;
|
||||||
|
virtual already_AddRefed<gfxASurface> GetAsSurface() = 0;
|
||||||
virtual bool AllocateForSurface(gfx::IntSize aSize) = 0;
|
virtual bool AllocateForSurface(gfx::IntSize aSize) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -203,6 +204,8 @@ public:
|
||||||
|
|
||||||
virtual bool UpdateSurface(gfxASurface* aSurface) MOZ_OVERRIDE;
|
virtual bool UpdateSurface(gfxASurface* aSurface) MOZ_OVERRIDE;
|
||||||
|
|
||||||
|
virtual already_AddRefed<gfxASurface> GetAsSurface() MOZ_OVERRIDE;
|
||||||
|
|
||||||
virtual bool AllocateForSurface(gfx::IntSize aSize) MOZ_OVERRIDE;
|
virtual bool AllocateForSurface(gfx::IntSize aSize) MOZ_OVERRIDE;
|
||||||
|
|
||||||
// TextureClientYCbCr
|
// TextureClientYCbCr
|
||||||
|
|
Загрузка…
Ссылка в новой задаче