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 09:20:52 +00: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 23:17:23 +00: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 09:20:52 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
2013-08-11 23:17:23 +00: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 09:20:52 +00:00
|
|
|
|
|
|
|
using namespace gfx;
|
|
|
|
|
|
|
|
namespace layers {
|
|
|
|
|
2013-08-11 23:17:23 +00:00
|
|
|
class ISurfaceAllocator;
|
|
|
|
|
2013-07-30 09:59:51 +00:00
|
|
|
ImageHost::ImageHost(const TextureInfo& aTextureInfo)
|
|
|
|
: CompositableHost(aTextureInfo)
|
|
|
|
, mFrontBuffer(nullptr)
|
|
|
|
, mHasPictureRect(false)
|
2014-06-22 17:06:00 +00:00
|
|
|
, mLocked(false)
|
2013-07-30 09:59:51 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
ImageHost::~ImageHost() {}
|
|
|
|
|
|
|
|
void
|
|
|
|
ImageHost::UseTextureHost(TextureHost* aTexture)
|
|
|
|
{
|
2013-12-12 01:44:41 +00:00
|
|
|
CompositableHost::UseTextureHost(aTexture);
|
2013-07-30 09:59:51 +00:00
|
|
|
mFrontBuffer = aTexture;
|
|
|
|
}
|
|
|
|
|
2014-02-10 20:52:35 +00:00
|
|
|
void
|
|
|
|
ImageHost::RemoveTextureHost(TextureHost* aTexture)
|
|
|
|
{
|
|
|
|
CompositableHost::RemoveTextureHost(aTexture);
|
|
|
|
if (aTexture && mFrontBuffer == aTexture) {
|
|
|
|
aTexture->SetCompositableBackendSpecificData(nullptr);
|
|
|
|
mFrontBuffer = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-30 09:59:51 +00:00
|
|
|
TextureHost*
|
2013-12-05 18:39:22 +00:00
|
|
|
ImageHost::GetAsTextureHost()
|
2013-07-30 09:59:51 +00: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-12 01:44:41 +00:00
|
|
|
|
|
|
|
// Make sure the front buffer has a compositor
|
|
|
|
mFrontBuffer->SetCompositor(GetCompositor());
|
2014-02-16 01:00:16 +00:00
|
|
|
mFrontBuffer->SetCompositableBackendSpecificData(GetCompositableBackendSpecificData());
|
2013-12-12 01:44:41 +00:00
|
|
|
|
2014-06-22 17:06:00 +00:00
|
|
|
AutoLockCompositableHost autoLock(this);
|
2013-12-19 16:20:51 +00:00
|
|
|
if (autoLock.Failed()) {
|
2013-07-30 09:59:51 +00:00
|
|
|
NS_WARNING("failed to lock front buffer");
|
|
|
|
return;
|
|
|
|
}
|
2014-06-22 17:06:00 +00:00
|
|
|
RefPtr<NewTextureSource> source = GetTextureSource();
|
2013-07-30 09:59:51 +00:00
|
|
|
if (!source) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-19 00:04:06 +00:00
|
|
|
|
2014-06-22 17:06:00 +00:00
|
|
|
RefPtr<TexturedEffect> effect = GenEffect(aFilter);
|
2013-11-21 22:07:56 +00:00
|
|
|
if (!effect) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-30 09:59:51 +00:00
|
|
|
aEffectChain.mPrimaryEffect = effect;
|
2013-08-02 22:50:17 +00: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-02 01:12:16 +00:00
|
|
|
|
|
|
|
gfx::Rect pictureRect(0, 0,
|
|
|
|
mPictureRect.width,
|
|
|
|
mPictureRect.height);
|
2014-04-28 11:27:25 +00:00
|
|
|
BigImageIterator* it = source->AsBigImageIterator();
|
2013-07-30 09:59:51 +00:00
|
|
|
if (it) {
|
2014-05-28 10:52:12 +00:00
|
|
|
|
|
|
|
// This iteration does not work if we have multiple texture sources here
|
|
|
|
// (e.g. 3 YCbCr textures). There's nothing preventing the different
|
|
|
|
// planes from having different resolutions or tile sizes. For example, a
|
|
|
|
// YCbCr frame could have Cb and Cr planes that are half the resolution of
|
|
|
|
// the Y plane, in such a way that the Y plane overflows the maximum
|
|
|
|
// texture size and the Cb and Cr planes do not. Then the Y plane would be
|
|
|
|
// split into multiple tiles and the Cb and Cr planes would just be one
|
|
|
|
// tile each.
|
|
|
|
// To handle the general case correctly, we'd have to create a grid of
|
|
|
|
// intersected tiles over all planes, and then draw each grid tile using
|
|
|
|
// the corresponding source tiles from all planes, with appropriate
|
|
|
|
// per-plane per-tile texture coords.
|
|
|
|
// DrawQuad currently assumes that all planes use the same texture coords.
|
|
|
|
MOZ_ASSERT(it->GetTileCount() == 1 || !source->GetNextSibling(),
|
|
|
|
"Can't handle multi-plane BigImages");
|
|
|
|
|
2014-04-28 11:27:25 +00:00
|
|
|
it->BeginBigImageIteration();
|
2013-07-30 09:59:51 +00:00
|
|
|
do {
|
|
|
|
nsIntRect tileRect = it->GetTileRect();
|
|
|
|
gfx::Rect rect(tileRect.x, tileRect.y, tileRect.width, tileRect.height);
|
2013-08-02 01:12:16 +00: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);
|
|
|
|
}
|
2014-05-13 02:20:26 +00:00
|
|
|
if (mFrontBuffer->GetFlags() & TextureFlags::NEEDS_Y_FLIP) {
|
|
|
|
effect->mTextureCoords.y = effect->mTextureCoords.YMost();
|
|
|
|
effect->mTextureCoords.height = -effect->mTextureCoords.height;
|
|
|
|
}
|
2013-07-30 09:59:51 +00:00
|
|
|
GetCompositor()->DrawQuad(rect, aClipRect, aEffectChain,
|
2013-11-07 09:53:08 +00:00
|
|
|
aOpacity, aTransform);
|
2014-04-26 02:34:06 +00:00
|
|
|
GetCompositor()->DrawDiagnostics(DiagnosticFlags::IMAGE | DiagnosticFlags::BIGIMAGE,
|
2014-03-25 16:54:39 +00:00
|
|
|
rect, aClipRect, aTransform, mFlashCounter);
|
2013-07-30 09:59:51 +00:00
|
|
|
} while (it->NextTile());
|
2014-04-28 11:27:25 +00:00
|
|
|
it->EndBigImageIteration();
|
2013-08-02 22:50:17 +00:00
|
|
|
// layer border
|
2014-04-26 02:34:06 +00:00
|
|
|
GetCompositor()->DrawDiagnostics(DiagnosticFlags::IMAGE,
|
2013-08-02 22:50:17 +00:00
|
|
|
gfxPictureRect, aClipRect,
|
2014-03-25 16:54:39 +00:00
|
|
|
aTransform, mFlashCounter);
|
2013-07-30 09:59:51 +00:00
|
|
|
} else {
|
|
|
|
IntSize textureSize = source->GetSize();
|
2013-08-02 01:12:16 +00:00
|
|
|
gfx::Rect rect;
|
2013-07-30 09:59:51 +00: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-02 01:12:16 +00:00
|
|
|
rect = pictureRect;
|
2013-07-30 09:59:51 +00:00
|
|
|
} else {
|
|
|
|
effect->mTextureCoords = Rect(0, 0, 1, 1);
|
|
|
|
rect = gfx::Rect(0, 0, textureSize.width, textureSize.height);
|
|
|
|
}
|
|
|
|
|
2014-04-26 02:34:05 +00:00
|
|
|
if (mFrontBuffer->GetFlags() & TextureFlags::NEEDS_Y_FLIP) {
|
2013-07-30 09:59:51 +00:00
|
|
|
effect->mTextureCoords.y = effect->mTextureCoords.YMost();
|
|
|
|
effect->mTextureCoords.height = -effect->mTextureCoords.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
GetCompositor()->DrawQuad(rect, aClipRect, aEffectChain,
|
2013-11-07 09:53:08 +00:00
|
|
|
aOpacity, aTransform);
|
2014-04-26 02:34:06 +00:00
|
|
|
GetCompositor()->DrawDiagnostics(DiagnosticFlags::IMAGE,
|
2013-08-02 22:50:17 +00:00
|
|
|
rect, aClipRect,
|
2014-03-25 16:54:39 +00:00
|
|
|
aTransform, mFlashCounter);
|
2013-07-30 09:59:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-12 01:44:49 +00:00
|
|
|
void
|
|
|
|
ImageHost::SetCompositor(Compositor* aCompositor)
|
|
|
|
{
|
|
|
|
if (mFrontBuffer && mCompositor != aCompositor) {
|
|
|
|
mFrontBuffer->SetCompositor(aCompositor);
|
|
|
|
}
|
|
|
|
CompositableHost::SetCompositor(aCompositor);
|
|
|
|
}
|
|
|
|
|
2013-07-30 09:59:51 +00:00
|
|
|
void
|
2014-06-19 22:36:25 +00:00
|
|
|
ImageHost::PrintInfo(std::stringstream& aStream, const char* aPrefix)
|
2013-07-30 09:59:51 +00:00
|
|
|
{
|
2014-06-19 22:36:25 +00:00
|
|
|
aStream << aPrefix;
|
|
|
|
aStream << nsPrintfCString("ImageHost (0x%p)", this).get();
|
2013-07-30 09:59:51 +00:00
|
|
|
|
2014-06-19 22:36:25 +00:00
|
|
|
AppendToString(aStream, mPictureRect, " [picture-rect=", "]");
|
2013-07-30 09:59:51 +00:00
|
|
|
|
|
|
|
if (mFrontBuffer) {
|
|
|
|
nsAutoCString pfx(aPrefix);
|
|
|
|
pfx += " ";
|
2014-06-19 22:36:25 +00:00
|
|
|
aStream << "\n";
|
|
|
|
mFrontBuffer->PrintInfo(aStream, pfx.get());
|
2013-07-30 09:59:51 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-08 12:53:12 +00:00
|
|
|
|
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
2013-07-30 09:59:51 +00:00
|
|
|
void
|
2014-06-19 22:36:25 +00:00
|
|
|
ImageHost::Dump(std::stringstream& aStream,
|
2013-07-30 09:59:51 +00:00
|
|
|
const char* aPrefix,
|
|
|
|
bool aDumpHtml)
|
|
|
|
{
|
|
|
|
if (mFrontBuffer) {
|
2014-06-19 22:36:25 +00:00
|
|
|
aStream << aPrefix;
|
|
|
|
aStream << (aDumpHtml ? "<ul><li>TextureHost: "
|
2013-07-30 09:59:51 +00:00
|
|
|
: "TextureHost: ");
|
2014-06-19 22:36:25 +00:00
|
|
|
DumpTextureHost(aStream, mFrontBuffer);
|
|
|
|
aStream << (aDumpHtml ? " </li></ul> " : " ");
|
2013-07-30 09:59:51 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-08 12:53:12 +00:00
|
|
|
#endif
|
2013-07-30 09:59:51 +00:00
|
|
|
|
|
|
|
LayerRenderState
|
|
|
|
ImageHost::GetRenderState()
|
|
|
|
{
|
|
|
|
if (mFrontBuffer) {
|
|
|
|
return mFrontBuffer->GetRenderState();
|
|
|
|
}
|
|
|
|
return LayerRenderState();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
2013-11-27 09:59:01 +00:00
|
|
|
TemporaryRef<gfx::DataSourceSurface>
|
2013-07-30 09:59:51 +00:00
|
|
|
ImageHost::GetAsSurface()
|
|
|
|
{
|
|
|
|
return mFrontBuffer->GetAsSurface();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-06-22 17:06:00 +00:00
|
|
|
bool
|
|
|
|
ImageHost::Lock()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mLocked);
|
|
|
|
if (!mFrontBuffer->Lock()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mLocked = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ImageHost::Unlock()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mLocked);
|
|
|
|
mFrontBuffer->Unlock();
|
|
|
|
mLocked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
TemporaryRef<NewTextureSource>
|
|
|
|
ImageHost::GetTextureSource()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mLocked);
|
|
|
|
return mFrontBuffer->GetTextureSources();
|
|
|
|
}
|
|
|
|
|
|
|
|
TemporaryRef<TexturedEffect>
|
|
|
|
ImageHost::GenEffect(const gfx::Filter& aFilter)
|
|
|
|
{
|
|
|
|
RefPtr<NewTextureSource> source = GetTextureSource();
|
|
|
|
if (!source) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
bool isAlphaPremultiplied = true;
|
|
|
|
if (mFrontBuffer->GetFlags() & TextureFlags::NON_PREMULTIPLIED)
|
|
|
|
isAlphaPremultiplied = false;
|
|
|
|
|
|
|
|
return CreateTexturedEffect(mFrontBuffer->GetFormat(),
|
|
|
|
source,
|
|
|
|
aFilter,
|
|
|
|
isAlphaPremultiplied);
|
|
|
|
}
|
|
|
|
|
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 09:20:52 +00:00
|
|
|
}
|
|
|
|
}
|