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/Compositor.h"
|
2013-08-12 03:17:23 +04: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 18:35:29 +04: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 13:20:52 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2013-08-12 03:17:23 +04: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 13:20:52 +04:00
|
|
|
namespace layers {
|
|
|
|
|
2014-01-23 22:26:41 +04: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 13:20:52 +04:00
|
|
|
/* static */ LayersBackend
|
|
|
|
Compositor::GetBackend()
|
2013-07-30 22:03:40 +04:00
|
|
|
{
|
|
|
|
AssertOnCompositorThread();
|
|
|
|
return sBackend;
|
|
|
|
}
|
|
|
|
|
2014-02-13 20:53:50 +04:00
|
|
|
/* static */ void
|
|
|
|
Compositor::SetBackend(LayersBackend backend)
|
|
|
|
{
|
|
|
|
if (sBackend != LayersBackend::LAYERS_NONE && sBackend != backend) {
|
2014-02-15 01:35:49 +04: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 20:53:50 +04:00
|
|
|
}
|
|
|
|
sBackend = backend;
|
|
|
|
}
|
|
|
|
|
2013-07-30 22:03:40 +04: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 13:20:52 +04:00
|
|
|
{
|
2013-06-27 03:30:52 +04: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 13:20:52 +04:00
|
|
|
}
|
|
|
|
|
2013-10-24 18:35:29 +04:00
|
|
|
bool
|
|
|
|
Compositor::ShouldDrawDiagnostics(DiagnosticFlags aFlags)
|
|
|
|
{
|
2014-04-26 06:34:06 +04:00
|
|
|
if ((aFlags & DiagnosticFlags::TILE) && !(mDiagnosticTypes & DiagnosticTypes::TILE_BORDERS)) {
|
2013-10-24 18:35:29 +04:00
|
|
|
return false;
|
|
|
|
}
|
2014-04-26 06:34:06 +04:00
|
|
|
if ((aFlags & DiagnosticFlags::BIGIMAGE) &&
|
|
|
|
!(mDiagnosticTypes & DiagnosticTypes::BIGIMAGE_BORDERS)) {
|
2013-10-24 18:35:29 +04:00
|
|
|
return false;
|
|
|
|
}
|
2014-04-26 06:34:06 +04:00
|
|
|
if (mDiagnosticTypes == DiagnosticTypes::NO_DIAGNOSTIC) {
|
2013-10-24 18:35:29 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-21 21:08:01 +04:00
|
|
|
void
|
2013-08-03 02:50:17 +04:00
|
|
|
Compositor::DrawDiagnostics(DiagnosticFlags aFlags,
|
2013-10-24 18:35:29 +04:00
|
|
|
const nsIntRegion& aVisibleRegion,
|
2013-03-21 21:08:01 +04:00
|
|
|
const gfx::Rect& aClipRect,
|
2014-03-25 20:54:39 +04:00
|
|
|
const gfx::Matrix4x4& aTransform,
|
|
|
|
uint32_t aFlashCounter)
|
2013-03-21 21:08:01 +04:00
|
|
|
{
|
2013-10-24 18:35:29 +04:00
|
|
|
if (!ShouldDrawDiagnostics(aFlags)) {
|
2013-03-21 21:08:01 +04:00
|
|
|
return;
|
|
|
|
}
|
2013-10-24 18:35:29 +04:00
|
|
|
|
|
|
|
if (aVisibleRegion.GetNumRects() > 1) {
|
|
|
|
nsIntRegionRectIterator screenIter(aVisibleRegion);
|
|
|
|
|
|
|
|
while (const nsIntRect* rect = screenIter.Next())
|
|
|
|
{
|
2014-04-26 06:34:06 +04:00
|
|
|
DrawDiagnostics(aFlags | DiagnosticFlags::REGION_RECT,
|
2014-03-25 20:54:39 +04:00
|
|
|
ToRect(*rect), aClipRect, aTransform, aFlashCounter);
|
2013-10-24 18:35:29 +04:00
|
|
|
}
|
2013-10-10 21:36:24 +04:00
|
|
|
}
|
2013-10-24 18:35:29 +04:00
|
|
|
|
|
|
|
DrawDiagnostics(aFlags, ToRect(aVisibleRegion.GetBounds()),
|
2014-03-25 20:54:39 +04:00
|
|
|
aClipRect, aTransform, aFlashCounter);
|
2013-10-24 18:35:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Compositor::DrawDiagnostics(DiagnosticFlags aFlags,
|
|
|
|
const gfx::Rect& aVisibleRect,
|
|
|
|
const gfx::Rect& aClipRect,
|
2014-03-25 20:54:39 +04:00
|
|
|
const gfx::Matrix4x4& aTransform,
|
|
|
|
uint32_t aFlashCounter)
|
2013-10-24 18:35:29 +04:00
|
|
|
{
|
|
|
|
if (!ShouldDrawDiagnostics(aFlags)) {
|
2013-08-03 02:50:17 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-25 20:54:39 +04:00
|
|
|
DrawDiagnosticsInternal(aFlags, aVisibleRect, aClipRect, aTransform,
|
|
|
|
aFlashCounter);
|
2013-10-24 18:35:29 +04:00
|
|
|
}
|
|
|
|
|
2014-04-02 11:23:04 +04:00
|
|
|
gfx::Rect
|
|
|
|
Compositor::ClipRectInLayersCoordinates(gfx::Rect aClip) const {
|
|
|
|
gfx::Rect result;
|
2014-04-25 15:38:17 +04:00
|
|
|
aClip = aClip + GetCurrentRenderTarget()->GetOrigin();
|
|
|
|
gfx::IntSize destSize = GetWidgetSize();
|
|
|
|
|
2014-04-02 11:23:04 +04:00
|
|
|
switch (mScreenRotation) {
|
2014-04-25 15:38:17 +04:00
|
|
|
case ROTATION_0:
|
|
|
|
result = aClip;
|
|
|
|
break;
|
2014-04-02 11:23:04 +04:00
|
|
|
case ROTATION_90:
|
2014-04-25 15:38:17 +04:00
|
|
|
result = gfx::Rect(aClip.y,
|
|
|
|
destSize.width - aClip.x - aClip.width,
|
|
|
|
aClip.height, aClip.width);
|
|
|
|
break;
|
2014-04-02 11:23:04 +04:00
|
|
|
case ROTATION_270:
|
2014-04-25 15:38:17 +04:00
|
|
|
result = gfx::Rect(destSize.height - aClip.y - aClip.height,
|
|
|
|
aClip.x,
|
|
|
|
aClip.height, aClip.width);
|
2014-04-02 11:23:04 +04:00
|
|
|
break;
|
|
|
|
case ROTATION_180:
|
2014-04-25 15:38:17 +04:00
|
|
|
result = gfx::Rect(destSize.width - aClip.x - aClip.width,
|
|
|
|
destSize.height - aClip.y - aClip.height,
|
|
|
|
aClip.width, aClip.height);
|
2014-04-02 11:23:04 +04:00
|
|
|
break;
|
2014-04-25 15:38:17 +04:00
|
|
|
// ScreenRotation has a sentinel value, need to catch it in the switch
|
|
|
|
// statement otherwise the build fails (-WError)
|
|
|
|
default: {}
|
2014-04-02 11:23:04 +04:00
|
|
|
}
|
2014-04-25 15:38:17 +04:00
|
|
|
return result;
|
2014-04-02 11:23:04 +04:00
|
|
|
}
|
|
|
|
|
2013-10-24 18:35:29 +04:00
|
|
|
void
|
|
|
|
Compositor::DrawDiagnosticsInternal(DiagnosticFlags aFlags,
|
|
|
|
const gfx::Rect& aVisibleRect,
|
|
|
|
const gfx::Rect& aClipRect,
|
2014-03-25 20:54:39 +04:00
|
|
|
const gfx::Matrix4x4& aTransform,
|
|
|
|
uint32_t aFlashCounter)
|
2013-10-24 18:35:29 +04:00
|
|
|
{
|
2013-10-10 21:36:24 +04:00
|
|
|
#ifdef MOZ_B2G
|
|
|
|
int lWidth = 4;
|
|
|
|
#elif defined(ANDROID)
|
|
|
|
int lWidth = 10;
|
|
|
|
#else
|
2013-08-03 02:50:17 +04:00
|
|
|
int lWidth = 2;
|
2013-10-10 21:36:24 +04:00
|
|
|
#endif
|
2014-01-09 18:26:19 +04:00
|
|
|
float opacity = 0.7f;
|
2013-08-03 02:50:17 +04:00
|
|
|
|
|
|
|
gfx::Color color;
|
2014-04-26 06:34:06 +04:00
|
|
|
if (aFlags & DiagnosticFlags::CONTENT) {
|
2014-01-09 18:26:19 +04:00
|
|
|
color = gfx::Color(0.0f, 1.0f, 0.0f, 1.0f); // green
|
2014-04-26 06:34:06 +04:00
|
|
|
if (aFlags & DiagnosticFlags::COMPONENT_ALPHA) {
|
2014-01-09 18:26:19 +04:00
|
|
|
color = gfx::Color(0.0f, 1.0f, 1.0f, 1.0f); // greenish blue
|
2013-08-03 02:50:17 +04:00
|
|
|
}
|
2014-04-26 06:34:06 +04:00
|
|
|
} else if (aFlags & DiagnosticFlags::IMAGE) {
|
2014-01-09 18:26:19 +04:00
|
|
|
color = gfx::Color(1.0f, 0.0f, 0.0f, 1.0f); // red
|
2014-04-26 06:34:06 +04:00
|
|
|
} else if (aFlags & DiagnosticFlags::COLOR) {
|
2014-01-09 18:26:19 +04:00
|
|
|
color = gfx::Color(0.0f, 0.0f, 1.0f, 1.0f); // blue
|
2014-04-26 06:34:06 +04:00
|
|
|
} else if (aFlags & DiagnosticFlags::CONTAINER) {
|
2014-01-09 18:26:19 +04:00
|
|
|
color = gfx::Color(0.8f, 0.0f, 0.8f, 1.0f); // purple
|
2013-08-03 02:50:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// make tile borders a bit more transparent to keep layer borders readable.
|
2014-04-26 06:34:06 +04:00
|
|
|
if (aFlags & DiagnosticFlags::TILE ||
|
|
|
|
aFlags & DiagnosticFlags::BIGIMAGE ||
|
|
|
|
aFlags & DiagnosticFlags::REGION_RECT) {
|
2013-08-03 02:50:17 +04:00
|
|
|
lWidth = 1;
|
2014-01-09 18:26:19 +04:00
|
|
|
opacity = 0.5f;
|
|
|
|
color.r *= 0.7f;
|
|
|
|
color.g *= 0.7f;
|
|
|
|
color.b *= 0.7f;
|
2013-08-03 02:50:17 +04:00
|
|
|
}
|
|
|
|
|
2014-04-26 06:34:06 +04:00
|
|
|
if (mDiagnosticTypes & DiagnosticTypes::FLASH_BORDERS) {
|
2014-03-25 20:54:39 +04:00
|
|
|
float flash = (float)aFlashCounter / (float)DIAGNOSTIC_FLASH_COUNTER_MAX;
|
|
|
|
color.r *= flash;
|
|
|
|
color.g *= flash;
|
|
|
|
color.b *= flash;
|
|
|
|
}
|
|
|
|
|
2013-03-21 21:08:01 +04:00
|
|
|
EffectChain effects;
|
2013-08-03 02:50:17 +04:00
|
|
|
|
|
|
|
effects.mPrimaryEffect = new EffectSolidColor(color);
|
2013-03-21 21:08:01 +04:00
|
|
|
// left
|
2013-10-24 18:35:29 +04:00
|
|
|
this->DrawQuad(gfx::Rect(aVisibleRect.x, aVisibleRect.y,
|
|
|
|
lWidth, aVisibleRect.height),
|
2013-03-21 21:08:01 +04:00
|
|
|
aClipRect, effects, opacity,
|
2013-11-07 13:53:08 +04:00
|
|
|
aTransform);
|
2013-03-21 21:08:01 +04:00
|
|
|
// top
|
2013-10-24 18:35:29 +04:00
|
|
|
this->DrawQuad(gfx::Rect(aVisibleRect.x + lWidth, aVisibleRect.y,
|
|
|
|
aVisibleRect.width - 2 * lWidth, lWidth),
|
2013-03-21 21:08:01 +04:00
|
|
|
aClipRect, effects, opacity,
|
2013-11-07 13:53:08 +04:00
|
|
|
aTransform);
|
2013-03-21 21:08:01 +04:00
|
|
|
// right
|
2013-10-24 18:35:29 +04:00
|
|
|
this->DrawQuad(gfx::Rect(aVisibleRect.x + aVisibleRect.width - lWidth, aVisibleRect.y,
|
|
|
|
lWidth, aVisibleRect.height),
|
2013-03-21 21:08:01 +04:00
|
|
|
aClipRect, effects, opacity,
|
2013-11-07 13:53:08 +04:00
|
|
|
aTransform);
|
2013-03-21 21:08:01 +04:00
|
|
|
// bottom
|
2013-10-24 18:35:29 +04:00
|
|
|
this->DrawQuad(gfx::Rect(aVisibleRect.x + lWidth, aVisibleRect.y + aVisibleRect.height-lWidth,
|
|
|
|
aVisibleRect.width - 2 * lWidth, lWidth),
|
2013-03-21 21:08:01 +04:00
|
|
|
aClipRect, effects, opacity,
|
2013-11-07 13:53:08 +04:00
|
|
|
aTransform);
|
2013-03-21 21:08:01 +04: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 13:20:52 +04:00
|
|
|
} // namespace
|
|
|
|
} // namespace
|