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 02:20:52 -07: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 "ImageHost.h"
|
2013-08-11 16:17:23 -07:00
|
|
|
#include "LayersLogging.h" // for AppendToString
|
|
|
|
#include "composite/CompositableHost.h" // for CompositableHost, etc
|
|
|
|
#include "ipc/IPCMessageUtils.h" // for null_t
|
|
|
|
#include "mozilla/layers/Compositor.h" // for Compositor
|
|
|
|
#include "mozilla/layers/Effects.h" // for TexturedEffect, Effect, etc
|
|
|
|
#include "nsAString.h"
|
|
|
|
#include "nsDebug.h" // for NS_WARNING, NS_ASSERTION
|
|
|
|
#include "nsPrintfCString.h" // for nsPrintfCString
|
|
|
|
#include "nsString.h" // for nsAutoCString
|
|
|
|
|
|
|
|
class nsIntRegion;
|
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 02:20:52 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
2013-08-11 16:17:23 -07:00
|
|
|
namespace gfx {
|
|
|
|
class Matrix4x4;
|
|
|
|
}
|
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 02:20:52 -07:00
|
|
|
|
|
|
|
using namespace gfx;
|
|
|
|
|
|
|
|
namespace layers {
|
|
|
|
|
2013-08-11 16:17:23 -07:00
|
|
|
class ISurfaceAllocator;
|
|
|
|
|
2013-07-30 02:59:51 -07:00
|
|
|
ImageHost::ImageHost(const TextureInfo& aTextureInfo)
|
|
|
|
: CompositableHost(aTextureInfo)
|
|
|
|
, mFrontBuffer(nullptr)
|
|
|
|
, mHasPictureRect(false)
|
|
|
|
{}
|
|
|
|
|
|
|
|
ImageHost::~ImageHost() {}
|
|
|
|
|
|
|
|
void
|
|
|
|
ImageHost::UseTextureHost(TextureHost* aTexture)
|
|
|
|
{
|
2013-12-11 17:44:41 -08:00
|
|
|
CompositableHost::UseTextureHost(aTexture);
|
2013-07-30 02:59:51 -07:00
|
|
|
mFrontBuffer = aTexture;
|
|
|
|
}
|
|
|
|
|
2014-02-10 12:52:35 -08:00
|
|
|
void
|
|
|
|
ImageHost::RemoveTextureHost(TextureHost* aTexture)
|
|
|
|
{
|
|
|
|
CompositableHost::RemoveTextureHost(aTexture);
|
|
|
|
if (aTexture && mFrontBuffer == aTexture) {
|
|
|
|
aTexture->SetCompositableBackendSpecificData(nullptr);
|
|
|
|
mFrontBuffer = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-30 02:59:51 -07:00
|
|
|
TextureHost*
|
2013-12-05 10:39:22 -08:00
|
|
|
ImageHost::GetAsTextureHost()
|
2013-07-30 02:59:51 -07:00
|
|
|
{
|
|
|
|
return mFrontBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ImageHost::Composite(EffectChain& aEffectChain,
|
|
|
|
float aOpacity,
|
|
|
|
const gfx::Matrix4x4& aTransform,
|
|
|
|
const gfx::Filter& aFilter,
|
|
|
|
const gfx::Rect& aClipRect,
|
|
|
|
const nsIntRegion* aVisibleRegion,
|
|
|
|
TiledLayerProperties* aLayerProperties)
|
|
|
|
{
|
|
|
|
if (!GetCompositor()) {
|
|
|
|
// should only happen when a tab is dragged to another window and
|
|
|
|
// async-video is still sending frames but we haven't attached the
|
|
|
|
// set the new compositor yet.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!mFrontBuffer) {
|
|
|
|
return;
|
|
|
|
}
|
2013-12-11 17:44:41 -08:00
|
|
|
|
|
|
|
// Make sure the front buffer has a compositor
|
|
|
|
mFrontBuffer->SetCompositor(GetCompositor());
|
2014-02-15 17:00:16 -08:00
|
|
|
mFrontBuffer->SetCompositableBackendSpecificData(GetCompositableBackendSpecificData());
|
2013-12-11 17:44:41 -08:00
|
|
|
|
2013-12-19 08:20:51 -08:00
|
|
|
AutoLockTextureHost autoLock(mFrontBuffer);
|
|
|
|
if (autoLock.Failed()) {
|
2013-07-30 02:59:51 -07:00
|
|
|
NS_WARNING("failed to lock front buffer");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
RefPtr<NewTextureSource> source = mFrontBuffer->GetTextureSources();
|
|
|
|
if (!source) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
RefPtr<TexturedEffect> effect = CreateTexturedEffect(mFrontBuffer->GetFormat(),
|
|
|
|
source,
|
|
|
|
aFilter);
|
2013-11-21 14:07:56 -08:00
|
|
|
if (!effect) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-30 02:59:51 -07:00
|
|
|
aEffectChain.mPrimaryEffect = effect;
|
2013-08-02 15:50:17 -07:00
|
|
|
IntSize textureSize = source->GetSize();
|
|
|
|
gfx::Rect gfxPictureRect
|
|
|
|
= mHasPictureRect ? gfx::Rect(0, 0, mPictureRect.width, mPictureRect.height)
|
|
|
|
: gfx::Rect(0, 0, textureSize.width, textureSize.height);
|
2013-08-01 18:12:16 -07:00
|
|
|
|
|
|
|
gfx::Rect pictureRect(0, 0,
|
|
|
|
mPictureRect.width,
|
|
|
|
mPictureRect.height);
|
|
|
|
//XXX: We might have multiple texture sources here (e.g. 3 YCbCr textures), and we're
|
|
|
|
// only iterating over the tiles of the first one. Are we assuming that the tiling
|
|
|
|
// will be identical? Can we ensure that somehow?
|
2013-07-30 02:59:51 -07:00
|
|
|
TileIterator* it = source->AsTileIterator();
|
|
|
|
if (it) {
|
|
|
|
it->BeginTileIteration();
|
|
|
|
do {
|
|
|
|
nsIntRect tileRect = it->GetTileRect();
|
|
|
|
gfx::Rect rect(tileRect.x, tileRect.y, tileRect.width, tileRect.height);
|
2013-08-01 18:12:16 -07:00
|
|
|
if (mHasPictureRect) {
|
|
|
|
rect = rect.Intersect(pictureRect);
|
|
|
|
effect->mTextureCoords = Rect(Float(rect.x - tileRect.x)/ tileRect.width,
|
|
|
|
Float(rect.y - tileRect.y) / tileRect.height,
|
|
|
|
Float(rect.width) / tileRect.width,
|
|
|
|
Float(rect.height) / tileRect.height);
|
|
|
|
} else {
|
|
|
|
effect->mTextureCoords = Rect(0, 0, 1, 1);
|
|
|
|
}
|
2013-07-30 02:59:51 -07:00
|
|
|
GetCompositor()->DrawQuad(rect, aClipRect, aEffectChain,
|
2013-11-07 01:53:08 -08:00
|
|
|
aOpacity, aTransform);
|
2014-04-25 19:34:06 -07:00
|
|
|
GetCompositor()->DrawDiagnostics(DiagnosticFlags::IMAGE | DiagnosticFlags::BIGIMAGE,
|
2014-03-25 09:54:39 -07:00
|
|
|
rect, aClipRect, aTransform, mFlashCounter);
|
2013-07-30 02:59:51 -07:00
|
|
|
} while (it->NextTile());
|
|
|
|
it->EndTileIteration();
|
2013-08-02 15:50:17 -07:00
|
|
|
// layer border
|
2014-04-25 19:34:06 -07:00
|
|
|
GetCompositor()->DrawDiagnostics(DiagnosticFlags::IMAGE,
|
2013-08-02 15:50:17 -07:00
|
|
|
gfxPictureRect, aClipRect,
|
2014-03-25 09:54:39 -07:00
|
|
|
aTransform, mFlashCounter);
|
2013-07-30 02:59:51 -07:00
|
|
|
} else {
|
|
|
|
IntSize textureSize = source->GetSize();
|
2013-08-01 18:12:16 -07:00
|
|
|
gfx::Rect rect;
|
2013-07-30 02:59:51 -07:00
|
|
|
if (mHasPictureRect) {
|
|
|
|
effect->mTextureCoords = Rect(Float(mPictureRect.x) / textureSize.width,
|
|
|
|
Float(mPictureRect.y) / textureSize.height,
|
|
|
|
Float(mPictureRect.width) / textureSize.width,
|
|
|
|
Float(mPictureRect.height) / textureSize.height);
|
2013-08-01 18:12:16 -07:00
|
|
|
rect = pictureRect;
|
2013-07-30 02:59:51 -07:00
|
|
|
} else {
|
|
|
|
effect->mTextureCoords = Rect(0, 0, 1, 1);
|
|
|
|
rect = gfx::Rect(0, 0, textureSize.width, textureSize.height);
|
|
|
|
}
|
|
|
|
|
2014-04-25 19:34:05 -07:00
|
|
|
if (mFrontBuffer->GetFlags() & TextureFlags::NEEDS_Y_FLIP) {
|
2013-07-30 02:59:51 -07:00
|
|
|
effect->mTextureCoords.y = effect->mTextureCoords.YMost();
|
|
|
|
effect->mTextureCoords.height = -effect->mTextureCoords.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
GetCompositor()->DrawQuad(rect, aClipRect, aEffectChain,
|
2013-11-07 01:53:08 -08:00
|
|
|
aOpacity, aTransform);
|
2014-04-25 19:34:06 -07:00
|
|
|
GetCompositor()->DrawDiagnostics(DiagnosticFlags::IMAGE,
|
2013-08-02 15:50:17 -07:00
|
|
|
rect, aClipRect,
|
2014-03-25 09:54:39 -07:00
|
|
|
aTransform, mFlashCounter);
|
2013-07-30 02:59:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-11 17:44:49 -08:00
|
|
|
void
|
|
|
|
ImageHost::SetCompositor(Compositor* aCompositor)
|
|
|
|
{
|
|
|
|
if (mFrontBuffer && mCompositor != aCompositor) {
|
|
|
|
mFrontBuffer->SetCompositor(aCompositor);
|
|
|
|
}
|
|
|
|
CompositableHost::SetCompositor(aCompositor);
|
|
|
|
}
|
|
|
|
|
2013-07-30 02:59:51 -07:00
|
|
|
void
|
|
|
|
ImageHost::PrintInfo(nsACString& aTo, const char* aPrefix)
|
|
|
|
{
|
|
|
|
aTo += aPrefix;
|
|
|
|
aTo += nsPrintfCString("ImageHost (0x%p)", this);
|
|
|
|
|
|
|
|
AppendToString(aTo, mPictureRect, " [picture-rect=", "]");
|
|
|
|
|
|
|
|
if (mFrontBuffer) {
|
|
|
|
nsAutoCString pfx(aPrefix);
|
|
|
|
pfx += " ";
|
|
|
|
aTo += "\n";
|
|
|
|
mFrontBuffer->PrintInfo(aTo, pfx.get());
|
|
|
|
}
|
|
|
|
}
|
2013-08-08 05:53:12 -07:00
|
|
|
|
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
2013-07-30 02:59:51 -07:00
|
|
|
void
|
|
|
|
ImageHost::Dump(FILE* aFile,
|
|
|
|
const char* aPrefix,
|
|
|
|
bool aDumpHtml)
|
|
|
|
{
|
|
|
|
if (!aFile) {
|
|
|
|
aFile = stderr;
|
|
|
|
}
|
|
|
|
if (mFrontBuffer) {
|
2013-11-23 14:44:18 -08:00
|
|
|
fprintf_stderr(aFile, "%s", aPrefix);
|
|
|
|
fprintf_stderr(aFile, aDumpHtml ? "<ul><li>TextureHost: "
|
2013-07-30 02:59:51 -07:00
|
|
|
: "TextureHost: ");
|
|
|
|
DumpTextureHost(aFile, mFrontBuffer);
|
2013-11-23 14:44:18 -08:00
|
|
|
fprintf_stderr(aFile, aDumpHtml ? " </li></ul> " : " ");
|
2013-07-30 02:59:51 -07:00
|
|
|
}
|
|
|
|
}
|
2013-08-08 05:53:12 -07:00
|
|
|
#endif
|
2013-07-30 02:59:51 -07:00
|
|
|
|
|
|
|
LayerRenderState
|
|
|
|
ImageHost::GetRenderState()
|
|
|
|
{
|
|
|
|
if (mFrontBuffer) {
|
|
|
|
return mFrontBuffer->GetRenderState();
|
|
|
|
}
|
|
|
|
return LayerRenderState();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
2013-11-27 01:59:01 -08:00
|
|
|
TemporaryRef<gfx::DataSourceSurface>
|
2013-07-30 02:59:51 -07:00
|
|
|
ImageHost::GetAsSurface()
|
|
|
|
{
|
|
|
|
return mFrontBuffer->GetAsSurface();
|
|
|
|
}
|
|
|
|
#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 02:20:52 -07:00
|
|
|
}
|
|
|
|
}
|