gecko/gfx/layers/client/CanvasClient.cpp
Matt Woodrow c727739057 Bug 867474 - Split BasicShadowableLayerManager into a separate ClientLayerManager. r=nrc
--HG--
rename : gfx/layers/basic/BasicCanvasLayer.cpp => gfx/layers/CopyableCanvasLayer.cpp
rename : gfx/layers/basic/BasicCanvasLayer.h => gfx/layers/CopyableCanvasLayer.h
rename : gfx/layers/basic/BasicCanvasLayer.cpp => gfx/layers/client/ClientCanvasLayer.cpp
rename : gfx/layers/basic/BasicCanvasLayer.h => gfx/layers/client/ClientCanvasLayer.h
rename : gfx/layers/basic/BasicColorLayer.cpp => gfx/layers/client/ClientColorLayer.cpp
rename : gfx/layers/basic/BasicContainerLayer.cpp => gfx/layers/client/ClientContainerLayer.cpp
rename : gfx/layers/basic/BasicContainerLayer.h => gfx/layers/client/ClientContainerLayer.h
rename : gfx/layers/basic/BasicImageLayer.cpp => gfx/layers/client/ClientImageLayer.cpp
rename : gfx/layers/basic/BasicLayerManager.cpp => gfx/layers/client/ClientLayerManager.cpp
rename : gfx/layers/basic/BasicLayers.h => gfx/layers/client/ClientLayerManager.h
rename : gfx/layers/basic/BasicThebesLayer.cpp => gfx/layers/client/ClientThebesLayer.cpp
rename : gfx/layers/basic/BasicThebesLayer.h => gfx/layers/client/ClientThebesLayer.h
rename : gfx/layers/basic/BasicTiledThebesLayer.cpp => gfx/layers/client/ClientTiledThebesLayer.cpp
rename : gfx/layers/basic/BasicTiledThebesLayer.h => gfx/layers/client/ClientTiledThebesLayer.h
2013-05-01 17:03:25 +12:00

100 lines
3.0 KiB
C++

/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/layers/CanvasClient.h"
#include "mozilla/layers/TextureClient.h"
#include "ClientCanvasLayer.h"
#include "mozilla/layers/ShadowLayers.h"
#include "SharedTextureImage.h"
#include "nsXULAppAPI.h"
#include "GLContext.h"
#include "SurfaceStream.h"
using namespace mozilla::gl;
namespace mozilla {
namespace layers {
/* static */ TemporaryRef<CanvasClient>
CanvasClient::CreateCanvasClient(CompositableType aCompositableHostType,
CompositableForwarder* aForwarder,
TextureFlags aFlags)
{
if (aCompositableHostType == BUFFER_IMAGE_SINGLE) {
return new CanvasClient2D(aForwarder, aFlags);
}
if (aCompositableHostType == BUFFER_IMAGE_BUFFERED) {
if (aForwarder->GetCompositorBackendType() == LAYERS_OPENGL) {
return new CanvasClientWebGL(aForwarder, aFlags);
}
return new CanvasClient2D(aForwarder, aFlags);
}
return nullptr;
}
void
CanvasClient::Updated()
{
mForwarder->UpdateTexture(this, 1, mTextureClient->GetDescriptor());
}
CanvasClient2D::CanvasClient2D(CompositableForwarder* aFwd,
TextureFlags aFlags)
: CanvasClient(aFwd, aFlags)
{
mTextureInfo.mCompositableType = BUFFER_IMAGE_SINGLE;
}
void
CanvasClient2D::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer)
{
if (!mTextureClient) {
mTextureClient = CreateTextureClient(TEXTURE_SHMEM);
MOZ_ASSERT(mTextureClient, "Failed to create texture client");
}
bool isOpaque = (aLayer->GetContentFlags() & Layer::CONTENT_OPAQUE);
gfxASurface::gfxContentType contentType = isOpaque
? gfxASurface::CONTENT_COLOR
: gfxASurface::CONTENT_COLOR_ALPHA;
mTextureClient->EnsureAllocated(aSize, contentType);
gfxASurface* surface = mTextureClient->LockSurface();
aLayer->UpdateSurface(surface);
mTextureClient->Unlock();
}
CanvasClientWebGL::CanvasClientWebGL(CompositableForwarder* aFwd,
TextureFlags aFlags)
: CanvasClient(aFwd, aFlags)
{
mTextureInfo.mCompositableType = BUFFER_IMAGE_BUFFERED;
}
void
CanvasClientWebGL::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer)
{
if (!mTextureClient) {
mTextureClient = CreateTextureClient(TEXTURE_STREAM_GL);
MOZ_ASSERT(mTextureClient, "Failed to create texture client");
}
NS_ASSERTION(aLayer->mGLContext, "CanvasClientWebGL should only be used with GL canvases");
// the content type won't be used
mTextureClient->EnsureAllocated(aSize, gfxASurface::CONTENT_COLOR);
GLScreenBuffer* screen = aLayer->mGLContext->Screen();
SurfaceStreamHandle handle = screen->Stream()->GetShareHandle();
mTextureClient->SetDescriptor(SurfaceStreamDescriptor(handle, false));
aLayer->Painted();
}
}
}