Bug 590294, part 2: Add a ContainerLayer attribute FrameMetrics that stores relevant information from layout/ on the root layer. r=roc sr=vlad

This commit is contained in:
Chris Jones 2010-09-03 15:10:45 -05:00
parent b1006262ae
commit 2aaf1a0c12
7 changed files with 182 additions and 4 deletions

View File

@ -39,7 +39,9 @@
* ***** END LICENSE BLOCK ***** */
#include "ImageLayers.h"
#include "Layers.h"
#include "Layers.h"
using namespace mozilla::layers;
#ifdef MOZ_LAYERS_HAVE_LOG
FILE*
@ -52,7 +54,7 @@ FILEOrDefault(FILE* aFile)
namespace {
// XXX pretty general utilities, could centralize
nsACString&
AppendToString(nsACString& s, const gfxPattern::GraphicsFilter& f,
const char* pfx="", const char* sfx="")
@ -108,6 +110,15 @@ AppendToString(nsACString& s, const gfx3DMatrix& m,
return s += sfx;
}
nsACString&
AppendToString(nsACString& s, const nsIntPoint& p,
const char* pfx="", const char* sfx="")
{
s += pfx;
s += nsPrintfCString(128, "(x=%d, y=%d)", p.x, p.y);
return s += sfx;
}
nsACString&
AppendToString(nsACString& s, const nsIntRect& r,
const char* pfx="", const char* sfx="")
@ -134,6 +145,26 @@ AppendToString(nsACString& s, const nsIntRegion& r,
return s += sfx;
}
nsACString&
AppendToString(nsACString& s, const nsIntSize& sz,
const char* pfx="", const char* sfx="")
{
s += pfx;
s += nsPrintfCString(128, "(w=%d, h=%d)", sz.width, sz.height);
return s += sfx;
}
nsACString&
AppendToString(nsACString& s, const FrameMetrics& m,
const char* pfx="", const char* sfx="")
{
s += pfx;
AppendToString(s, m.mViewportSize, "{ viewport=");
AppendToString(s, m.mViewportScrollOffset, " viewportScroll=");
AppendToString(s, m.mDisplayPort, " displayport=", " }");
return s += sfx;
}
} // namespace <anon>
namespace mozilla {
@ -251,6 +282,14 @@ ThebesLayer::PrintInfo(nsACString& aTo, const char* aPrefix)
aTo : AppendToString(aTo, mValidRegion, " [valid=", "]");
}
nsACString&
ContainerLayer::PrintInfo(nsACString& aTo, const char* aPrefix)
{
Layer::PrintInfo(aTo, aPrefix);
return mFrameMetrics.IsDefault() ?
aTo : AppendToString(aTo, mFrameMetrics, " [metrics=", "]");
}
nsACString&
ColorLayer::PrintInfo(nsACString& aTo, const char* aPrefix)
{
@ -369,6 +408,10 @@ nsACString&
ThebesLayer::PrintInfo(nsACString& aTo, const char* aPrefix)
{ return aTo; }
nsACString&
ContainerLayer::PrintInfo(nsACString& aTo, const char* aPrefix)
{ return aTo; }
nsACString&
ColorLayer::PrintInfo(nsACString& aTo, const char* aPrefix)
{ return aTo; }

View File

@ -79,6 +79,37 @@ class ImageContainer;
class CanvasLayer;
class SpecificLayerAttributes;
/**
* The viewport and displayport metrics for the painted frame at the
* time of a layer-tree transaction. These metrics are especially
* useful for shadow layers, because the metrics values are updated
* atomically with new pixels.
*/
struct FrameMetrics {
FrameMetrics()
: mViewportSize(0, 0)
, mViewportScrollOffset(0, 0)
{}
// Default copy ctor and operator= are fine
PRBool operator==(const FrameMetrics& aOther) const
{
return (mViewportSize == aOther.mViewportSize &&
mViewportScrollOffset == aOther.mViewportScrollOffset &&
mDisplayPort == aOther.mDisplayPort);
}
PRBool IsDefault() const
{
return (FrameMetrics() == *this);
}
nsIntSize mViewportSize;
nsIntPoint mViewportScrollOffset;
nsIntRect mDisplayPort;
};
#define MOZ_LAYER_DECL_NAME(n, e) \
virtual const char* Name() const { return n; } \
virtual LayerType GetType() const { return e; }
@ -733,8 +764,20 @@ public:
*/
virtual void RemoveChild(Layer* aChild) = 0;
// This getter can be used anytime.
/**
* CONSTRUCTION PHASE ONLY
* Set the (sub)document metrics used to render the Layer subtree
* rooted at this.
*/
void SetFrameMetrics(const FrameMetrics& aFrameMetrics)
{
mFrameMetrics = aFrameMetrics;
}
// These getters can be used anytime.
virtual Layer* GetFirstChild() { return mFirstChild; }
const FrameMetrics& GetFrameMetrics() { return mFrameMetrics; }
MOZ_LAYER_DECL_NAME("ContainerLayer", TYPE_CONTAINER)
@ -744,7 +787,10 @@ protected:
mFirstChild(nsnull)
{}
virtual nsACString& PrintInfo(nsACString& aTo, const char* aPrefix);
Layer* mFirstChild;
FrameMetrics mFrameMetrics;
};
/**

View File

@ -103,7 +103,8 @@ endif
endif
ifdef MOZ_IPC #{
EXPORTS_NAMESPACES = mozilla/layers
EXPORTS_NAMESPACES = IPC mozilla/layers
EXPORTS_IPC = ShadowLayerUtils.h
EXPORTS_mozilla/layers =\
ShadowLayers.h \
ShadowLayersChild.h \

View File

@ -1239,6 +1239,11 @@ public:
virtual void InsertAfter(Layer* aChild, Layer* aAfter);
virtual void RemoveChild(Layer* aChild);
virtual void FillSpecificAttributes(SpecificLayerAttributes& aAttrs)
{
aAttrs = ContainerLayerAttributes(GetFrameMetrics());
}
virtual Layer* AsLayer() { return this; }
virtual ShadowableLayer* AsShadowableLayer() { return this; }

View File

@ -42,6 +42,8 @@
include protocol PLayer;
include protocol PRenderFrame;
include "IPC/ShadowLayerUtils.h";
using gfx3DMatrix;
using gfxRGBA;
using nsIntPoint;
@ -49,6 +51,7 @@ using nsIntRect;
using nsIntRegion;
using nsIntSize;
using mozilla::GraphicsFilterType;
using mozilla::layers::FrameMetrics;
using mozilla::null_t;
/**
@ -105,6 +108,7 @@ struct CommonLayerAttributes {
};
struct ThebesLayerAttributes { nsIntRegion validRegion; };
struct ContainerLayerAttributes{ FrameMetrics metrics; };
struct ColorLayerAttributes { gfxRGBA color; };
struct CanvasLayerAttributes { GraphicsFilterType filter; };
struct ImageLayerAttributes { GraphicsFilterType filter; };
@ -112,6 +116,7 @@ struct ImageLayerAttributes { GraphicsFilterType filter; };
union SpecificLayerAttributes {
null_t;
ThebesLayerAttributes;
ContainerLayerAttributes;
ColorLayerAttributes;
CanvasLayerAttributes;
ImageLayerAttributes;

View File

@ -0,0 +1,71 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=8 et :
*/
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Code.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Chris Jones <jones.chris.g@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef IPC_ShadowLayerUtils_h
#define IPC_ShadowLayerUtils_h
#include "IPC/IPCMessageUtils.h"
#include "Layers.h"
namespace IPC {
template <>
struct ParamTraits<mozilla::layers::FrameMetrics>
{
typedef mozilla::layers::FrameMetrics paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
WriteParam(aMsg, aParam.mViewportSize);
WriteParam(aMsg, aParam.mViewportScrollOffset);
WriteParam(aMsg, aParam.mDisplayPort);
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
return (ReadParam(aMsg, aIter, &aResult->mViewportSize) &&
ReadParam(aMsg, aIter, &aResult->mViewportScrollOffset) &&
ReadParam(aMsg, aIter, &aResult->mDisplayPort));
}
};
}
#endif // IPC_ShadowLayerUtils_h

View File

@ -287,6 +287,13 @@ ShadowLayersParent::RecvUpdate(const nsTArray<Edit>& cset,
specific.get_ThebesLayerAttributes().validRegion());
break;
case Specific::TContainerLayerAttributes:
MOZ_LAYERS_LOG(("[ParentSide] container layer"));
static_cast<ContainerLayer*>(layer)->SetFrameMetrics(
specific.get_ContainerLayerAttributes().metrics());
break;
case Specific::TColorLayerAttributes:
MOZ_LAYERS_LOG(("[ParentSide] color layer"));