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 "mozilla/layers/Compositor.h"
|
2013-08-11 23:17:23 +00:00
|
|
|
#include "base/message_loop.h" // for MessageLoop
|
|
|
|
#include "mozilla/layers/CompositorParent.h" // for CompositorParent
|
|
|
|
#include "mozilla/layers/Effects.h" // for Effect, EffectChain, etc
|
|
|
|
#include "mozilla/mozalloc.h" // for operator delete, etc
|
2013-10-24 14:35:29 +00:00
|
|
|
#include "gfx2DGlue.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 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
|
|
|
namespace layers {
|
|
|
|
|
2014-01-23 18:26:41 +00:00
|
|
|
/* static */ LayersBackend Compositor::sBackend = LayersBackend::LAYERS_NONE;
|
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
|
|
|
/* static */ LayersBackend
|
|
|
|
Compositor::GetBackend()
|
2013-07-30 18:03:40 +00:00
|
|
|
{
|
|
|
|
AssertOnCompositorThread();
|
|
|
|
return sBackend;
|
|
|
|
}
|
|
|
|
|
2014-02-13 16:53:50 +00:00
|
|
|
/* static */ void
|
|
|
|
Compositor::SetBackend(LayersBackend backend)
|
|
|
|
{
|
|
|
|
if (sBackend != LayersBackend::LAYERS_NONE && sBackend != backend) {
|
2014-02-14 21:35:49 +00:00
|
|
|
// Assert this once we figure out bug 972891.
|
|
|
|
//MOZ_CRASH("Trying to use more than one OMTC compositor.");
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
printf("ERROR: Changing compositor from %u to %u.\n",
|
|
|
|
unsigned(sBackend), unsigned(backend));
|
|
|
|
#endif
|
2014-02-13 16:53:50 +00:00
|
|
|
}
|
|
|
|
sBackend = backend;
|
|
|
|
}
|
|
|
|
|
2013-07-30 18:03:40 +00:00
|
|
|
/* static */ void
|
|
|
|
Compositor::AssertOnCompositorThread()
|
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
|
|
|
{
|
2013-06-26 23:30:52 +00:00
|
|
|
MOZ_ASSERT(CompositorParent::CompositorLoop() ==
|
|
|
|
MessageLoop::current(),
|
|
|
|
"Can only call this from the compositor thread!");
|
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
|
|
|
}
|
|
|
|
|
2013-10-24 14:35:29 +00:00
|
|
|
bool
|
|
|
|
Compositor::ShouldDrawDiagnostics(DiagnosticFlags aFlags)
|
|
|
|
{
|
2014-04-26 02:34:06 +00:00
|
|
|
if ((aFlags & DiagnosticFlags::TILE) && !(mDiagnosticTypes & DiagnosticTypes::TILE_BORDERS)) {
|
2013-10-24 14:35:29 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-04-26 02:34:06 +00:00
|
|
|
if ((aFlags & DiagnosticFlags::BIGIMAGE) &&
|
|
|
|
!(mDiagnosticTypes & DiagnosticTypes::BIGIMAGE_BORDERS)) {
|
2013-10-24 14:35:29 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-04-26 02:34:06 +00:00
|
|
|
if (mDiagnosticTypes == DiagnosticTypes::NO_DIAGNOSTIC) {
|
2013-10-24 14:35:29 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-21 17:08:01 +00:00
|
|
|
void
|
2013-08-02 22:50:17 +00:00
|
|
|
Compositor::DrawDiagnostics(DiagnosticFlags aFlags,
|
2013-10-24 14:35:29 +00:00
|
|
|
const nsIntRegion& aVisibleRegion,
|
2013-03-21 17:08:01 +00:00
|
|
|
const gfx::Rect& aClipRect,
|
2014-03-25 16:54:39 +00:00
|
|
|
const gfx::Matrix4x4& aTransform,
|
|
|
|
uint32_t aFlashCounter)
|
2013-03-21 17:08:01 +00:00
|
|
|
{
|
2013-10-24 14:35:29 +00:00
|
|
|
if (!ShouldDrawDiagnostics(aFlags)) {
|
2013-03-21 17:08:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-10-24 14:35:29 +00:00
|
|
|
|
|
|
|
if (aVisibleRegion.GetNumRects() > 1) {
|
|
|
|
nsIntRegionRectIterator screenIter(aVisibleRegion);
|
|
|
|
|
|
|
|
while (const nsIntRect* rect = screenIter.Next())
|
|
|
|
{
|
2014-04-26 02:34:06 +00:00
|
|
|
DrawDiagnostics(aFlags | DiagnosticFlags::REGION_RECT,
|
2014-03-25 16:54:39 +00:00
|
|
|
ToRect(*rect), aClipRect, aTransform, aFlashCounter);
|
2013-10-24 14:35:29 +00:00
|
|
|
}
|
2013-10-10 17:36:24 +00:00
|
|
|
}
|
2013-10-24 14:35:29 +00:00
|
|
|
|
|
|
|
DrawDiagnostics(aFlags, ToRect(aVisibleRegion.GetBounds()),
|
2014-03-25 16:54:39 +00:00
|
|
|
aClipRect, aTransform, aFlashCounter);
|
2013-10-24 14:35:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Compositor::DrawDiagnostics(DiagnosticFlags aFlags,
|
|
|
|
const gfx::Rect& aVisibleRect,
|
|
|
|
const gfx::Rect& aClipRect,
|
2014-03-25 16:54:39 +00:00
|
|
|
const gfx::Matrix4x4& aTransform,
|
|
|
|
uint32_t aFlashCounter)
|
2013-10-24 14:35:29 +00:00
|
|
|
{
|
|
|
|
if (!ShouldDrawDiagnostics(aFlags)) {
|
2013-08-02 22:50:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-25 16:54:39 +00:00
|
|
|
DrawDiagnosticsInternal(aFlags, aVisibleRect, aClipRect, aTransform,
|
|
|
|
aFlashCounter);
|
2013-10-24 14:35:29 +00:00
|
|
|
}
|
|
|
|
|
2014-07-30 18:36:15 +00:00
|
|
|
RenderTargetRect
|
2014-08-27 22:46:55 +00:00
|
|
|
Compositor::ClipRectInLayersCoordinates(Layer* aLayer, RenderTargetIntRect aClip) const {
|
|
|
|
ContainerLayer* parent = aLayer->AsContainerLayer() ? aLayer->AsContainerLayer() : aLayer->GetParent();
|
|
|
|
while (!parent->UseIntermediateSurface() && parent->GetParent()) {
|
|
|
|
parent = parent->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
RenderTargetIntPoint renderTargetOffset = RenderTargetIntRect::FromUntyped(
|
|
|
|
parent->GetEffectiveVisibleRegion().GetBounds()).TopLeft();
|
|
|
|
|
2014-07-30 18:36:15 +00:00
|
|
|
RenderTargetRect result;
|
2014-08-27 22:46:55 +00:00
|
|
|
aClip = aClip + renderTargetOffset;
|
2014-09-10 19:59:00 +00:00
|
|
|
result = RenderTargetRect(aClip.x, aClip.y, aClip.width, aClip.height);
|
2014-04-25 11:38:17 +00:00
|
|
|
return result;
|
2014-04-02 07:23:04 +00:00
|
|
|
}
|
|
|
|
|
2013-10-24 14:35:29 +00:00
|
|
|
void
|
|
|
|
Compositor::DrawDiagnosticsInternal(DiagnosticFlags aFlags,
|
|
|
|
const gfx::Rect& aVisibleRect,
|
|
|
|
const gfx::Rect& aClipRect,
|
2014-03-25 16:54:39 +00:00
|
|
|
const gfx::Matrix4x4& aTransform,
|
|
|
|
uint32_t aFlashCounter)
|
2013-10-24 14:35:29 +00:00
|
|
|
{
|
2013-10-10 17:36:24 +00:00
|
|
|
#ifdef MOZ_B2G
|
|
|
|
int lWidth = 4;
|
|
|
|
#elif defined(ANDROID)
|
|
|
|
int lWidth = 10;
|
|
|
|
#else
|
2013-08-02 22:50:17 +00:00
|
|
|
int lWidth = 2;
|
2013-10-10 17:36:24 +00:00
|
|
|
#endif
|
2014-01-09 14:26:19 +00:00
|
|
|
float opacity = 0.7f;
|
2013-08-02 22:50:17 +00:00
|
|
|
|
|
|
|
gfx::Color color;
|
2014-04-26 02:34:06 +00:00
|
|
|
if (aFlags & DiagnosticFlags::CONTENT) {
|
2014-01-09 14:26:19 +00:00
|
|
|
color = gfx::Color(0.0f, 1.0f, 0.0f, 1.0f); // green
|
2014-04-26 02:34:06 +00:00
|
|
|
if (aFlags & DiagnosticFlags::COMPONENT_ALPHA) {
|
2014-01-09 14:26:19 +00:00
|
|
|
color = gfx::Color(0.0f, 1.0f, 1.0f, 1.0f); // greenish blue
|
2013-08-02 22:50:17 +00:00
|
|
|
}
|
2014-04-26 02:34:06 +00:00
|
|
|
} else if (aFlags & DiagnosticFlags::IMAGE) {
|
2014-01-09 14:26:19 +00:00
|
|
|
color = gfx::Color(1.0f, 0.0f, 0.0f, 1.0f); // red
|
2014-04-26 02:34:06 +00:00
|
|
|
} else if (aFlags & DiagnosticFlags::COLOR) {
|
2014-01-09 14:26:19 +00:00
|
|
|
color = gfx::Color(0.0f, 0.0f, 1.0f, 1.0f); // blue
|
2014-04-26 02:34:06 +00:00
|
|
|
} else if (aFlags & DiagnosticFlags::CONTAINER) {
|
2014-01-09 14:26:19 +00:00
|
|
|
color = gfx::Color(0.8f, 0.0f, 0.8f, 1.0f); // purple
|
2013-08-02 22:50:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// make tile borders a bit more transparent to keep layer borders readable.
|
2014-04-26 02:34:06 +00:00
|
|
|
if (aFlags & DiagnosticFlags::TILE ||
|
|
|
|
aFlags & DiagnosticFlags::BIGIMAGE ||
|
|
|
|
aFlags & DiagnosticFlags::REGION_RECT) {
|
2013-08-02 22:50:17 +00:00
|
|
|
lWidth = 1;
|
2014-01-09 14:26:19 +00:00
|
|
|
opacity = 0.5f;
|
|
|
|
color.r *= 0.7f;
|
|
|
|
color.g *= 0.7f;
|
|
|
|
color.b *= 0.7f;
|
2013-08-02 22:50:17 +00:00
|
|
|
}
|
|
|
|
|
2014-04-26 02:34:06 +00:00
|
|
|
if (mDiagnosticTypes & DiagnosticTypes::FLASH_BORDERS) {
|
2014-03-25 16:54:39 +00:00
|
|
|
float flash = (float)aFlashCounter / (float)DIAGNOSTIC_FLASH_COUNTER_MAX;
|
|
|
|
color.r *= flash;
|
|
|
|
color.g *= flash;
|
|
|
|
color.b *= flash;
|
|
|
|
}
|
|
|
|
|
2013-03-21 17:08:01 +00:00
|
|
|
EffectChain effects;
|
2013-08-02 22:50:17 +00:00
|
|
|
|
|
|
|
effects.mPrimaryEffect = new EffectSolidColor(color);
|
2013-03-21 17:08:01 +00:00
|
|
|
// left
|
2013-10-24 14:35:29 +00:00
|
|
|
this->DrawQuad(gfx::Rect(aVisibleRect.x, aVisibleRect.y,
|
|
|
|
lWidth, aVisibleRect.height),
|
2013-03-21 17:08:01 +00:00
|
|
|
aClipRect, effects, opacity,
|
2013-11-07 09:53:08 +00:00
|
|
|
aTransform);
|
2013-03-21 17:08:01 +00:00
|
|
|
// top
|
2013-10-24 14:35:29 +00:00
|
|
|
this->DrawQuad(gfx::Rect(aVisibleRect.x + lWidth, aVisibleRect.y,
|
|
|
|
aVisibleRect.width - 2 * lWidth, lWidth),
|
2013-03-21 17:08:01 +00:00
|
|
|
aClipRect, effects, opacity,
|
2013-11-07 09:53:08 +00:00
|
|
|
aTransform);
|
2013-03-21 17:08:01 +00:00
|
|
|
// right
|
2013-10-24 14:35:29 +00:00
|
|
|
this->DrawQuad(gfx::Rect(aVisibleRect.x + aVisibleRect.width - lWidth, aVisibleRect.y,
|
|
|
|
lWidth, aVisibleRect.height),
|
2013-03-21 17:08:01 +00:00
|
|
|
aClipRect, effects, opacity,
|
2013-11-07 09:53:08 +00:00
|
|
|
aTransform);
|
2013-03-21 17:08:01 +00:00
|
|
|
// bottom
|
2013-10-24 14:35:29 +00:00
|
|
|
this->DrawQuad(gfx::Rect(aVisibleRect.x + lWidth, aVisibleRect.y + aVisibleRect.height-lWidth,
|
|
|
|
aVisibleRect.width - 2 * lWidth, lWidth),
|
2013-03-21 17:08:01 +00:00
|
|
|
aClipRect, effects, opacity,
|
2013-11-07 09:53:08 +00:00
|
|
|
aTransform);
|
2013-03-21 17:08:01 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
} // namespace
|