Bug 60431, part 1: Add a ShadowLayer base class. r=roc sr=vlad

This commit is contained in:
Chris Jones 2010-10-13 17:55:45 -05:00
Родитель 485eaa8ad1
Коммит 6072b647fd
4 изменённых файлов: 159 добавлений и 36 удалений

Просмотреть файл

@ -38,6 +38,10 @@
*
* ***** END LICENSE BLOCK ***** */
#ifdef MOZ_IPC
# include "mozilla/layers/ShadowLayers.h"
#endif // MOZ_IPC
#include "ImageLayers.h"
#include "Layers.h"
#include "gfxPlatform.h"
@ -200,8 +204,50 @@ Layer::CanUseOpaqueSurface()
parent->CanUseOpaqueSurface();
}
#ifdef MOZ_IPC
// 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();
}
const gfx3DMatrix&
Layer::GetEffectiveTransform()
{
if (ShadowLayer* shadow = AsShadowLayer()) {
return shadow->GetShadowTransform();
}
return GetTransform();
}
#else
const nsIntRect* Layer::GetEffectiveClipRect() { return GetClipRect(); }
const nsIntRegion& Layer::GetEffectiveVisibleRegion() { return GetVisibleRegion(); }
const gfx3DMatrix& Layer::GetEffectiveTransform() { return GetTransform(); }
#endif // MOZ_IPC
#ifdef MOZ_LAYERS_HAVE_LOG
static nsACString& PrintInfo(nsACString& aTo, ShadowLayer* aShadowLayer);
void
Layer::Dump(FILE* aFile, const char* aPrefix)
{
@ -260,6 +306,8 @@ Layer::PrintInfo(nsACString& aTo, const char* aPrefix)
aTo += aPrefix;
aTo += nsPrintfCString(64, "%s%s (0x%p)", mManager->Name(), Name(), this);
::PrintInfo(aTo, AsShadowLayer());
if (mUseClipRect) {
AppendToString(aTo, mClipRect, " [clip=", "]");
}
@ -405,6 +453,28 @@ LayerManager::IsLogEnabled()
return PR_LOG_TEST(sLog, PR_LOG_DEBUG);
}
# ifdef MOZ_IPC
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;
}
# else
static nsACString& PrintInfo(nsACString& aTo, ShadowLayer* aShadowLayer) {}
# endif // MOZ_IPC
#else // !MOZ_LAYERS_HAVE_LOG
void Layer::Dump(FILE* aFile, const char* aPrefix) {}

Просмотреть файл

@ -77,6 +77,7 @@ class ImageLayer;
class ColorLayer;
class ImageContainer;
class CanvasLayer;
class ShadowLayer;
class SpecificLayerAttributes;
/**
@ -643,6 +644,19 @@ public:
*/
virtual ThebesLayer* AsThebesLayer() { return nsnull; }
/**
* Dynamic cast to a ShadowLayer. Return null if this is not a
* ShadowLayer. Can be used anytime.
*/
virtual ShadowLayer* AsShadowLayer() { return nsnull; }
// These getters can be used anytime. They return the effective
// values that should be used when drawing this layer to screen,
// accounting for this layer possibly being a shadow.
const nsIntRect* GetEffectiveClipRect();
const nsIntRegion& GetEffectiveVisibleRegion();
const gfx3DMatrix& GetEffectiveTransform();
virtual const char* Name() const =0;
virtual LayerType GetType() const =0;

Просмотреть файл

