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/. */
|
|
|
|
|
2014-07-12 02:10:49 +04:00
|
|
|
#include "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
|
2014-10-08 08:01:51 +04:00
|
|
|
#include "ScopedGLHelpers.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "gfx2DGlue.h" // for ImageFormatToSurfaceFormat
|
|
|
|
#include "gfxPlatform.h" // for gfxPlatform
|
2014-10-08 08:01:51 +04:00
|
|
|
#include "GLReadTexImageHelper.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "mozilla/gfx/BaseSize.h" // for BaseSize
|
2015-10-12 06:21:02 +03:00
|
|
|
#include "mozilla/layers/AsyncCanvasRenderer.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "mozilla/layers/CompositableForwarder.h"
|
2014-10-27 15:57:36 +03:00
|
|
|
#include "mozilla/layers/CompositorChild.h" // for CompositorChild
|
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
|
2015-06-05 03:15:38 +03:00
|
|
|
#include "TextureClientSharedSurface.h"
|
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 {
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
/* static */ already_AddRefed<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-10-08 08:01:51 +04:00
|
|
|
switch (aType) {
|
|
|
|
case CanvasClientTypeShSurf:
|
2015-04-30 22:20:30 +03:00
|
|
|
return MakeAndAddRef<CanvasClientSharedSurface>(aForwarder, aFlags);
|
2015-10-12 06:21:02 +03:00
|
|
|
case CanvasClientAsync:
|
|
|
|
return MakeAndAddRef<CanvasClientBridge>(aForwarder, aFlags);
|
2014-10-08 08:01:51 +04:00
|
|
|
default:
|
2015-04-30 22:20:30 +03:00
|
|
|
return MakeAndAddRef<CanvasClient2D>(aForwarder, aFlags);
|
|
|
|
break;
|
2013-08-03 06:59:49 +04:00
|
|
|
}
|
2013-08-03 21:29:37 +04:00
|
|
|
}
|
|
|
|
|
2015-10-12 06:21:02 +03:00
|
|
|
void
|
|
|
|
CanvasClientBridge::UpdateAsync(AsyncCanvasRenderer* aRenderer)
|
|
|
|
{
|
|
|
|
if (!GetForwarder() || !mLayer || !aRenderer ||
|
|
|
|
!aRenderer->GetCanvasClient()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t asyncID = aRenderer->GetCanvasClientAsyncID();
|
|
|
|
if (asyncID == 0 || mAsyncID == asyncID) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static_cast<ShadowLayerForwarder*>(GetForwarder())
|
|
|
|
->AttachAsyncCompositable(asyncID, mLayer);
|
|
|
|
mAsyncID = asyncID;
|
|
|
|
}
|
|
|
|
|
2013-08-03 21:29:37 +04:00
|
|
|
void
|
|
|
|
CanvasClient2D::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer)
|
|
|
|
{
|
2014-05-16 19:25:23 +04:00
|
|
|
AutoRemoveTexture autoRemove(this);
|
2013-08-03 21:29:37 +04:00
|
|
|
if (mBuffer &&
|
|
|
|
(mBuffer->IsImmutable() || mBuffer->GetSize() != aSize)) {
|
2014-05-16 19:25:23 +04:00
|
|
|
autoRemove.mTexture = 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;
|
2015-07-07 05:27:19 +03:00
|
|
|
gfx::SurfaceFormat surfaceFormat
|
|
|
|
= gfxPlatform::GetPlatform()->Optimal2DFormatForContent(contentType);
|
2014-04-26 06:34:05 +04:00
|
|
|
TextureFlags flags = TextureFlags::DEFAULT;
|
2014-11-18 04:02:19 +03:00
|
|
|
if (mTextureFlags & TextureFlags::ORIGIN_BOTTOM_LEFT) {
|
|
|
|
flags |= TextureFlags::ORIGIN_BOTTOM_LEFT;
|
2014-04-01 11:52:47 +04:00
|
|
|
}
|
2014-05-15 02:31:23 +04:00
|
|
|
|
2014-06-10 22:02:16 +04:00
|
|
|
mBuffer = CreateTextureClientForCanvas(surfaceFormat, aSize, flags, aLayer);
|
2014-07-10 15:45:40 +04:00
|
|
|
if (!mBuffer) {
|
|
|
|
NS_WARNING("Failed to allocate the TextureClient");
|
|
|
|
return;
|
|
|
|
}
|
2014-04-14 23:29:42 +04:00
|
|
|
MOZ_ASSERT(mBuffer->CanExposeDrawTarget());
|
2014-03-31 22:31:52 +04:00
|
|
|
|
2013-08-20 03:39:55 +04:00
|
|
|
bufferCreated = true;
|
2013-08-03 21:29:37 +04:00
|
|
|
}
|
|
|
|
|
2014-02-19 19:53:26 +04:00
|
|
|
bool updated = false;
|
|
|
|
{
|
2015-11-11 10:58:29 +03:00
|
|
|
TextureClientAutoLock autoLock(mBuffer, OpenMode::OPEN_WRITE_ONLY);
|
|
|
|
if (!autoLock.Succeeded()) {
|
|
|
|
mBuffer = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<DrawTarget> target = mBuffer->BorrowDrawTarget();
|
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
|
|
|
}
|
|
|
|
|
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) {
|
2015-07-03 13:37:03 +03:00
|
|
|
nsAutoTArray<CompositableForwarder::TimedTextureClient,1> textures;
|
|
|
|
CompositableForwarder::TimedTextureClient* t = textures.AppendElement();
|
|
|
|
t->mTextureClient = mBuffer;
|
|
|
|
t->mPictureRect = nsIntRect(nsIntPoint(0, 0), mBuffer->GetSize());
|
2015-10-12 06:21:03 +03:00
|
|
|
t->mFrameID = mFrameID;
|
2015-07-03 13:37:03 +03:00
|
|
|
GetForwarder()->UseTextures(this, textures);
|
2014-12-13 04:50:47 +03:00
|
|
|
mBuffer->SyncWithObject(GetForwarder()->GetSyncObject());
|
2013-08-03 21:29:37 +04:00
|
|
|
}
|
2013-08-03 06:59:49 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<TextureClient>
|
2014-06-10 22:02:16 +04:00
|
|
|
CanvasClient2D::CreateTextureClientForCanvas(gfx::SurfaceFormat aFormat,
|
|
|
|
gfx::IntSize aSize,
|
|
|
|
TextureFlags aFlags,
|
|
|
|
ClientCanvasLayer* aLayer)
|
|
|
|
{
|
|
|
|
if (aLayer->IsGLLayer()) {
|
|
|
|
// We want a cairo backend here as we don't want to be copying into
|
|
|
|
// an accelerated backend and we like LockBits to work. This is currently
|
|
|
|
// the most effective way to make this work.
|
2014-07-10 15:45:40 +04:00
|
|
|
return TextureClient::CreateForRawBufferAccess(GetForwarder(),
|
|
|
|
aFormat, aSize, BackendType::CAIRO,
|
2014-11-25 22:19:13 +03:00
|
|
|
mTextureFlags | aFlags);
|
2014-06-10 22:02:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
2015-08-07 03:27:36 +03:00
|
|
|
return CreateTextureClientForDrawing(aFormat, aSize, BackendSelector::Canvas, aFlags);
|
2014-06-10 22:02:16 +04:00
|
|
|
#else
|
|
|
|
// XXX - We should use CreateTextureClientForDrawing, but we first need
|
|
|
|
// to use double buffering.
|
2015-10-08 02:34:41 +03:00
|
|
|
gfx::BackendType backend = gfxPlatform::GetPlatform()->GetPreferredCanvasBackend();
|
2014-07-10 15:45:40 +04:00
|
|
|
return TextureClient::CreateForRawBufferAccess(GetForwarder(),
|
2015-10-08 02:34:41 +03:00
|
|
|
aFormat, aSize, backend,
|
2014-11-25 22:19:13 +03:00
|
|
|
mTextureFlags | aFlags);
|
2014-06-10 22:02:16 +04:00
|
|
|
#endif
|
|
|
|
}
|
2014-01-10 17:06:06 +04:00
|
|
|
|
2014-10-08 08:01:51 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-10-08 08:11:54 +04:00
|
|
|
CanvasClientSharedSurface::CanvasClientSharedSurface(CompositableForwarder* aLayerForwarder,
|
|
|
|
TextureFlags aFlags)
|
2014-10-08 08:01:51 +04:00
|
|
|
: CanvasClient(aLayerForwarder, aFlags)
|
2015-06-05 03:15:38 +03:00
|
|
|
{ }
|
2014-10-08 08:01:51 +04:00
|
|
|
|
2015-06-05 03:15:38 +03:00
|
|
|
CanvasClientSharedSurface::~CanvasClientSharedSurface()
|
2014-10-08 08:01:51 +04:00
|
|
|
{
|
2015-06-05 03:15:38 +03:00
|
|
|
ClearSurfaces();
|
2014-10-08 08:01:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////
|
|
|
|
// Readback
|
|
|
|
|
|
|
|
// For formats compatible with R8G8B8A8.
|
|
|
|
static inline void SwapRB_R8G8B8A8(uint8_t* pixel) {
|
|
|
|
// [RR, GG, BB, AA]
|
|
|
|
Swap(pixel[0], pixel[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
class TexClientFactory
|
|
|
|
{
|
|
|
|
ISurfaceAllocator* const mAllocator;
|
|
|
|
const bool mHasAlpha;
|
|
|
|
const gfx::IntSize mSize;
|
|
|
|
const gfx::BackendType mBackendType;
|
|
|
|
const TextureFlags mBaseTexFlags;
|
2014-10-08 08:11:54 +04:00
|
|
|
const LayersBackend mLayersBackend;
|
2014-10-08 08:01:51 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
TexClientFactory(ISurfaceAllocator* allocator, bool hasAlpha,
|
|
|
|
const gfx::IntSize& size, gfx::BackendType backendType,
|
2014-10-08 08:11:54 +04:00
|
|
|
TextureFlags baseTexFlags, LayersBackend layersBackend)
|
2014-10-08 08:01:51 +04:00
|
|
|
: mAllocator(allocator)
|
|
|
|
, mHasAlpha(hasAlpha)
|
|
|
|
, mSize(size)
|
|
|
|
, mBackendType(backendType)
|
|
|
|
, mBaseTexFlags(baseTexFlags)
|
2014-10-08 08:11:54 +04:00
|
|
|
, mLayersBackend(layersBackend)
|
2014-10-08 08:01:51 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<BufferTextureClient> Create(gfx::SurfaceFormat format) {
|
2014-10-08 08:01:51 +04:00
|
|
|
return TextureClient::CreateForRawBufferAccess(mAllocator, format,
|
|
|
|
mSize, mBackendType,
|
|
|
|
mBaseTexFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<BufferTextureClient> CreateB8G8R8AX8() {
|
2014-10-08 08:01:51 +04:00
|
|
|
gfx::SurfaceFormat format = mHasAlpha ? gfx::SurfaceFormat::B8G8R8A8
|
|
|
|
: gfx::SurfaceFormat::B8G8R8X8;
|
|
|
|
return Create(format);
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<BufferTextureClient> CreateR8G8B8AX8() {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<BufferTextureClient> ret;
|
2014-10-08 08:11:54 +04:00
|
|
|
|
|
|
|
bool areRGBAFormatsBroken = mLayersBackend == LayersBackend::LAYERS_BASIC;
|
|
|
|
if (!areRGBAFormatsBroken) {
|
|
|
|
gfx::SurfaceFormat format = mHasAlpha ? gfx::SurfaceFormat::R8G8B8A8
|
|
|
|
: gfx::SurfaceFormat::R8G8B8X8;
|
|
|
|
ret = Create(format);
|
|
|
|
}
|
2014-10-08 08:01:51 +04:00
|
|
|
|
2014-10-08 08:11:54 +04:00
|
|
|
if (!ret) {
|
|
|
|
ret = CreateB8G8R8AX8();
|
|
|
|
if (ret) {
|
|
|
|
ret->AddFlags(TextureFlags::RB_SWAPPED);
|
|
|
|
}
|
2014-10-08 08:01:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret.forget();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
static already_AddRefed<TextureClient>
|
2014-10-08 08:01:51 +04:00
|
|
|
TexClientFromReadback(SharedSurface* src, ISurfaceAllocator* allocator,
|
|
|
|
TextureFlags baseFlags, LayersBackend layersBackend)
|
|
|
|
{
|
|
|
|
auto backendType = gfx::BackendType::CAIRO;
|
|
|
|
TexClientFactory factory(allocator, src->mHasAlpha, src->mSize, backendType,
|
2014-10-08 08:11:54 +04:00
|
|
|
baseFlags, layersBackend);
|
2014-10-08 08:01:51 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<BufferTextureClient> texClient;
|
2014-10-08 08:01:51 +04:00
|
|
|
|
|
|
|
{
|
|
|
|
gl::ScopedReadbackFB autoReadback(src);
|
|
|
|
|
|
|
|
// We have a source FB, now we need a format.
|
|
|
|
GLenum destFormat = LOCAL_GL_BGRA;
|
|
|
|
GLenum destType = LOCAL_GL_UNSIGNED_BYTE;
|
|
|
|
GLenum readFormat;
|
|
|
|
GLenum readType;
|
|
|
|
|
|
|
|
// We actually don't care if they match, since we can handle
|
|
|
|
// any read{Format,Type} we get.
|
|
|
|
auto gl = src->mGL;
|
|
|
|
GetActualReadFormats(gl, destFormat, destType, &readFormat, &readType);
|
|
|
|
|
|
|
|
MOZ_ASSERT(readFormat == LOCAL_GL_RGBA ||
|
|
|
|
readFormat == LOCAL_GL_BGRA);
|
|
|
|
MOZ_ASSERT(readType == LOCAL_GL_UNSIGNED_BYTE);
|
|
|
|
|
|
|
|
// With a format and type, we can create texClient.
|
|
|
|
if (readFormat == LOCAL_GL_BGRA &&
|
|
|
|
readType == LOCAL_GL_UNSIGNED_BYTE)
|
|
|
|
{
|
|
|
|
// 0xAARRGGBB
|
|
|
|
// In Lendian: [BB, GG, RR, AA]
|
|
|
|
texClient = factory.CreateB8G8R8AX8();
|
|
|
|
|
|
|
|
} else if (readFormat == LOCAL_GL_RGBA &&
|
|
|
|
readType == LOCAL_GL_UNSIGNED_BYTE)
|
|
|
|
{
|
|
|
|
// [RR, GG, BB, AA]
|
|
|
|
texClient = factory.CreateR8G8B8AX8();
|
|
|
|
} else {
|
|
|
|
MOZ_CRASH("Bad `read{Format,Type}`.");
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(texClient);
|
|
|
|
if (!texClient)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
// With a texClient, we can lock for writing.
|
2015-11-11 10:58:29 +03:00
|
|
|
TextureClientAutoLock autoLock(texClient, OpenMode::OPEN_WRITE);
|
|
|
|
DebugOnly<bool> succeeded = autoLock.Succeeded();
|
|
|
|
MOZ_ASSERT(succeeded, "texture should have locked");
|
2014-10-08 08:01:51 +04:00
|
|
|
|
|
|
|
uint8_t* lockedBytes = texClient->GetLockedData();
|
|
|
|
|
|
|
|
// ReadPixels from the current FB into lockedBits.
|
|
|
|
auto width = src->mSize.width;
|
|
|
|
auto height = src->mSize.height;
|
|
|
|
|
|
|
|
{
|
|
|
|
ScopedPackAlignment autoAlign(gl, 4);
|
|
|
|
|
|
|
|
gl->raw_fReadPixels(0, 0, width, height, readFormat, readType, lockedBytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
// RB_SWAPPED doesn't work with D3D11. (bug 1051010)
|
|
|
|
// RB_SWAPPED doesn't work with Basic. (bug ???????)
|
2014-10-08 08:11:54 +04:00
|
|
|
// RB_SWAPPED doesn't work with D3D9. (bug ???????)
|
|
|
|
bool layersNeedsManualSwap = layersBackend == LayersBackend::LAYERS_BASIC ||
|
|
|
|
layersBackend == LayersBackend::LAYERS_D3D9 ||
|
|
|
|
layersBackend == LayersBackend::LAYERS_D3D11;
|
2014-10-08 08:01:51 +04:00
|
|
|
if (texClient->HasFlags(TextureFlags::RB_SWAPPED) &&
|
|
|
|
layersNeedsManualSwap)
|
|
|
|
{
|
|
|
|
size_t pixels = width * height;
|
|
|
|
uint8_t* itr = lockedBytes;
|
|
|
|
for (size_t i = 0; i < pixels; i++) {
|
|
|
|
SwapRB_R8G8B8A8(itr);
|
|
|
|
itr += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
texClient->RemoveFlags(TextureFlags::RB_SWAPPED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return texClient.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
static already_AddRefed<SharedSurfaceTextureClient>
|
2014-10-08 08:15:39 +04:00
|
|
|
CloneSurface(gl::SharedSurface* src, gl::SurfaceFactory* factory)
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SharedSurfaceTextureClient> dest = factory->NewTexClient(src->mSize);
|
2015-02-03 01:18:29 +03:00
|
|
|
if (!dest) {
|
2015-06-05 03:15:38 +03:00
|
|
|
return nullptr;
|
2015-02-03 01:18:29 +03:00
|
|
|
}
|
2014-10-08 08:15:39 +04:00
|
|
|
SharedSurface::ProdCopy(src, dest->Surf(), factory);
|
2015-06-05 03:15:38 +03:00
|
|
|
dest->Surf()->Fence();
|
2014-10-08 08:15:39 +04:00
|
|
|
return dest.forget();
|
|
|
|
}
|
|
|
|
|
2014-10-08 08:01:51 +04:00
|
|
|
void
|
2014-10-08 08:11:54 +04:00
|
|
|
CanvasClientSharedSurface::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer)
|
2014-10-08 08:01:51 +04:00
|
|
|
{
|
2015-10-12 06:21:02 +03:00
|
|
|
Renderer renderer;
|
|
|
|
renderer.construct<ClientCanvasLayer*>(aLayer);
|
|
|
|
UpdateRenderer(aSize, renderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CanvasClientSharedSurface::UpdateAsync(AsyncCanvasRenderer* aRenderer)
|
|
|
|
{
|
|
|
|
Renderer renderer;
|
|
|
|
renderer.construct<AsyncCanvasRenderer*>(aRenderer);
|
|
|
|
UpdateRenderer(aRenderer->GetSize(), renderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CanvasClientSharedSurface::UpdateRenderer(gfx::IntSize aSize, Renderer& aRenderer)
|
|
|
|
{
|
|
|
|
GLContext* gl = nullptr;
|
|
|
|
ClientCanvasLayer* layer = nullptr;
|
|
|
|
AsyncCanvasRenderer* asyncRenderer = nullptr;
|
|
|
|
if (aRenderer.constructed<ClientCanvasLayer*>()) {
|
|
|
|
layer = aRenderer.ref<ClientCanvasLayer*>();
|
|
|
|
gl = layer->mGLContext;
|
|
|
|
} else {
|
|
|
|
asyncRenderer = aRenderer.ref<AsyncCanvasRenderer*>();
|
|
|
|
gl = asyncRenderer->mGLContext;
|
|
|
|
}
|
2014-10-08 08:15:39 +04:00
|
|
|
gl->MakeCurrent();
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TextureClient> newFront;
|
2015-06-05 03:15:38 +03:00
|
|
|
|
2015-10-12 06:21:02 +03:00
|
|
|
if (layer && layer->mGLFrontbuffer) {
|
|
|
|
mShSurfClient = CloneSurface(layer->mGLFrontbuffer.get(), layer->mFactory.get());
|
2015-06-05 03:15:38 +03:00
|
|
|
if (!mShSurfClient) {
|
|
|
|
gfxCriticalError() << "Invalid canvas front buffer";
|
|
|
|
return;
|
|
|
|
}
|
2014-10-08 08:15:39 +04:00
|
|
|
} else {
|
2015-06-05 03:15:38 +03:00
|
|
|
mShSurfClient = gl->Screen()->Front();
|
|
|
|
if (!mShSurfClient) {
|
|
|
|
return;
|
|
|
|
}
|
2015-04-24 21:21:26 +03:00
|
|
|
}
|
2015-06-05 03:15:38 +03:00
|
|
|
MOZ_ASSERT(mShSurfClient);
|
|
|
|
|
|
|
|
newFront = mShSurfClient;
|
|
|
|
|
|
|
|
SharedSurface* surf = mShSurfClient->Surf();
|
|
|
|
|
|
|
|
// Readback if needed.
|
|
|
|
mReadbackClient = nullptr;
|
2014-10-08 08:01:51 +04:00
|
|
|
|
|
|
|
auto forwarder = GetForwarder();
|
|
|
|
|
2015-06-05 03:15:38 +03:00
|
|
|
bool needsReadback = (surf->mType == SharedSurfaceType::Basic);
|
|
|
|
if (needsReadback) {
|
2015-10-12 06:21:02 +03:00
|
|
|
TextureFlags flags = TextureFlags::IMMUTABLE;
|
|
|
|
|
|
|
|
CompositableForwarder* shadowForwarder = nullptr;
|
|
|
|
if (layer) {
|
|
|
|
flags |= layer->Flags();
|
|
|
|
shadowForwarder = layer->ClientManager()->AsShadowForwarder();
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(asyncRenderer);
|
|
|
|
flags |= mTextureFlags;
|
|
|
|
shadowForwarder = GetForwarder();
|
|
|
|
}
|
2015-06-05 03:15:38 +03:00
|
|
|
|
2014-10-08 08:01:51 +04:00
|
|
|
auto layersBackend = shadowForwarder->GetCompositorBackendType();
|
2015-06-05 03:15:38 +03:00
|
|
|
mReadbackClient = TexClientFromReadback(surf, forwarder, flags, layersBackend);
|
2014-10-08 08:01:51 +04:00
|
|
|
|
2015-10-12 06:21:03 +03:00
|
|
|
if (asyncRenderer) {
|
|
|
|
// Above codes will readback the GLContext to mReadbackClient
|
|
|
|
// in order to send frame to compositor. We copy from this
|
|
|
|
// TextureClient directly by calling CopyFromTextureClient().
|
|
|
|
// Therefore, if main-thread want the content of GLContext,
|
|
|
|
// it don't have to readback it again.
|
|
|
|
asyncRenderer->CopyFromTextureClient(mReadbackClient);
|
|
|
|
}
|
|
|
|
|
2015-06-05 03:15:38 +03:00
|
|
|
newFront = mReadbackClient;
|
|
|
|
} else {
|
|
|
|
mReadbackClient = nullptr;
|
2014-10-08 08:01:51 +04:00
|
|
|
}
|
2015-04-24 21:21:26 +03:00
|
|
|
|
2015-06-05 03:15:38 +03:00
|
|
|
MOZ_ASSERT(newFront);
|
|
|
|
if (!newFront) {
|
2014-12-18 21:28:16 +03:00
|
|
|
// May happen in a release build in case of memory pressure.
|
2015-06-05 03:15:38 +03:00
|
|
|
gfxCriticalError() << "Failed to allocate a TextureClient for SharedSurface Canvas. Size: " << aSize;
|
2014-12-18 21:28:16 +03:00
|
|
|
return;
|
|
|
|
}
|
2014-10-08 08:01:51 +04:00
|
|
|
|
2015-10-12 06:21:02 +03:00
|
|
|
mNewFront = newFront;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CanvasClientSharedSurface::Updated()
|
|
|
|
{
|
2015-11-04 00:07:02 +03:00
|
|
|
if (!mNewFront) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-12 06:21:02 +03:00
|
|
|
auto forwarder = GetForwarder();
|
|
|
|
|
2015-09-21 17:21:52 +03:00
|
|
|
#ifndef MOZ_WIDGET_GONK
|
2015-06-05 03:15:38 +03:00
|
|
|
if (mFront) {
|
|
|
|
if (mFront->GetFlags() & TextureFlags::RECYCLE) {
|
|
|
|
mFront->WaitForCompositorRecycle();
|
|
|
|
}
|
2014-10-08 08:01:51 +04:00
|
|
|
}
|
2015-09-21 17:21:52 +03:00
|
|
|
#else
|
|
|
|
// AutoRemoveTexture does the followings.
|
|
|
|
// - Ensure to deliver FenceHandle from TextureHost to TextureClient, before
|
|
|
|
// next TextureClient usage.
|
|
|
|
// - Control TextureClient's recycling timing.
|
|
|
|
// - Call RemoveTexture() after newFront's UseTextures() call.
|
|
|
|
// It could improve performance of Host side's EGL handling on gonk
|
|
|
|
AutoRemoveTexture autoRemove(this);
|
2015-10-12 06:21:02 +03:00
|
|
|
if (mFront && mFront != mNewFront) {
|
2015-09-21 17:21:52 +03:00
|
|
|
autoRemove.mTexture = mFront;
|
|
|
|
}
|
|
|
|
#endif
|
2014-10-08 08:01:51 +04:00
|
|
|
|
2015-10-12 06:21:02 +03:00
|
|
|
mFront = mNewFront;
|
|
|
|
mNewFront = nullptr;
|
2014-10-08 08:01:51 +04:00
|
|
|
|
2015-06-05 03:15:38 +03:00
|
|
|
// Add the new TexClient.
|
|
|
|
MOZ_ALWAYS_TRUE( AddTextureClient(mFront) );
|
|
|
|
|
2015-07-03 13:37:03 +03:00
|
|
|
nsAutoTArray<CompositableForwarder::TimedTextureClient,1> textures;
|
|
|
|
CompositableForwarder::TimedTextureClient* t = textures.AppendElement();
|
|
|
|
t->mTextureClient = mFront;
|
|
|
|
t->mPictureRect = nsIntRect(nsIntPoint(0, 0), mFront->GetSize());
|
2015-10-12 06:21:03 +03:00
|
|
|
t->mFrameID = mFrameID;
|
2015-07-03 13:37:03 +03:00
|
|
|
forwarder->UseTextures(this, textures);
|
2014-10-08 08:01:51 +04:00
|
|
|
}
|
|
|
|
|
2015-01-23 17:35:16 +03:00
|
|
|
void
|
|
|
|
CanvasClientSharedSurface::ClearSurfaces()
|
|
|
|
{
|
|
|
|
mFront = nullptr;
|
2015-10-12 06:21:02 +03:00
|
|
|
mNewFront = nullptr;
|
2015-06-05 03:15:38 +03:00
|
|
|
mShSurfClient = nullptr;
|
|
|
|
mReadbackClient = nullptr;
|
2015-01-23 17:35:16 +03:00
|
|
|
}
|
|
|
|
|
2015-06-05 03:15:38 +03:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|