Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
/* -*- 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"
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "ClientCanvasLayer.h" // for ClientCanvasLayer
|
|
|
|
#include "GLContext.h" // for GLContext
|
|
|
|
#include "GLScreenBuffer.h" // for GLScreenBuffer
|
|
|
|
#include "SurfaceStream.h" // for SurfaceStream
|
|
|
|
#include "SurfaceTypes.h" // for SurfaceStreamHandle
|
|
|
|
#include "gfx2DGlue.h" // for ImageFormatToSurfaceFormat
|
|
|
|
#include "gfxASurface.h" // for gfxASurface, etc
|
|
|
|
#include "gfxPlatform.h" // for gfxPlatform
|
|
|
|
#include "mozilla/gfx/BaseSize.h" // for BaseSize
|
|
|
|
#include "mozilla/layers/CompositableForwarder.h"
|
2014-01-10 17:06:06 +04:00
|
|
|
#include "mozilla/layers/GrallocTextureClient.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "mozilla/layers/LayersTypes.h"
|
|
|
|
#include "mozilla/layers/TextureClient.h" // for TextureClient, etc
|
2014-01-10 17:06:06 +04:00
|
|
|
#include "mozilla/layers/TextureClientOGL.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "nsAutoPtr.h" // for nsRefPtr
|
|
|
|
#include "nsDebug.h" // for printf_stderr, NS_ASSERTION
|
|
|
|
#include "nsXULAppAPI.h" // for XRE_GetProcessType, etc
|
2013-05-27 18:12:13 +04:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
#include "SharedSurfaceGralloc.h"
|
|
|
|
#endif
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
|
2013-12-09 06:53:26 +04:00
|
|
|
using namespace mozilla::gfx;
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
using namespace mozilla::gl;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
/* static */ TemporaryRef<CanvasClient>
|
2013-08-02 05:12:15 +04:00
|
|
|
CanvasClient::CreateCanvasClient(CanvasClientType aType,
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
CompositableForwarder* aForwarder,
|
|
|
|
TextureFlags aFlags)
|
|
|
|
{
|
2014-04-07 13:01:45 +04:00
|
|
|
#ifndef MOZ_WIDGET_GONK
|
|
|
|
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
|
|
|
NS_WARNING("Most platforms still need an optimized way to share GL cross process.");
|
|
|
|
return new CanvasClient2D(aForwarder, aFlags);
|
|
|
|
}
|
|
|
|
#endif
|
2013-08-02 05:12:15 +04:00
|
|
|
if (aType == CanvasClientGLContext &&
|
2014-01-23 22:26:41 +04:00
|
|
|
aForwarder->GetCompositorBackendType() == LayersBackend::LAYERS_OPENGL) {
|
2013-10-03 00:52:04 +04:00
|
|
|
aFlags |= TEXTURE_DEALLOCATE_CLIENT;
|
2014-01-10 17:06:06 +04:00
|
|
|
return new CanvasClientSurfaceStream(aForwarder, aFlags);
|
2013-08-03 06:59:49 +04:00
|
|
|
}
|
2013-08-03 21:29:37 +04:00
|
|
|
return new CanvasClient2D(aForwarder, aFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CanvasClient2D::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer)
|
|
|
|
{
|
|
|
|
if (mBuffer &&
|
|
|
|
(mBuffer->IsImmutable() || mBuffer->GetSize() != aSize)) {
|
2014-02-11 00:52:35 +04:00
|
|
|
GetForwarder()->RemoveTextureFromCompositable(this, mBuffer);
|
2013-08-03 21:29:37 +04:00
|
|
|
mBuffer = nullptr;
|
|
|
|
}
|
|
|
|
|
2013-08-20 03:39:55 +04:00
|
|
|
bool bufferCreated = false;
|
2013-08-03 21:29:37 +04:00
|
|
|
if (!mBuffer) {
|
|
|
|
bool isOpaque = (aLayer->GetContentFlags() & Layer::CONTENT_OPAQUE);
|
2013-09-25 00:45:13 +04:00
|
|
|
gfxContentType contentType = isOpaque
|
2014-01-23 22:26:40 +04:00
|
|
|
? gfxContentType::COLOR
|
|
|
|
: gfxContentType::COLOR_ALPHA;
|
2013-09-25 00:45:13 +04:00
|
|
|
gfxImageFormat format
|
2013-08-03 21:29:37 +04:00
|
|
|
= gfxPlatform::GetPlatform()->OptimalFormatForContent(contentType);
|
2014-04-01 11:52:47 +04:00
|
|
|
uint32_t flags = TEXTURE_FLAGS_DEFAULT;
|
|
|
|
if (mTextureFlags & TEXTURE_NEEDS_Y_FLIP) {
|
|
|
|
flags |= TEXTURE_NEEDS_Y_FLIP;
|
|
|
|
}
|
2014-03-31 22:31:52 +04:00
|
|
|
mBuffer = CreateBufferTextureClient(gfx::ImageFormatToSurfaceFormat(format),
|
2014-04-01 11:52:47 +04:00
|
|
|
flags,
|
2014-03-31 22:31:52 +04:00
|
|
|
gfxPlatform::GetPlatform()->GetPreferredCanvasBackend());
|
|
|
|
MOZ_ASSERT(mBuffer->AsTextureClientSurface());
|
|
|
|
mBuffer->AsTextureClientSurface()->AllocateForSurface(aSize);
|
|
|
|
|
2013-08-20 03:39:55 +04:00
|
|
|
bufferCreated = true;
|
2013-08-03 21:29:37 +04:00
|
|
|
}
|
|
|
|
|
2014-01-07 20:20:11 +04:00
|
|
|
if (!mBuffer->Lock(OPEN_WRITE_ONLY)) {
|
2013-08-03 21:29:37 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-19 19:53:26 +04:00
|
|
|
bool updated = false;
|
|
|
|
{
|
|
|
|
// Restrict drawTarget to a scope so that terminates before Unlock.
|
2014-04-01 11:51:10 +04:00
|
|
|
RefPtr<DrawTarget> target =
|
2014-04-10 15:15:47 +04:00
|
|
|
mBuffer->AsTextureClientDrawTarget()->GetAsDrawTarget();
|
2014-04-01 11:51:10 +04:00
|
|
|
if (target) {
|
|
|
|
aLayer->UpdateTarget(target);
|
2014-02-19 19:53:26 +04:00
|
|
|
updated = true;
|
|
|
|
}
|
2013-08-03 21:29:37 +04:00
|
|
|
}
|
|
|
|
mBuffer->Unlock();
|
|
|
|
|
2013-10-10 03:18:29 +04:00
|
|
|
if (bufferCreated && !AddTextureClient(mBuffer)) {
|
|
|
|
mBuffer = nullptr;
|
|
|
|
return;
|
2013-08-20 03:39:55 +04:00
|
|
|
}
|
|
|
|
|
2014-02-19 19:53:26 +04:00
|
|
|
if (updated) {
|
2013-08-03 21:29:37 +04:00
|
|
|
GetForwarder()->UpdatedTexture(this, mBuffer, nullptr);
|
|
|
|
GetForwarder()->UseTexture(this, mBuffer);
|
|
|
|
}
|
2013-08-03 06:59:49 +04:00
|
|
|
}
|
|
|
|
|
2014-01-10 17:06:06 +04:00
|
|
|
CanvasClientSurfaceStream::CanvasClientSurfaceStream(CompositableForwarder* aLayerForwarder,
|
|
|
|
TextureFlags aFlags)
|
|
|
|
: CanvasClient(aLayerForwarder, aFlags)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CanvasClientSurfaceStream::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer)
|
|
|
|
{
|
2014-03-28 01:59:38 +04:00
|
|
|
aLayer->mGLContext->MakeCurrent();
|
2014-01-10 17:06:06 +04:00
|
|
|
GLScreenBuffer* screen = aLayer->mGLContext->Screen();
|
2014-03-06 01:49:37 +04:00
|
|
|
SurfaceStream* stream = nullptr;
|
|
|
|
|
|
|
|
if (aLayer->mStream) {
|
|
|
|
stream = aLayer->mStream;
|
|
|
|
|
|
|
|
// Copy our current surface to the current producer surface in our stream, then
|
|
|
|
// call SwapProducer to make a new buffer ready.
|
|
|
|
stream->CopySurfaceToProducer(aLayer->mTextureSurface, aLayer->mFactory);
|
|
|
|
stream->SwapProducer(aLayer->mFactory, gfx::IntSize(aSize.width, aSize.height));
|
|
|
|
} else {
|
|
|
|
stream = screen->Stream();
|
|
|
|
}
|
2014-01-10 17:06:06 +04:00
|
|
|
|
|
|
|
bool isCrossProcess = !(XRE_GetProcessType() == GeckoProcessType_Default);
|
|
|
|
bool bufferCreated = false;
|
|
|
|
if (isCrossProcess) {
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
SharedSurface* surf = stream->SwapConsumer();
|
|
|
|
if (!surf) {
|
|
|
|
printf_stderr("surf is null post-SwapConsumer!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (surf->Type() != SharedSurfaceType::Gralloc) {
|
|
|
|
printf_stderr("Unexpected non-Gralloc SharedSurface in IPC path!");
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SharedSurface_Gralloc* grallocSurf = SharedSurface_Gralloc::Cast(surf);
|
|
|
|
|
2014-02-18 18:46:13 +04:00
|
|
|
RefPtr<GrallocTextureClientOGL> grallocTextureClient =
|
2014-01-10 17:06:06 +04:00
|
|
|
static_cast<GrallocTextureClientOGL*>(grallocSurf->GetTextureClient());
|
|
|
|
|
|
|
|
// If IPDLActor is null means this TextureClient didn't AddTextureClient yet
|
|
|
|
if (!grallocTextureClient->GetIPDLActor()) {
|
|
|
|
grallocTextureClient->SetTextureFlags(mTextureInfo.mTextureFlags);
|
|
|
|
AddTextureClient(grallocTextureClient);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (grallocTextureClient->GetIPDLActor()) {
|
|
|
|
GetForwarder()->UseTexture(this, grallocTextureClient);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
printf_stderr("isCrossProcess, but not MOZ_WIDGET_GONK! Someone needs to write some code!");
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
if (!mBuffer) {
|
|
|
|
StreamTextureClientOGL* textureClient =
|
|
|
|
new StreamTextureClientOGL(mTextureInfo.mTextureFlags);
|
|
|
|
textureClient->InitWith(stream);
|
|
|
|
mBuffer = textureClient;
|
|
|
|
bufferCreated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bufferCreated && !AddTextureClient(mBuffer)) {
|
|
|
|
mBuffer = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mBuffer) {
|
|
|
|
GetForwarder()->UseTexture(this, mBuffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aLayer->Painted();
|
|
|
|
}
|
|
|
|
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
}
|
|
|
|
}
|