2010-07-21 18:06:33 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: sw=2 ts=8 et :
|
|
|
|
*/
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2010-07-21 18:06:33 +00:00
|
|
|
|
2011-08-09 19:38:26 +00:00
|
|
|
#include "mozilla/layers/PLayers.h"
|
2011-04-03 02:14:00 +00:00
|
|
|
#include "mozilla/layers/ShadowLayers.h"
|
2012-07-13 19:38:09 +00:00
|
|
|
#include "mozilla/layers/ImageBridgeChild.h" // TODO: temp
|
2010-10-13 22:55:45 +00:00
|
|
|
|
2010-07-21 18:06:33 +00:00
|
|
|
#include "ImageLayers.h"
|
2010-09-03 20:10:45 +00:00
|
|
|
#include "Layers.h"
|
2010-09-08 03:27:29 +00:00
|
|
|
#include "gfxPlatform.h"
|
2011-02-16 22:43:30 +00:00
|
|
|
#include "ReadbackLayer.h"
|
2011-02-25 07:44:22 +00:00
|
|
|
#include "gfxUtils.h"
|
2011-08-25 08:46:01 +00:00
|
|
|
#include "nsPrintfCString.h"
|
2011-05-23 00:27:03 +00:00
|
|
|
#include "mozilla/Util.h"
|
2011-10-06 21:23:18 +00:00
|
|
|
#include "LayerSorter.h"
|
2012-07-31 17:28:20 +00:00
|
|
|
#include "AnimationCommon.h"
|
2010-09-03 20:10:45 +00:00
|
|
|
|
|
|
|
using namespace mozilla::layers;
|
2011-06-24 17:41:18 +00:00
|
|
|
using namespace mozilla::gfx;
|
2011-01-13 17:45:14 +00:00
|
|
|
|
|
|
|
typedef FrameMetrics::ViewID ViewID;
|
|
|
|
const ViewID FrameMetrics::NULL_SCROLL_ID = 0;
|
|
|
|
const ViewID FrameMetrics::ROOT_SCROLL_ID = 1;
|
|
|
|
const ViewID FrameMetrics::START_SCROLL_ID = 2;
|
|
|
|
|
2010-07-21 18:06:33 +00:00
|
|
|
#ifdef MOZ_LAYERS_HAVE_LOG
|
|
|
|
FILE*
|
|
|
|
FILEOrDefault(FILE* aFile)
|
|
|
|
{
|
|
|
|
return aFile ? aFile : stderr;
|
|
|
|
}
|
|
|
|
#endif // MOZ_LAYERS_HAVE_LOG
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// XXX pretty general utilities, could centralize
|
2010-09-03 20:10:45 +00:00
|
|
|
|
2011-02-16 22:43:30 +00:00
|
|
|
nsACString&
|
|
|
|
AppendToString(nsACString& s, const void* p,
|
|
|
|
const char* pfx="", const char* sfx="")
|
|
|
|
{
|
|
|
|
s += pfx;
|
2012-04-24 18:43:00 +00:00
|
|
|
s += nsPrintfCString("%p", p);
|
2011-02-16 22:43:30 +00:00
|
|
|
return s += sfx;
|
|
|
|
}
|
|
|
|
|
2010-07-21 18:06:33 +00:00
|
|
|
nsACString&
|
|
|
|
AppendToString(nsACString& s, const gfxPattern::GraphicsFilter& f,
|
|
|
|
const char* pfx="", const char* sfx="")
|
|
|
|
{
|
|
|
|
s += pfx;
|
|
|
|
switch (f) {
|
|
|
|
case gfxPattern::FILTER_FAST: s += "fast"; break;
|
|
|
|
case gfxPattern::FILTER_GOOD: s += "good"; break;
|
|
|
|
case gfxPattern::FILTER_BEST: s += "best"; break;
|
|
|
|
case gfxPattern::FILTER_NEAREST: s += "nearest"; break;
|
|
|
|
case gfxPattern::FILTER_BILINEAR: s += "bilinear"; break;
|
|
|
|
case gfxPattern::FILTER_GAUSSIAN: s += "gaussian"; break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("unknown filter type");
|
|
|
|
s += "???";
|
|
|
|
}
|
|
|
|
return s += sfx;
|
|
|
|
}
|
|
|
|
|
2011-01-13 17:45:14 +00:00
|
|
|
nsACString&
|
|
|
|
AppendToString(nsACString& s, ViewID n,
|
|
|
|
const char* pfx="", const char* sfx="")
|
|
|
|
{
|
|
|
|
s += pfx;
|
|
|
|
s.AppendInt(n);
|
|
|
|
return s += sfx;
|
|
|
|
}
|
|
|
|
|
2010-07-21 18:06:33 +00:00
|
|
|
nsACString&
|
|
|
|
AppendToString(nsACString& s, const gfxRGBA& c,
|
|
|
|
const char* pfx="", const char* sfx="")
|
|
|
|
{
|
|
|
|
s += pfx;
|
|
|
|
s += nsPrintfCString(
|
2012-04-24 18:43:00 +00:00
|
|
|
"rgba(%d, %d, %d, %g)",
|
2010-07-21 18:06:33 +00:00
|
|
|
PRUint8(c.r*255.0), PRUint8(c.g*255.0), PRUint8(c.b*255.0), c.a);
|
|
|
|
return s += sfx;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsACString&
|
|
|
|
AppendToString(nsACString& s, const gfx3DMatrix& m,
|
|
|
|
const char* pfx="", const char* sfx="")
|
|
|
|
{
|
|
|
|
s += pfx;
|
|
|
|
if (m.IsIdentity())
|
|
|
|
s += "[ I ]";
|
|
|
|
else {
|
|
|
|
gfxMatrix matrix;
|
|
|
|
if (m.Is2D(&matrix)) {
|
|
|
|
s += nsPrintfCString(
|
2012-04-24 18:43:00 +00:00
|
|
|
"[ %g %g; %g %g; %g %g; ]",
|
2010-08-02 03:06:58 +00:00
|
|
|
matrix.xx, matrix.yx, matrix.xy, matrix.yy, matrix.x0, matrix.y0);
|
2010-07-21 18:06:33 +00:00
|
|
|
} else {
|
|
|
|
s += nsPrintfCString(
|
2012-04-24 18:43:00 +00:00
|
|
|
"[ %g %g %g %g; %g %g %g %g; %g %g %g %g; %g %g %g %g; ]",
|
2010-07-21 18:06:33 +00:00
|
|
|
m._11, m._12, m._13, m._14,
|
|
|
|
m._21, m._22, m._23, m._24,
|
|
|
|
m._31, m._32, m._33, m._34,
|
|
|
|
m._41, m._42, m._43, m._44);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return s += sfx;
|
|
|
|
}
|
|
|
|
|
2010-09-03 20:10:45 +00:00
|
|
|
nsACString&
|
|
|
|
AppendToString(nsACString& s, const nsIntPoint& p,
|
|
|
|
const char* pfx="", const char* sfx="")
|
|
|
|
{
|
|
|
|
s += pfx;
|
2012-04-24 18:43:00 +00:00
|
|
|
s += nsPrintfCString("(x=%d, y=%d)", p.x, p.y);
|
2010-09-03 20:10:45 +00:00
|
|
|
return s += sfx;
|
|
|
|
}
|
|
|
|
|
2010-07-21 18:06:33 +00:00
|
|
|
nsACString&
|
|
|
|
AppendToString(nsACString& s, const nsIntRect& r,
|
|
|
|
const char* pfx="", const char* sfx="")
|
|
|
|
{
|
|
|
|
s += pfx;
|
|
|
|
s += nsPrintfCString(
|
2012-04-24 18:43:00 +00:00
|
|
|
"(x=%d, y=%d, w=%d, h=%d)",
|
2010-07-21 18:06:33 +00:00
|
|
|
r.x, r.y, r.width, r.height);
|
|
|
|
return s += sfx;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsACString&
|
|
|
|
AppendToString(nsACString& s, const nsIntRegion& r,
|
|
|
|
const char* pfx="", const char* sfx="")
|
|
|
|
{
|
|
|
|
s += pfx;
|
|
|
|
|
|
|
|
nsIntRegionRectIterator it(r);
|
|
|
|
s += "< ";
|
|
|
|
while (const nsIntRect* sr = it.Next())
|
|
|
|
AppendToString(s, *sr) += "; ";
|
|
|
|
s += ">";
|
|
|
|
|
|
|
|
return s += sfx;
|
|
|
|
}
|
|
|
|
|
2010-09-03 20:10:45 +00:00
|
|
|
nsACString&
|
|
|
|
AppendToString(nsACString& s, const nsIntSize& sz,
|
|
|
|
const char* pfx="", const char* sfx="")
|
|
|
|
{
|
|
|
|
s += pfx;
|
2012-04-24 18:43:00 +00:00
|
|
|
s += nsPrintfCString("(w=%d, h=%d)", sz.width, sz.height);
|
2010-09-03 20:10:45 +00:00
|
|
|
return s += sfx;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsACString&
|
|
|
|
AppendToString(nsACString& s, const FrameMetrics& m,
|
|
|
|
const char* pfx="", const char* sfx="")
|
|
|
|
{
|
|
|
|
s += pfx;
|
2011-01-13 17:45:14 +00:00
|
|
|
AppendToString(s, m.mViewport, "{ viewport=");
|
2010-09-03 20:10:45 +00:00
|
|
|
AppendToString(s, m.mViewportScrollOffset, " viewportScroll=");
|
2011-01-13 17:45:14 +00:00
|
|
|
AppendToString(s, m.mDisplayPort, " displayport=");
|
|
|
|
AppendToString(s, m.mScrollId, " scrollId=", " }");
|
2010-09-03 20:10:45 +00:00
|
|
|
return s += sfx;
|
|
|
|
}
|
|
|
|
|
2010-07-21 18:06:33 +00:00
|
|
|
} // namespace <anon>
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
2010-07-21 18:06:33 +00:00
|
|
|
|
2010-09-08 03:27:29 +00:00
|
|
|
//--------------------------------------------------
|
|
|
|
// LayerManager
|
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
LayerManager::CreateOptimalSurface(const gfxIntSize &aSize,
|
|
|
|
gfxASurface::gfxImageFormat aFormat)
|
|
|
|
{
|
2010-09-16 21:34:53 +00:00
|
|
|
return gfxPlatform::GetPlatform()->
|
|
|
|
CreateOffscreenSurface(aSize, gfxASurface::ContentFromFormat(aFormat));
|
2010-09-08 03:27:29 +00:00
|
|
|
}
|
|
|
|
|
2012-06-26 02:43:31 +00:00
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
LayerManager::CreateOptimalMaskSurface(const gfxIntSize &aSize)
|
|
|
|
{
|
|
|
|
return CreateOptimalSurface(aSize, gfxASurface::ImageFormatA8);
|
|
|
|
}
|
|
|
|
|
2011-06-24 17:41:18 +00:00
|
|
|
TemporaryRef<DrawTarget>
|
|
|
|
LayerManager::CreateDrawTarget(const IntSize &aSize,
|
|
|
|
SurfaceFormat aFormat)
|
|
|
|
{
|
2011-11-02 19:55:03 +00:00
|
|
|
return gfxPlatform::GetPlatform()->
|
|
|
|
CreateOffscreenDrawTarget(aSize, aFormat);
|
2011-06-24 17:41:18 +00:00
|
|
|
}
|
|
|
|
|
2011-01-26 06:26:37 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
LayerManager::Mutated(Layer* aLayer)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
|
2012-02-01 02:18:30 +00:00
|
|
|
already_AddRefed<ImageContainer>
|
|
|
|
LayerManager::CreateImageContainer()
|
|
|
|
{
|
2012-07-13 19:38:09 +00:00
|
|
|
nsRefPtr<ImageContainer> container = new ImageContainer(ImageContainer::DISABLE_ASYNC);
|
|
|
|
return container.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<ImageContainer>
|
|
|
|
LayerManager::CreateAsynchronousImageContainer()
|
|
|
|
{
|
|
|
|
nsRefPtr<ImageContainer> container = new ImageContainer(ImageContainer::ENABLE_ASYNC);
|
2012-02-01 02:18:30 +00:00
|
|
|
return container.forget();
|
|
|
|
}
|
|
|
|
|
2010-07-21 18:06:33 +00:00
|
|
|
//--------------------------------------------------
|
|
|
|
// Layer
|
2010-07-21 18:06:33 +00:00
|
|
|
|
2012-07-31 17:28:20 +00:00
|
|
|
Layer::Layer(LayerManager* aManager, void* aImplData) :
|
|
|
|
mManager(aManager),
|
|
|
|
mParent(nullptr),
|
|
|
|
mNextSibling(nullptr),
|
|
|
|
mPrevSibling(nullptr),
|
|
|
|
mImplData(aImplData),
|
|
|
|
mMaskLayer(nullptr),
|
|
|
|
mXScale(1.0f),
|
|
|
|
mYScale(1.0f),
|
|
|
|
mOpacity(1.0),
|
|
|
|
mContentFlags(0),
|
|
|
|
mUseClipRect(false),
|
|
|
|
mUseTileSourceRect(false),
|
|
|
|
mIsFixedPosition(false),
|
|
|
|
mDebugColorIndex(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
Layer::~Layer()
|
|
|
|
{}
|
|
|
|
|
|
|
|
void
|
|
|
|
Layer::AddAnimation(const Animation& aAnimation)
|
|
|
|
{
|
|
|
|
if (!AsShadowableLayer() || !AsShadowableLayer()->HasShadow())
|
|
|
|
return;
|
|
|
|
|
|
|
|
MOZ_ASSERT(aAnimation.segments().Length() >= 1);
|
|
|
|
|
|
|
|
mAnimations.AppendElement(aAnimation);
|
|
|
|
Mutated();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Layer::ClearAnimations()
|
|
|
|
{
|
|
|
|
mAnimations.Clear();
|
|
|
|
mAnimationData.Clear();
|
|
|
|
Mutated();
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsCSSValueList*
|
|
|
|
CreateCSSValueList(const InfallibleTArray<TransformFunction>& aFunctions)
|
|
|
|
{
|
|
|
|
nsAutoPtr<nsCSSValueList> result;
|
|
|
|
nsCSSValueList** resultTail = getter_Transfers(result);
|
|
|
|
for (PRUint32 i = 0; i < aFunctions.Length(); i++) {
|
|
|
|
nsRefPtr<nsCSSValue::Array> arr;
|
|
|
|
switch (aFunctions[i].type()) {
|
|
|
|
case TransformFunction::TRotationX:
|
|
|
|
{
|
|
|
|
float theta = aFunctions[i].get_RotationX().radians();
|
|
|
|
arr = nsStyleAnimation::AppendTransformFunction(eCSSKeyword_rotatex, resultTail);
|
|
|
|
arr->Item(1).SetFloatValue(theta, eCSSUnit_Radian);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TransformFunction::TRotationY:
|
|
|
|
{
|
|
|
|
float theta = aFunctions[i].get_RotationY().radians();
|
|
|
|
arr = nsStyleAnimation::AppendTransformFunction(eCSSKeyword_rotatey, resultTail);
|
|
|
|
arr->Item(1).SetFloatValue(theta, eCSSUnit_Radian);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TransformFunction::TRotationZ:
|
|
|
|
{
|
|
|
|
float theta = aFunctions[i].get_RotationZ().radians();
|
|
|
|
arr = nsStyleAnimation::AppendTransformFunction(eCSSKeyword_rotatez, resultTail);
|
|
|
|
arr->Item(1).SetFloatValue(theta, eCSSUnit_Radian);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TransformFunction::TRotation:
|
|
|
|
{
|
|
|
|
float theta = aFunctions[i].get_Rotation().radians();
|
|
|
|
arr = nsStyleAnimation::AppendTransformFunction(eCSSKeyword_rotate, resultTail);
|
|
|
|
arr->Item(1).SetFloatValue(theta, eCSSUnit_Radian);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TransformFunction::TRotation3D:
|
|
|
|
{
|
|
|
|
float x = aFunctions[i].get_Rotation3D().x();
|
|
|
|
float y = aFunctions[i].get_Rotation3D().y();
|
|
|
|
float z = aFunctions[i].get_Rotation3D().z();
|
|
|
|
float theta = aFunctions[i].get_Rotation3D().radians();
|
|
|
|
arr = nsStyleAnimation::AppendTransformFunction(eCSSKeyword_rotate3d, resultTail);
|
|
|
|
arr->Item(1).SetFloatValue(x, eCSSUnit_Number);
|
|
|
|
arr->Item(2).SetFloatValue(y, eCSSUnit_Number);
|
|
|
|
arr->Item(3).SetFloatValue(z, eCSSUnit_Number);
|
|
|
|
arr->Item(4).SetFloatValue(theta, eCSSUnit_Radian);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TransformFunction::TScale:
|
|
|
|
{
|
|
|
|
arr = nsStyleAnimation::AppendTransformFunction(eCSSKeyword_scale3d, resultTail);
|
|
|
|
arr->Item(1).SetFloatValue(aFunctions[i].get_Scale().x(), eCSSUnit_Number);
|
|
|
|
arr->Item(2).SetFloatValue(aFunctions[i].get_Scale().y(), eCSSUnit_Number);
|
|
|
|
arr->Item(3).SetFloatValue(aFunctions[i].get_Scale().z(), eCSSUnit_Number);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TransformFunction::TTranslation:
|
|
|
|
{
|
|
|
|
arr = nsStyleAnimation::AppendTransformFunction(eCSSKeyword_translate3d, resultTail);
|
|
|
|
arr->Item(1).SetFloatValue(aFunctions[i].get_Translation().x(), eCSSUnit_Pixel);
|
|
|
|
arr->Item(2).SetFloatValue(aFunctions[i].get_Translation().y(), eCSSUnit_Pixel);
|
|
|
|
arr->Item(3).SetFloatValue(aFunctions[i].get_Translation().z(), eCSSUnit_Pixel);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TransformFunction::TSkewX:
|
|
|
|
{
|
|
|
|
float x = aFunctions[i].get_SkewX().x();
|
|
|
|
arr = nsStyleAnimation::AppendTransformFunction(eCSSKeyword_skewx, resultTail);
|
|
|
|
arr->Item(1).SetFloatValue(x, eCSSUnit_Number);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TransformFunction::TSkewY:
|
|
|
|
{
|
|
|
|
float y = aFunctions[i].get_SkewY().y();
|
|
|
|
arr = nsStyleAnimation::AppendTransformFunction(eCSSKeyword_skewy, resultTail);
|
|
|
|
arr->Item(1).SetFloatValue(y, eCSSUnit_Number);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TransformFunction::TTransformMatrix:
|
|
|
|
{
|
|
|
|
arr = nsStyleAnimation::AppendTransformFunction(eCSSKeyword_matrix3d, resultTail);
|
|
|
|
const gfx3DMatrix& matrix = aFunctions[i].get_TransformMatrix().value();
|
|
|
|
arr->Item(1).SetFloatValue(matrix._11, eCSSUnit_Number);
|
|
|
|
arr->Item(2).SetFloatValue(matrix._12, eCSSUnit_Number);
|
|
|
|
arr->Item(3).SetFloatValue(matrix._13, eCSSUnit_Number);
|
|
|
|
arr->Item(4).SetFloatValue(matrix._14, eCSSUnit_Number);
|
|
|
|
arr->Item(5).SetFloatValue(matrix._21, eCSSUnit_Number);
|
|
|
|
arr->Item(6).SetFloatValue(matrix._22, eCSSUnit_Number);
|
|
|
|
arr->Item(7).SetFloatValue(matrix._23, eCSSUnit_Number);
|
|
|
|
arr->Item(8).SetFloatValue(matrix._24, eCSSUnit_Number);
|
|
|
|
arr->Item(9).SetFloatValue(matrix._31, eCSSUnit_Number);
|
|
|
|
arr->Item(10).SetFloatValue(matrix._32, eCSSUnit_Number);
|
|
|
|
arr->Item(11).SetFloatValue(matrix._33, eCSSUnit_Number);
|
|
|
|
arr->Item(12).SetFloatValue(matrix._34, eCSSUnit_Number);
|
|
|
|
arr->Item(13).SetFloatValue(matrix._41, eCSSUnit_Number);
|
|
|
|
arr->Item(14).SetFloatValue(matrix._42, eCSSUnit_Number);
|
|
|
|
arr->Item(15).SetFloatValue(matrix._43, eCSSUnit_Number);
|
|
|
|
arr->Item(16).SetFloatValue(matrix._44, eCSSUnit_Number);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TransformFunction::TPerspective:
|
|
|
|
{
|
|
|
|
float perspective = aFunctions[i].get_Perspective().value();
|
|
|
|
arr = nsStyleAnimation::AppendTransformFunction(eCSSKeyword_perspective, resultTail);
|
|
|
|
arr->Item(1).SetFloatValue(perspective, eCSSUnit_Pixel);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
NS_ASSERTION(false, "All functions should be implemented?");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Layer::SetAnimations(const AnimationArray& aAnimations)
|
|
|
|
{
|
|
|
|
mAnimations = aAnimations;
|
|
|
|
mAnimationData.Clear();
|
|
|
|
for (PRUint32 i = 0; i < mAnimations.Length(); i++) {
|
|
|
|
AnimData data;
|
|
|
|
InfallibleTArray<css::ComputedTimingFunction*>* functions =
|
|
|
|
&data.mFunctions;
|
|
|
|
nsTArray<AnimationSegment> segments = mAnimations.ElementAt(i).segments();
|
|
|
|
for (PRUint32 j = 0; j < segments.Length(); j++) {
|
|
|
|
TimingFunction tf = segments.ElementAt(j).sampleFn();
|
|
|
|
css::ComputedTimingFunction* ctf = new css::ComputedTimingFunction();
|
|
|
|
switch (tf.type()) {
|
|
|
|
case TimingFunction::TCubicBezierFunction: {
|
|
|
|
CubicBezierFunction cbf = tf.get_CubicBezierFunction();
|
|
|
|
ctf->Init(nsTimingFunction(cbf.x1(), cbf.y1(), cbf.x2(), cbf.y2()));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
NS_ASSERTION(tf.type() == TimingFunction::TStepFunction,
|
|
|
|
"Function must be bezier or step");
|
|
|
|
StepFunction sf = tf.get_StepFunction();
|
|
|
|
nsTimingFunction::Type type = sf.type() == 1 ? nsTimingFunction::StepStart
|
|
|
|
: nsTimingFunction::StepEnd;
|
|
|
|
ctf->Init(nsTimingFunction(type, sf.steps()));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
functions->AppendElement(ctf);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Precompute the nsStyleAnimation::Values that we need if this is a transform
|
|
|
|
// animation.
|
|
|
|
InfallibleTArray<nsStyleAnimation::Value>* startValues =
|
|
|
|
&data.mStartValues;
|
|
|
|
InfallibleTArray<nsStyleAnimation::Value>* endValues =
|
|
|
|
&data.mEndValues;
|
|
|
|
for (PRUint32 j = 0; j < mAnimations[i].segments().Length(); j++) {
|
|
|
|
const AnimationSegment& segment = mAnimations[i].segments()[j];
|
|
|
|
if (segment.endState().type() == Animatable::TArrayOfTransformFunction) {
|
|
|
|
const InfallibleTArray<TransformFunction>& startFunctions =
|
|
|
|
segment.startState().get_ArrayOfTransformFunction();
|
|
|
|
nsStyleAnimation::Value startValue;
|
|
|
|
nsCSSValueList* startList;
|
|
|
|
if (startFunctions.Length() > 0) {
|
|
|
|
startList = CreateCSSValueList(startFunctions);
|
|
|
|
} else {
|
|
|
|
startList = new nsCSSValueList();
|
|
|
|
startList->mValue.SetNoneValue();
|
|
|
|
}
|
|
|
|
startValue.SetAndAdoptCSSValueListValue(startList, nsStyleAnimation::eUnit_Transform);
|
|
|
|
startValues->AppendElement(startValue);
|
|
|
|
|
|
|
|
const InfallibleTArray<TransformFunction>& endFunctions =
|
|
|
|
segment.endState().get_ArrayOfTransformFunction();
|
|
|
|
nsStyleAnimation::Value endValue;
|
|
|
|
nsCSSValueList* endList;
|
|
|
|
if (endFunctions.Length() > 0) {
|
|
|
|
endList = CreateCSSValueList(endFunctions);
|
|
|
|
} else {
|
|
|
|
endList = new nsCSSValueList();
|
|
|
|
endList->mValue.SetNoneValue();
|
|
|
|
}
|
|
|
|
endValue.SetAndAdoptCSSValueListValue(endList, nsStyleAnimation::eUnit_Transform);
|
|
|
|
endValues->AppendElement(endValue);
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(segment.endState().type() == Animatable::TOpacity,
|
|
|
|
"Unknown Animatable type");
|
|
|
|
nsStyleAnimation::Value startValue;
|
|
|
|
startValue.SetFloatValue(segment.startState().get_Opacity().value());
|
|
|
|
startValues->AppendElement(startValue);
|
|
|
|
|
|
|
|
nsStyleAnimation::Value endValue;
|
|
|
|
endValue.SetFloatValue(segment.endState().get_Opacity().value());
|
|
|
|
endValues->AppendElement(endValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mAnimationData.AppendElement(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
Mutated();
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2010-07-21 18:06:33 +00:00
|
|
|
Layer::CanUseOpaqueSurface()
|
|
|
|
{
|
|
|
|
// If the visible content in the layer is opaque, there is no need
|
|
|
|
// for an alpha channel.
|
2010-09-02 09:18:40 +00:00
|
|
|
if (GetContentFlags() & CONTENT_OPAQUE)
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-07-21 18:06:33 +00:00
|
|
|
// Also, if this layer is the bottommost layer in a container which
|
|
|
|
// doesn't need an alpha channel, we can use an opaque surface for this
|
|
|
|
// layer too. Any transparent areas must be covered by something else
|
|
|
|
// in the container.
|
|
|
|
ContainerLayer* parent = GetParent();
|
|
|
|
return parent && parent->GetFirstChild() == this &&
|
|
|
|
parent->CanUseOpaqueSurface();
|
|
|
|
}
|
|
|
|
|
2010-10-13 22:55:45 +00:00
|
|
|
// NB: eventually these methods will be defined unconditionally, and
|
|
|
|
// can be moved into Layers.h
|
|
|
|
const nsIntRect*
|
|
|
|
Layer::GetEffectiveClipRect()
|
|
|
|
{
|
|
|
|
if (ShadowLayer* shadow = AsShadowLayer()) {
|
|
|
|
return shadow->GetShadowClipRect();
|
|
|
|
}
|
|
|
|
return GetClipRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsIntRegion&
|
|
|
|
Layer::GetEffectiveVisibleRegion()
|
|
|
|
{
|
|
|
|
if (ShadowLayer* shadow = AsShadowLayer()) {
|
|
|
|
return shadow->GetShadowVisibleRegion();
|
|
|
|
}
|
|
|
|
return GetVisibleRegion();
|
|
|
|
}
|
|
|
|
|
2010-11-08 09:06:15 +00:00
|
|
|
gfx3DMatrix
|
|
|
|
Layer::SnapTransform(const gfx3DMatrix& aTransform,
|
|
|
|
const gfxRect& aSnapRect,
|
|
|
|
gfxMatrix* aResidualTransform)
|
|
|
|
{
|
|
|
|
if (aResidualTransform) {
|
|
|
|
*aResidualTransform = gfxMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxMatrix matrix2D;
|
|
|
|
gfx3DMatrix result;
|
|
|
|
if (mManager->IsSnappingEffectiveTransforms() &&
|
|
|
|
aTransform.Is2D(&matrix2D) &&
|
|
|
|
matrix2D.HasNonIntegerTranslation() &&
|
|
|
|
!matrix2D.IsSingular() &&
|
|
|
|
!matrix2D.HasNonAxisAlignedTransform()) {
|
|
|
|
gfxMatrix snappedMatrix;
|
|
|
|
gfxPoint topLeft = matrix2D.Transform(aSnapRect.TopLeft());
|
|
|
|
topLeft.Round();
|
|
|
|
// first compute scale factors that scale aSnapRect to the snapped rect
|
|
|
|
if (aSnapRect.IsEmpty()) {
|
|
|
|
snappedMatrix.xx = matrix2D.xx;
|
|
|
|
snappedMatrix.yy = matrix2D.yy;
|
|
|
|
} else {
|
|
|
|
gfxPoint bottomRight = matrix2D.Transform(aSnapRect.BottomRight());
|
|
|
|
bottomRight.Round();
|
|
|
|
snappedMatrix.xx = (bottomRight.x - topLeft.x)/aSnapRect.Width();
|
|
|
|
snappedMatrix.yy = (bottomRight.y - topLeft.y)/aSnapRect.Height();
|
|
|
|
}
|
|
|
|
// compute translation factors that will move aSnapRect to the snapped rect
|
|
|
|
// given those scale factors
|
2011-04-19 03:07:21 +00:00
|
|
|
snappedMatrix.x0 = topLeft.x - aSnapRect.X()*snappedMatrix.xx;
|
|
|
|
snappedMatrix.y0 = topLeft.y - aSnapRect.Y()*snappedMatrix.yy;
|
2010-11-08 09:06:15 +00:00
|
|
|
result = gfx3DMatrix::From2D(snappedMatrix);
|
|
|
|
if (aResidualTransform && !snappedMatrix.IsSingular()) {
|
|
|
|
// set aResidualTransform so that aResidual * snappedMatrix == matrix2D.
|
|
|
|
// (i.e., appying snappedMatrix after aResidualTransform gives the
|
|
|
|
// ideal transform.
|
|
|
|
gfxMatrix snappedMatrixInverse = snappedMatrix;
|
|
|
|
snappedMatrixInverse.Invert();
|
|
|
|
*aResidualTransform = matrix2D * snappedMatrixInverse;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = aTransform;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-07-31 17:28:20 +00:00
|
|
|
nsIntRect
|
2011-05-23 00:27:03 +00:00
|
|
|
Layer::CalculateScissorRect(const nsIntRect& aCurrentScissorRect,
|
|
|
|
const gfxMatrix* aWorldTransform)
|
2011-02-25 07:44:22 +00:00
|
|
|
{
|
2011-05-23 00:27:03 +00:00
|
|
|
ContainerLayer* container = GetParent();
|
|
|
|
NS_ASSERTION(container, "This can't be called on the root!");
|
|
|
|
|
|
|
|
// Establish initial clip rect: it's either the one passed in, or
|
|
|
|
// if the parent has an intermediate surface, it's the extents of that surface.
|
|
|
|
nsIntRect currentClip;
|
|
|
|
if (container->UseIntermediateSurface()) {
|
|
|
|
currentClip.SizeTo(container->GetIntermediateSurfaceRect().Size());
|
|
|
|
} else {
|
|
|
|
currentClip = aCurrentScissorRect;
|
|
|
|
}
|
2011-02-25 07:44:22 +00:00
|
|
|
|
|
|
|
const nsIntRect *clipRect = GetEffectiveClipRect();
|
2011-05-23 00:27:03 +00:00
|
|
|
if (!clipRect)
|
|
|
|
return currentClip;
|
2011-02-25 07:44:22 +00:00
|
|
|
|
2011-05-23 00:27:03 +00:00
|
|
|
if (clipRect->IsEmpty()) {
|
|
|
|
// We might have a non-translation transform in the container so we can't
|
|
|
|
// use the code path below.
|
|
|
|
return nsIntRect(currentClip.TopLeft(), nsIntSize(0, 0));
|
2011-02-25 07:44:22 +00:00
|
|
|
}
|
|
|
|
|
2011-05-23 00:27:03 +00:00
|
|
|
nsIntRect scissor = *clipRect;
|
|
|
|
if (!container->UseIntermediateSurface()) {
|
|
|
|
gfxMatrix matrix;
|
|
|
|
DebugOnly<bool> is2D = container->GetEffectiveTransform().Is2D(&matrix);
|
|
|
|
// See DefaultComputeEffectiveTransforms below
|
2011-06-16 10:51:05 +00:00
|
|
|
NS_ASSERTION(is2D && matrix.PreservesAxisAlignedRectangles(),
|
|
|
|
"Non preserves axis aligned transform with clipped child should have forced intermediate surface");
|
|
|
|
gfxRect r(scissor.x, scissor.y, scissor.width, scissor.height);
|
|
|
|
gfxRect trScissor = matrix.TransformBounds(r);
|
|
|
|
trScissor.Round();
|
|
|
|
if (!gfxUtils::GfxRectToIntRect(trScissor, &scissor)) {
|
|
|
|
return nsIntRect(currentClip.TopLeft(), nsIntSize(0, 0));
|
|
|
|
}
|
2011-05-23 00:27:03 +00:00
|
|
|
|
|
|
|
// Find the nearest ancestor with an intermediate surface
|
|
|
|
do {
|
|
|
|
container = container->GetParent();
|
|
|
|
} while (container && !container->UseIntermediateSurface());
|
2011-02-25 07:44:22 +00:00
|
|
|
}
|
2011-05-23 00:27:03 +00:00
|
|
|
if (container) {
|
|
|
|
scissor.MoveBy(-container->GetIntermediateSurfaceRect().TopLeft());
|
|
|
|
} else if (aWorldTransform) {
|
|
|
|
gfxRect r(scissor.x, scissor.y, scissor.width, scissor.height);
|
|
|
|
gfxRect trScissor = aWorldTransform->TransformBounds(r);
|
|
|
|
trScissor.Round();
|
|
|
|
if (!gfxUtils::GfxRectToIntRect(trScissor, &scissor))
|
|
|
|
return nsIntRect(currentClip.TopLeft(), nsIntSize(0, 0));
|
2011-02-25 07:44:22 +00:00
|
|
|
}
|
2011-05-23 00:27:03 +00:00
|
|
|
return currentClip.Intersect(scissor);
|
2011-02-25 07:44:22 +00:00
|
|
|
}
|
|
|
|
|
2012-07-31 02:20:00 +00:00
|
|
|
const gfx3DMatrix
|
|
|
|
Layer::GetTransform()
|
|
|
|
{
|
|
|
|
gfx3DMatrix transform = mTransform;
|
|
|
|
transform.Scale(mXScale, mYScale, 1);
|
|
|
|
return transform;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gfx3DMatrix
|
2010-11-08 09:06:15 +00:00
|
|
|
Layer::GetLocalTransform()
|
2010-10-13 22:55:45 +00:00
|
|
|
{
|
2012-07-31 02:20:00 +00:00
|
|
|
gfx3DMatrix transform;
|
2010-11-08 09:06:15 +00:00
|
|
|
if (ShadowLayer* shadow = AsShadowLayer())
|
2012-07-31 02:20:00 +00:00
|
|
|
transform = shadow->GetShadowTransform();
|
|
|
|
else
|
|
|
|
transform = mTransform;
|
|
|
|
transform.Scale(mXScale, mYScale, 1);
|
|
|
|
return transform;
|
2010-11-08 09:06:15 +00:00
|
|
|
}
|
|
|
|
|
2012-07-31 17:28:20 +00:00
|
|
|
const float
|
|
|
|
Layer::GetLocalOpacity()
|
|
|
|
{
|
|
|
|
if (ShadowLayer* shadow = AsShadowLayer())
|
|
|
|
return shadow->GetShadowOpacity();
|
|
|
|
return mOpacity;
|
|
|
|
}
|
|
|
|
|
2010-11-08 09:06:15 +00:00
|
|
|
float
|
|
|
|
Layer::GetEffectiveOpacity()
|
|
|
|
{
|
2012-07-31 17:28:20 +00:00
|
|
|
float opacity = GetLocalOpacity();
|
2010-11-08 09:06:15 +00:00
|
|
|
for (ContainerLayer* c = GetParent(); c && !c->UseIntermediateSurface();
|
|
|
|
c = c->GetParent()) {
|
2012-07-31 17:28:20 +00:00
|
|
|
opacity *= c->GetLocalOpacity();
|
2010-10-13 22:55:45 +00:00
|
|
|
}
|
2010-11-08 09:06:15 +00:00
|
|
|
return opacity;
|
2010-10-13 22:55:45 +00:00
|
|
|
}
|
|
|
|
|
2012-02-07 22:27:44 +00:00
|
|
|
void
|
|
|
|
Layer::ComputeEffectiveTransformForMaskLayer(const gfx3DMatrix& aTransformToSurface)
|
|
|
|
{
|
|
|
|
if (mMaskLayer) {
|
2012-07-25 08:48:09 +00:00
|
|
|
mMaskLayer->mEffectiveTransform = aTransformToSurface;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
gfxMatrix maskTranslation;
|
|
|
|
bool maskIs2D = mMaskLayer->GetTransform().CanDraw2D(&maskTranslation);
|
|
|
|
NS_ASSERTION(maskIs2D, "How did we end up with a 3D transform here?!");
|
|
|
|
#endif
|
|
|
|
mMaskLayer->mEffectiveTransform.PreMultiply(mMaskLayer->GetTransform());
|
2012-02-07 22:27:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-09 19:38:26 +00:00
|
|
|
void
|
|
|
|
ContainerLayer::FillSpecificAttributes(SpecificLayerAttributes& aAttrs)
|
|
|
|
{
|
|
|
|
aAttrs = ContainerLayerAttributes(GetFrameMetrics());
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2010-11-08 09:06:15 +00:00
|
|
|
ContainerLayer::HasMultipleChildren()
|
|
|
|
{
|
|
|
|
PRUint32 count = 0;
|
|
|
|
for (Layer* child = GetFirstChild(); child; child = child->GetNextSibling()) {
|
|
|
|
const nsIntRect *clipRect = child->GetEffectiveClipRect();
|
|
|
|
if (clipRect && clipRect->IsEmpty())
|
|
|
|
continue;
|
|
|
|
if (child->GetVisibleRegion().IsEmpty())
|
|
|
|
continue;
|
|
|
|
++count;
|
|
|
|
if (count > 1)
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-11-08 09:06:15 +00:00
|
|
|
}
|
2010-10-13 22:55:45 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-11-08 09:06:15 +00:00
|
|
|
}
|
2010-10-13 22:55:45 +00:00
|
|
|
|
2011-10-06 21:23:18 +00:00
|
|
|
void
|
|
|
|
ContainerLayer::SortChildrenBy3DZOrder(nsTArray<Layer*>& aArray)
|
|
|
|
{
|
|
|
|
nsAutoTArray<Layer*, 10> toSort;
|
|
|
|
|
|
|
|
for (Layer* l = GetFirstChild(); l; l = l->GetNextSibling()) {
|
|
|
|
ContainerLayer* container = l->AsContainerLayer();
|
|
|
|
if (container && container->GetContentFlags() & CONTENT_PRESERVE_3D) {
|
|
|
|
toSort.AppendElement(l);
|
|
|
|
} else {
|
|
|
|
if (toSort.Length() > 0) {
|
|
|
|
SortLayersBy3DZOrder(toSort);
|
|
|
|
aArray.MoveElementsFrom(toSort);
|
|
|
|
}
|
|
|
|
aArray.AppendElement(l);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (toSort.Length() > 0) {
|
|
|
|
SortLayersBy3DZOrder(toSort);
|
|
|
|
aArray.MoveElementsFrom(toSort);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-08 09:06:15 +00:00
|
|
|
void
|
|
|
|
ContainerLayer::DefaultComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface)
|
|
|
|
{
|
|
|
|
gfxMatrix residual;
|
|
|
|
gfx3DMatrix idealTransform = GetLocalTransform()*aTransformToSurface;
|
2011-10-06 21:29:07 +00:00
|
|
|
idealTransform.ProjectTo2D();
|
2010-11-08 09:06:15 +00:00
|
|
|
mEffectiveTransform = SnapTransform(idealTransform, gfxRect(0, 0, 0, 0), &residual);
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool useIntermediateSurface;
|
2012-02-07 22:27:44 +00:00
|
|
|
if (GetMaskLayer()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
useIntermediateSurface = true;
|
2012-03-01 08:26:09 +00:00
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
|
|
|
} else if (gfxUtils::sDumpPainting) {
|
|
|
|
useIntermediateSurface = true;
|
|
|
|
#endif
|
2010-11-08 09:06:15 +00:00
|
|
|
} else {
|
2012-02-07 22:27:44 +00:00
|
|
|
float opacity = GetEffectiveOpacity();
|
|
|
|
if (opacity != 1.0f && HasMultipleChildren()) {
|
|
|
|
useIntermediateSurface = true;
|
|
|
|
} else {
|
|
|
|
useIntermediateSurface = false;
|
|
|
|
gfxMatrix contTransform;
|
|
|
|
if (!mEffectiveTransform.Is2D(&contTransform) ||
|
2011-06-16 10:51:05 +00:00
|
|
|
#ifdef MOZ_GFX_OPTIMIZE_MOBILE
|
|
|
|
!contTransform.PreservesAxisAlignedRectangles()) {
|
|
|
|
#else
|
2011-05-23 00:27:03 +00:00
|
|
|
contTransform.HasNonIntegerTranslation()) {
|
2011-06-16 10:51:05 +00:00
|
|
|
#endif
|
2012-02-07 22:27:44 +00:00
|
|
|
for (Layer* child = GetFirstChild(); child; child = child->GetNextSibling()) {
|
|
|
|
const nsIntRect *clipRect = child->GetEffectiveClipRect();
|
|
|
|
/* We can't (easily) forward our transform to children with a non-empty clip
|
|
|
|
* rect since it would need to be adjusted for the transform. See
|
|
|
|
* the calculations performed by CalculateScissorRect above.
|
2012-06-26 20:06:32 +00:00
|
|
|
* Nor for a child with a mask layer.
|
2012-02-07 22:27:44 +00:00
|
|
|
*/
|
2012-06-26 20:06:32 +00:00
|
|
|
if ((clipRect && !clipRect->IsEmpty() && !child->GetVisibleRegion().IsEmpty()) ||
|
|
|
|
child->GetMaskLayer()) {
|
2012-02-07 22:27:44 +00:00
|
|
|
useIntermediateSurface = true;
|
|
|
|
break;
|
|
|
|
}
|
2010-11-08 09:06:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mUseIntermediateSurface = useIntermediateSurface;
|
|
|
|
if (useIntermediateSurface) {
|
|
|
|
ComputeEffectiveTransformsForChildren(gfx3DMatrix::From2D(residual));
|
|
|
|
} else {
|
|
|
|
ComputeEffectiveTransformsForChildren(idealTransform);
|
|
|
|
}
|
2012-02-07 22:27:44 +00:00
|
|
|
|
|
|
|
if (idealTransform.CanDraw2D()) {
|
|
|
|
ComputeEffectiveTransformForMaskLayer(aTransformToSurface);
|
|
|
|
} else {
|
|
|
|
ComputeEffectiveTransformForMaskLayer(gfx3DMatrix());
|
|
|
|
}
|
2010-11-08 09:06:15 +00:00
|
|
|
}
|
2010-10-13 22:55:45 +00:00
|
|
|
|
2010-11-08 09:06:15 +00:00
|
|
|
void
|
|
|
|
ContainerLayer::ComputeEffectiveTransformsForChildren(const gfx3DMatrix& aTransformToSurface)
|
|
|
|
{
|
|
|
|
for (Layer* l = mFirstChild; l; l = l->GetNextSibling()) {
|
|
|
|
l->ComputeEffectiveTransforms(aTransformToSurface);
|
|
|
|
}
|
|
|
|
}
|
2010-10-13 22:55:45 +00:00
|
|
|
|
2011-02-16 22:43:30 +00:00
|
|
|
void
|
|
|
|
ContainerLayer::DidRemoveChild(Layer* aLayer)
|
|
|
|
{
|
|
|
|
ThebesLayer* tl = aLayer->AsThebesLayer();
|
|
|
|
if (tl && tl->UsedForReadback()) {
|
|
|
|
for (Layer* l = mFirstChild; l; l = l->GetNextSibling()) {
|
|
|
|
if (l->GetType() == TYPE_READBACK) {
|
|
|
|
static_cast<ReadbackLayer*>(l)->NotifyThebesLayerRemoved(tl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (aLayer->GetType() == TYPE_READBACK) {
|
|
|
|
static_cast<ReadbackLayer*>(aLayer)->NotifyRemoved();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ContainerLayer::DidInsertChild(Layer* aLayer)
|
|
|
|
{
|
|
|
|
if (aLayer->GetType() == TYPE_READBACK) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mMayHaveReadbackChild = true;
|
2011-02-16 22:43:30 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-17 23:59:45 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
RefLayer::FillSpecificAttributes(SpecificLayerAttributes& aAttrs)
|
|
|
|
{
|
|
|
|
aAttrs = RefLayerAttributes(GetReferentId());
|
|
|
|
}
|
|
|
|
|
2012-01-05 22:40:35 +00:00
|
|
|
void
|
|
|
|
LayerManager::StartFrameTimeRecording()
|
|
|
|
{
|
|
|
|
mLastFrameTime = TimeStamp::Now();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LayerManager::PostPresent()
|
|
|
|
{
|
|
|
|
if (!mLastFrameTime.IsNull()) {
|
|
|
|
TimeStamp now = TimeStamp::Now();
|
|
|
|
mFrameTimes.AppendElement((now - mLastFrameTime).ToMilliseconds());
|
|
|
|
mLastFrameTime = now;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<float>
|
|
|
|
LayerManager::StopFrameTimeRecording()
|
|
|
|
{
|
|
|
|
mLastFrameTime = TimeStamp();
|
|
|
|
nsTArray<float> result = mFrameTimes;
|
|
|
|
mFrameTimes.Clear();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-07-05 02:52:00 +00:00
|
|
|
|
|
|
|
|
2010-07-21 18:06:33 +00:00
|
|
|
#ifdef MOZ_LAYERS_HAVE_LOG
|
|
|
|
|
2010-10-13 22:55:45 +00:00
|
|
|
static nsACString& PrintInfo(nsACString& aTo, ShadowLayer* aShadowLayer);
|
|
|
|
|
2012-03-01 08:26:09 +00:00
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
|
|
|
template <typename T>
|
|
|
|
void WriteSnapshotLinkToDumpFile(T* aObj, FILE* aFile)
|
|
|
|
{
|
|
|
|
nsCString string(aObj->Name());
|
|
|
|
string.Append("-");
|
|
|
|
string.AppendInt((PRUint64)aObj);
|
|
|
|
fprintf(aFile, "href=\"javascript:ViewImage('%s')\"", string.BeginReading());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void WriteSnapshotToDumpFile_internal(T* aObj, gfxASurface* aSurf)
|
|
|
|
{
|
|
|
|
nsCString string(aObj->Name());
|
|
|
|
string.Append("-");
|
|
|
|
string.AppendInt((PRUint64)aObj);
|
2012-03-28 18:10:22 +00:00
|
|
|
if (gfxUtils::sDumpPaintFile)
|
|
|
|
fprintf(gfxUtils::sDumpPaintFile, "array[\"%s\"]=\"", string.BeginReading());
|
2012-03-01 08:26:09 +00:00
|
|
|
aSurf->DumpAsDataURL(gfxUtils::sDumpPaintFile);
|
2012-03-28 18:10:22 +00:00
|
|
|
if (gfxUtils::sDumpPaintFile)
|
|
|
|
fprintf(gfxUtils::sDumpPaintFile, "\";");
|
2012-03-01 08:26:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WriteSnapshotToDumpFile(Layer* aLayer, gfxASurface* aSurf)
|
|
|
|
{
|
|
|
|
WriteSnapshotToDumpFile_internal(aLayer, aSurf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WriteSnapshotToDumpFile(LayerManager* aManager, gfxASurface* aSurf)
|
|
|
|
{
|
|
|
|
WriteSnapshotToDumpFile_internal(aManager, aSurf);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-07-21 18:06:33 +00:00
|
|
|
void
|
|
|
|
Layer::Dump(FILE* aFile, const char* aPrefix)
|
|
|
|
{
|
2012-03-01 08:26:09 +00:00
|
|
|
fprintf(aFile, "<li><a id=\"%p\" ", this);
|
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
|
|
|
if (GetType() == TYPE_CONTAINER || GetType() == TYPE_THEBES) {
|
|
|
|
WriteSnapshotLinkToDumpFile(this, aFile);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
fprintf(aFile, ">");
|
2010-07-21 18:06:33 +00:00
|
|
|
DumpSelf(aFile, aPrefix);
|
2012-03-01 08:26:09 +00:00
|
|
|
fprintf(aFile, "</a>");
|
2010-07-21 18:06:33 +00:00
|
|
|
|
2012-01-18 01:35:49 +00:00
|
|
|
if (Layer* mask = GetMaskLayer()) {
|
|
|
|
nsCAutoString pfx(aPrefix);
|
|
|
|
pfx += " Mask layer: ";
|
|
|
|
mask->Dump(aFile, pfx.get());
|
|
|
|
}
|
|
|
|
|
2010-07-21 18:06:33 +00:00
|
|
|
if (Layer* kid = GetFirstChild()) {
|
|
|
|
nsCAutoString pfx(aPrefix);
|
|
|
|
pfx += " ";
|
2012-03-01 08:26:09 +00:00
|
|
|
fprintf(aFile, "<ul>");
|
2010-07-21 18:06:33 +00:00
|
|
|
kid->Dump(aFile, pfx.get());
|
2012-03-01 08:26:09 +00:00
|
|
|
fprintf(aFile, "</ul>");
|
2010-07-21 18:06:33 +00:00
|
|
|
}
|
|
|
|
|
2012-03-01 08:26:09 +00:00
|
|
|
fprintf(aFile, "</li>");
|
2010-07-21 18:06:33 +00:00
|
|
|
if (Layer* next = GetNextSibling())
|
|
|
|
next->Dump(aFile, aPrefix);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Layer::DumpSelf(FILE* aFile, const char* aPrefix)
|
|
|
|
{
|
|
|
|
nsCAutoString str;
|
|
|
|
PrintInfo(str, aPrefix);
|
|
|
|
fprintf(FILEOrDefault(aFile), "%s\n", str.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Layer::Log(const char* aPrefix)
|
|
|
|
{
|
|
|
|
if (!IsLogEnabled())
|
|
|
|
return;
|
|
|
|
|
|
|
|
LogSelf(aPrefix);
|
|
|
|
|
|
|
|
if (Layer* kid = GetFirstChild()) {
|
|
|
|
nsCAutoString pfx(aPrefix);
|
|
|
|
pfx += " ";
|
|
|
|
kid->Log(pfx.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Layer* next = GetNextSibling())
|
|
|
|
next->Log(aPrefix);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Layer::LogSelf(const char* aPrefix)
|
|
|
|
{
|
|
|
|
if (!IsLogEnabled())
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCAutoString str;
|
|
|
|
PrintInfo(str, aPrefix);
|
|
|
|
MOZ_LAYERS_LOG(("%s", str.get()));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsACString&
|
|
|
|
Layer::PrintInfo(nsACString& aTo, const char* aPrefix)
|
|
|
|
{
|
|
|
|
aTo += aPrefix;
|
2012-04-24 18:43:00 +00:00
|
|
|
aTo += nsPrintfCString("%s%s (0x%p)", mManager->Name(), Name(), this);
|
2010-07-21 18:06:33 +00:00
|
|
|
|
2010-10-13 22:55:45 +00:00
|
|
|
::PrintInfo(aTo, AsShadowLayer());
|
|
|
|
|
2010-08-02 03:06:58 +00:00
|
|
|
if (mUseClipRect) {
|
|
|
|
AppendToString(aTo, mClipRect, " [clip=", "]");
|
|
|
|
}
|
2010-09-02 09:18:40 +00:00
|
|
|
if (!mTransform.IsIdentity()) {
|
2010-07-21 18:06:33 +00:00
|
|
|
AppendToString(aTo, mTransform, " [transform=", "]");
|
2010-09-02 09:18:40 +00:00
|
|
|
}
|
|
|
|
if (!mVisibleRegion.IsEmpty()) {
|
2010-08-02 03:06:58 +00:00
|
|
|
AppendToString(aTo, mVisibleRegion, " [visible=", "]");
|
2010-09-02 09:18:40 +00:00
|
|
|
}
|
|
|
|
if (1.0 != mOpacity) {
|
2010-07-21 18:06:33 +00:00
|
|
|
aTo.AppendPrintf(" [opacity=%g]", mOpacity);
|
2010-09-02 09:18:40 +00:00
|
|
|
}
|
|
|
|
if (GetContentFlags() & CONTENT_OPAQUE) {
|
2010-07-21 18:06:33 +00:00
|
|
|
aTo += " [opaqueContent]";
|
2010-09-02 09:18:40 +00:00
|
|
|
}
|
2010-12-20 01:26:14 +00:00
|
|
|
if (GetContentFlags() & CONTENT_COMPONENT_ALPHA) {
|
|
|
|
aTo += " [componentAlpha]";
|
2010-09-02 09:18:40 +00:00
|
|
|
}
|
2011-04-06 05:00:25 +00:00
|
|
|
if (GetIsFixedPosition()) {
|
|
|
|
aTo += " [isFixedPosition]";
|
|
|
|
}
|
2010-07-21 18:06:33 +00:00
|
|
|
|
|
|
|
return aTo;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsACString&
|
|
|
|
ThebesLayer::PrintInfo(nsACString& aTo, const char* aPrefix)
|
|
|
|
{
|
|
|
|
Layer::PrintInfo(aTo, aPrefix);
|
2010-10-13 22:55:45 +00:00
|
|
|
if (!mValidRegion.IsEmpty()) {
|
|
|
|
AppendToString(aTo, mValidRegion, " [valid=", "]");
|
|
|
|
}
|
|
|
|
return aTo;
|
2010-07-21 18:06:33 +00:00
|
|
|
}
|
|
|
|
|
2010-09-03 20:10:45 +00:00
|
|
|
nsACString&
|
|
|
|
ContainerLayer::PrintInfo(nsACString& aTo, const char* aPrefix)
|
|
|
|
{
|
|
|
|
Layer::PrintInfo(aTo, aPrefix);
|
2011-01-08 05:05:35 +00:00
|
|
|
if (!mFrameMetrics.IsDefault()) {
|
|
|
|
AppendToString(aTo, mFrameMetrics, " [metrics=", "]");
|
|
|
|
}
|
|
|
|
if (UseIntermediateSurface()) {
|
|
|
|
aTo += " [usesTmpSurf]";
|
|
|
|
}
|
|
|
|
return aTo;
|
2010-09-03 20:10:45 +00:00
|
|
|
}
|
|
|
|
|
2010-07-21 18:06:33 +00:00
|
|
|
nsACString&
|
|
|
|
ColorLayer::PrintInfo(nsACString& aTo, const char* aPrefix)
|
|
|
|
{
|
|
|
|
Layer::PrintInfo(aTo, aPrefix);
|
|
|
|
AppendToString(aTo, mColor, " [color=", "]");
|
|
|
|
return aTo;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsACString&
|
|
|
|
CanvasLayer::PrintInfo(nsACString& aTo, const char* aPrefix)
|
|
|
|
{
|
|
|
|
Layer::PrintInfo(aTo, aPrefix);
|
2010-08-02 03:06:58 +00:00
|
|
|
if (mFilter != gfxPattern::FILTER_GOOD) {
|
|
|
|
AppendToString(aTo, mFilter, " [filter=", "]");
|
|
|
|
}
|
2010-07-21 18:06:33 +00:00
|
|
|
return aTo;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsACString&
|
|
|
|
ImageLayer::PrintInfo(nsACString& aTo, const char* aPrefix)
|
|
|
|
{
|
|
|
|
Layer::PrintInfo(aTo, aPrefix);
|
2010-08-02 03:06:58 +00:00
|
|
|
if (mFilter != gfxPattern::FILTER_GOOD) {
|
|
|
|
AppendToString(aTo, mFilter, " [filter=", "]");
|
|
|
|
}
|
2010-07-21 18:06:33 +00:00
|
|
|
return aTo;
|
|
|
|
}
|
|
|
|
|
2012-07-17 23:59:45 +00:00
|
|
|
nsACString&
|
|
|
|
RefLayer::PrintInfo(nsACString& aTo, const char* aPrefix)
|
|
|
|
{
|
|
|
|
ContainerLayer::PrintInfo(aTo, aPrefix);
|
|
|
|
if (-1 != mId) {
|
|
|
|
AppendToString(aTo, mId, " [id=", "]");
|
|
|
|
}
|
|
|
|
return aTo;
|
|
|
|
}
|
|
|
|
|
2011-02-16 22:43:30 +00:00
|
|
|
nsACString&
|
|
|
|
ReadbackLayer::PrintInfo(nsACString& aTo, const char* aPrefix)
|
|
|
|
{
|
|
|
|
Layer::PrintInfo(aTo, aPrefix);
|
|
|
|
AppendToString(aTo, mSize, " [size=", "]");
|
|
|
|
if (mBackgroundLayer) {
|
|
|
|
AppendToString(aTo, mBackgroundLayer, " [backgroundLayer=", "]");
|
|
|
|
AppendToString(aTo, mBackgroundLayerOffset, " [backgroundOffset=", "]");
|
|
|
|
} else if (mBackgroundColor.a == 1.0) {
|
|
|
|
AppendToString(aTo, mBackgroundColor, " [backgroundColor=", "]");
|
|
|
|
} else {
|
|
|
|
aTo += " [nobackground]";
|
|
|
|
}
|
|
|
|
return aTo;
|
|
|
|
}
|
|
|
|
|
2010-07-21 18:06:33 +00:00
|
|
|
//--------------------------------------------------
|
|
|
|
// LayerManager
|
|
|
|
|
|
|
|
void
|
|
|
|
LayerManager::Dump(FILE* aFile, const char* aPrefix)
|
|
|
|
{
|
|
|
|
FILE* file = FILEOrDefault(aFile);
|
2012-07-31 17:28:20 +00:00
|
|
|
|
2012-03-01 08:26:09 +00:00
|
|
|
fprintf(file, "<ul><li><a ");
|
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
2012-06-28 15:23:40 +00:00
|
|
|
WriteSnapshotLinkToDumpFile(this, file);
|
2012-03-01 08:26:09 +00:00
|
|
|
#endif
|
|
|
|
fprintf(file, ">");
|
2010-07-21 18:06:33 +00:00
|
|
|
DumpSelf(file, aPrefix);
|
2012-03-01 08:26:09 +00:00
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
2012-06-28 15:23:40 +00:00
|
|
|
fprintf(file, "</a>");
|
2012-03-01 08:26:09 +00:00
|
|
|
#endif
|
2010-07-21 18:06:33 +00:00
|
|
|
|
|
|
|
nsCAutoString pfx(aPrefix);
|
|
|
|
pfx += " ";
|
2010-09-03 03:50:29 +00:00
|
|
|
if (!GetRoot()) {
|
2012-03-01 08:26:09 +00:00
|
|
|
fprintf(file, "%s(null)</li></ul>", pfx.get());
|
2010-07-21 18:06:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-07-31 17:28:20 +00:00
|
|
|
|
2012-03-01 08:26:09 +00:00
|
|
|
fprintf(file, "<ul>");
|
2010-09-03 03:50:29 +00:00
|
|
|
GetRoot()->Dump(file, pfx.get());
|
2012-03-01 08:26:09 +00:00
|
|
|
fprintf(file, "</ul></li></ul>");
|
2010-07-21 18:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LayerManager::DumpSelf(FILE* aFile, const char* aPrefix)
|
|
|
|
{
|
|
|
|
nsCAutoString str;
|
|
|
|
PrintInfo(str, aPrefix);
|
|
|
|
fprintf(FILEOrDefault(aFile), "%s\n", str.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LayerManager::Log(const char* aPrefix)
|
|
|
|
{
|
|
|
|
if (!IsLogEnabled())
|
|
|
|
return;
|
|
|
|
|
|
|
|
LogSelf(aPrefix);
|
|
|
|
|
|
|
|
nsCAutoString pfx(aPrefix);
|
|
|
|
pfx += " ";
|
2010-09-03 03:50:29 +00:00
|
|
|
if (!GetRoot()) {
|
2010-07-21 18:06:33 +00:00
|
|
|
MOZ_LAYERS_LOG(("%s(null)", pfx.get()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-03 03:50:29 +00:00
|
|
|
GetRoot()->Log(pfx.get());
|
2010-07-21 18:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LayerManager::LogSelf(const char* aPrefix)
|
|
|
|
{
|
|
|
|
nsCAutoString str;
|
|
|
|
PrintInfo(str, aPrefix);
|
|
|
|
MOZ_LAYERS_LOG(("%s", str.get()));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsACString&
|
|
|
|
LayerManager::PrintInfo(nsACString& aTo, const char* aPrefix)
|
|
|
|
{
|
|
|
|
aTo += aPrefix;
|
2012-04-24 18:43:00 +00:00
|
|
|
return aTo += nsPrintfCString("%sLayerManager (0x%p)", Name(), this);
|
2010-07-21 18:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void
|
|
|
|
LayerManager::InitLog()
|
|
|
|
{
|
|
|
|
if (!sLog)
|
|
|
|
sLog = PR_NewLogModule("Layers");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ bool
|
|
|
|
LayerManager::IsLogEnabled()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(!!sLog,
|
|
|
|
"layer manager must be created before logging is allowed");
|
|
|
|
return PR_LOG_TEST(sLog, PR_LOG_DEBUG);
|
|
|
|
}
|
|
|
|
|
2010-10-13 22:55:45 +00:00
|
|
|
static nsACString&
|
|
|
|
PrintInfo(nsACString& aTo, ShadowLayer* aShadowLayer)
|
|
|
|
{
|
|
|
|
if (!aShadowLayer) {
|
|
|
|
return aTo;
|
|
|
|
}
|
|
|
|
if (const nsIntRect* clipRect = aShadowLayer->GetShadowClipRect()) {
|
|
|
|
AppendToString(aTo, *clipRect, " [shadow-clip=", "]");
|
|
|
|
}
|
|
|
|
if (!aShadowLayer->GetShadowTransform().IsIdentity()) {
|
|
|
|
AppendToString(aTo, aShadowLayer->GetShadowTransform(), " [shadow-transform=", "]");
|
|
|
|
}
|
|
|
|
if (!aShadowLayer->GetShadowVisibleRegion().IsEmpty()) {
|
|
|
|
AppendToString(aTo, aShadowLayer->GetShadowVisibleRegion(), " [shadow-visible=", "]");
|
|
|
|
}
|
|
|
|
return aTo;
|
|
|
|
}
|
|
|
|
|
2010-07-21 18:06:33 +00:00
|
|
|
#else // !MOZ_LAYERS_HAVE_LOG
|
|
|
|
|
|
|
|
void Layer::Dump(FILE* aFile, const char* aPrefix) {}
|
|
|
|
void Layer::DumpSelf(FILE* aFile, const char* aPrefix) {}
|
|
|
|
void Layer::Log(const char* aPrefix) {}
|
|
|
|
void Layer::LogSelf(const char* aPrefix) {}
|
|
|
|
nsACString&
|
|
|
|
Layer::PrintInfo(nsACString& aTo, const char* aPrefix)
|
|
|
|
{ return aTo; }
|
|
|
|
|
|
|
|
nsACString&
|
|
|
|
ThebesLayer::PrintInfo(nsACString& aTo, const char* aPrefix)
|
|
|
|
{ return aTo; }
|
|
|
|
|
2010-09-03 20:10:45 +00:00
|
|
|
nsACString&
|
|
|
|
ContainerLayer::PrintInfo(nsACString& aTo, const char* aPrefix)
|
|
|
|
{ return aTo; }
|
|
|
|
|
2010-07-21 18:06:33 +00:00
|
|
|
nsACString&
|
|
|
|
ColorLayer::PrintInfo(nsACString& aTo, const char* aPrefix)
|
|
|
|
{ return aTo; }
|
|
|
|
|
|
|
|
nsACString&
|
|
|
|
CanvasLayer::PrintInfo(nsACString& aTo, const char* aPrefix)
|
|
|
|
{ return aTo; }
|
|
|
|
|
|
|
|
nsACString&
|
|
|
|
ImageLayer::PrintInfo(nsACString& aTo, const char* aPrefix)
|
|
|
|
{ return aTo; }
|
|
|
|
|
2012-07-17 23:59:45 +00:00
|
|
|
nsACString&
|
|
|
|
RefLayer::PrintInfo(nsACString& aTo, const char* aPrefix)
|
|
|
|
{ return aTo; }
|
|
|
|
|
2011-02-16 22:43:30 +00:00
|
|
|
nsACString&
|
|
|
|
ReadbackLayer::PrintInfo(nsACString& aTo, const char* aPrefix)
|
|
|
|
{ return aTo; }
|
|
|
|
|
2010-07-21 18:06:33 +00:00
|
|
|
void LayerManager::Dump(FILE* aFile, const char* aPrefix) {}
|
|
|
|
void LayerManager::DumpSelf(FILE* aFile, const char* aPrefix) {}
|
|
|
|
void LayerManager::Log(const char* aPrefix) {}
|
|
|
|
void LayerManager::LogSelf(const char* aPrefix) {}
|
|
|
|
|
|
|
|
nsACString&
|
|
|
|
LayerManager::PrintInfo(nsACString& aTo, const char* aPrefix)
|
|
|
|
{ return aTo; }
|
|
|
|
|
|
|
|
/*static*/ void LayerManager::InitLog() {}
|
|
|
|
/*static*/ bool LayerManager::IsLogEnabled() { return false; }
|
|
|
|
|
|
|
|
#endif // MOZ_LAYERS_HAVE_LOG
|
|
|
|
|
|
|
|
PRLogModuleInfo* LayerManager::sLog;
|
|
|
|
|
2012-07-31 17:28:20 +00:00
|
|
|
} // namespace layers
|
2010-07-21 18:06:33 +00:00
|
|
|
} // namespace mozilla
|