@ -385,18 +385,76 @@ protected:
};
class ShadowThebesLayer : public ThebesLayer
/**
* A ShadowLayer is the representation of a child-context's Layer in a
* parent context. They can be transformed, clipped,
* etc. independently of their origin Layers.
*
* Note that ShadowLayers can themselves have a shadow in a parent
* context.
*/
class ShadowLayer
{
public:
virtual ~ShadowLayer() {}
/**
* CONSTRUCTION PHASE ONLY
*/
void SetParent(PLayersParent* aParent)
void SetAllocator(PLayersParent* aAllocator)
{
NS_ABORT_IF_FALSE(!mAllocator, "Stomping parent?");
mAllocator = aParent;
NS_ABORT_IF_FALSE(!mAllocator, "Stomping allocator?");
mAllocator = aAllocator;
}
/**
* The following methods are
*
* CONSTRUCTION PHASE ONLY
*
* They are analogous to the Layer interface.
*/
void SetShadowVisibleRegion(const nsIntRegion& aRegion)
{
mShadowVisibleRegion = aRegion;
}
void SetShadowClipRect(const nsIntRect* aRect)
{
mUseShadowClipRect = aRect != nsnull;
if (aRect) {
mShadowClipRect = *aRect;
}
}
void SetShadowTransform(const gfx3DMatrix& aMatrix)
{
mShadowTransform = aMatrix;
}
// These getters can be used anytime.
const nsIntRect* GetShadowClipRect() { return mUseShadowClipRect ? &mShadowClipRect : nsnull; }
const nsIntRegion& GetShadowVisibleRegion() { return mShadowVisibleRegion; }
const gfx3DMatrix& GetShadowTransform() { return mShadowTransform; }
protected:
ShadowLayer()
: mAllocator(nsnull)
, mUseShadowClipRect(PR_FALSE)
{}
PLayersParent* mAllocator;
nsIntRegion mShadowVisibleRegion;
gfx3DMatrix mShadowTransform;
nsIntRect mShadowClipRect;
PRPackedBool mUseShadowClipRect;
};
class ShadowThebesLayer : public ShadowLayer,
public ThebesLayer
{
public:
/**
* CONSTRUCTION PHASE ONLY
*
@ -450,30 +508,21 @@ public:
*/
virtual void DestroyFrontBuffer() = 0;
virtual ShadowLayer* AsShadowLayer() { return this; }
MOZ_LAYER_DECL_NAME("ShadowThebesLayer", TYPE_SHADOW)
protected:
ShadowThebesLayer(LayerManager* aManager, void* aImplData)
: ThebesLayer(aManager, aImplData)
, mAllocator(nsnull)
{}
PLayersParent* mAllocator;
};
class ShadowCanvasLayer : public CanvasLayer
class ShadowCanvasLayer : public ShadowLayer,
public CanvasLayer
{
public:
/**
* CONSTRUCTION PHASE ONLY
*/
void SetParent(PLayersParent* aParent)
{
NS_ABORT_IF_FALSE(!mAllocator, "Stomping parent?");
mAllocator = aParent;
}
/**
* CONSTRUCTION PHASE ONLY
*
@ -491,30 +540,21 @@ public:
*/
virtual void DestroyFrontBuffer() = 0;
virtual ShadowLayer* AsShadowLayer() { return this; }
MOZ_LAYER_DECL_NAME("ShadowCanvasLayer", TYPE_SHADOW)
protected:
ShadowCanvasLayer(LayerManager* aManager, void* aImplData)
: CanvasLayer(aManager, aImplData)
, mAllocator(nsnull)
{}
PLayersParent* mAllocator;
};
class ShadowImageLayer : public ImageLayer
class ShadowImageLayer : public ShadowLayer,
public ImageLayer
{
public:
/**
* CONSTRUCTION PHASE ONLY
*/
void SetParent(PLayersParent* aParent)
{
NS_ABORT_IF_FALSE(!mAllocator, "Stomping parent?");
mAllocator = aParent;
}
/**
* CONSTRUCTION PHASE ONLY
*
@ -539,15 +579,14 @@ public:
*/
virtual void DestroyFrontBuffer() = 0;
virtual ShadowLayer* AsShadowLayer() { return this; }
MOZ_LAYER_DECL_NAME("ShadowImageLayer", TYPE_SHADOW)
protected:
ShadowImageLayer(LayerManager* aManager, void* aImplData)
: ImageLayer(aManager, aImplData)
, mAllocator(nsnull)
{}
PLayersParent* mAllocator;
};

Просмотреть файл

@ -152,7 +152,7 @@ ShadowLayersParent::RecvUpdate(const nsTArray<Edit>& cset,
nsRefPtr<ShadowThebesLayer> layer =
layer_manager()->CreateShadowThebesLayer();
layer->SetParent(this);
layer->SetAllocator(this);
AsShadowLayer(edit.get_OpCreateThebesLayer())->Bind(layer);
break;
}
@ -168,7 +168,7 @@ ShadowLayersParent::RecvUpdate(const nsTArray<Edit>& cset,
nsRefPtr<ShadowImageLayer> layer =
layer_manager()->CreateShadowImageLayer();
layer->SetParent(this);
layer->SetAllocator(this);
AsShadowLayer(edit.get_OpCreateImageLayer())->Bind(layer);
break;
}
@ -184,7 +184,7 @@ ShadowLayersParent::RecvUpdate(const nsTArray<Edit>& cset,
nsRefPtr<ShadowCanvasLayer> layer =
layer_manager()->CreateShadowCanvasLayer();
layer->SetParent(this);
layer->SetAllocator(this);
AsShadowLayer(edit.get_OpCreateCanvasLayer())->Bind(layer);
break;
}