gecko-dev/gfx/layers/client/ClientCanvasLayer.cpp
Matt Woodrow 99f82e605d 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

105 lines
2.8 KiB
C++

/* -*- Mode: C++; tab-width: 2; 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 "ClientCanvasLayer.h"
#include "gfxPlatform.h"
#include "SurfaceStream.h"
#include "SharedSurfaceGL.h"
#include "SharedSurfaceEGL.h"
using namespace mozilla::gl;
namespace mozilla {
namespace layers {
void
ClientCanvasLayer::Initialize(const Data& aData)
{
CopyableCanvasLayer::Initialize(aData);
mCanvasClient = nullptr;
if (mGLContext) {
GLScreenBuffer* screen = mGLContext->Screen();
SurfaceStreamType streamType =
SurfaceStream::ChooseGLStreamType(SurfaceStream::OffMainThread,
screen->PreserveBuffer());
SurfaceFactory_GL* factory = nullptr;
if (!mForceReadback) {
if (ClientManager()->GetCompositorBackendType() == mozilla::layers::LAYERS_OPENGL) {
if (mGLContext->GetEGLContext()) {
bool isCrossProcess = !(XRE_GetProcessType() == GeckoProcessType_Default);
if (!isCrossProcess) {
// [Basic/OGL Layers, OMTC] WebGL layer init.
factory = SurfaceFactory_EGLImage::Create(mGLContext, screen->Caps());
} else {
// [Basic/OGL Layers, OOPC] WebGL layer init. (Out Of Process Compositing)
// Fall back to readback.
}
} else {
// [Basic Layers, OMTC] WebGL layer init.
// Well, this *should* work...
factory = new SurfaceFactory_GLTexture(mGLContext, mGLContext, screen->Caps());
}
}
}
if (factory) {
screen->Morph(factory, streamType);
}
}
}
void
ClientCanvasLayer::RenderLayer()
{
PROFILER_LABEL("ClientCanvasLayer", "Paint");
if (!IsDirty()) {
return;
}
if (GetMaskLayer()) {
ToClientLayer(GetMaskLayer())->RenderLayer();
}
if (!mCanvasClient) {
TextureFlags flags = 0;
if (mNeedsYFlip) {
flags |= NeedsYFlip;
}
mCanvasClient = CanvasClient::CreateCanvasClient(GetCompositableClientType(),
ClientManager(), flags);
if (!mCanvasClient) {
return;
}
if (HasShadow()) {
mCanvasClient->Connect();
ClientManager()->Attach(mCanvasClient, this);
}
}
FirePreTransactionCallback();
mCanvasClient->Update(gfx::IntSize(mBounds.width, mBounds.height), this);
FireDidTransactionCallback();
ClientManager()->Hold(this);
mCanvasClient->Updated();
}
already_AddRefed<CanvasLayer>
ClientLayerManager::CreateCanvasLayer()
{
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
nsRefPtr<ClientCanvasLayer> layer =
new ClientCanvasLayer(this);
CREATE_SHADOW(Canvas);
return layer.forget();
}
}
}