Skip to content

Commit

Permalink
Bug 745148, part 6: Allow layer trees to be given IDs so that the ref…
Browse files Browse the repository at this point in the history
…erent can be used in another context. r=ajuma sr=roc
  • Loading branch information
joneschrisg committed Jul 17, 2012
1 parent 49ee683 commit befb6c8
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 34 deletions.
3 changes: 2 additions & 1 deletion dom/ipc/TabChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,8 @@ TabChild::InitWidget(const nsIntSize& size)
"shouldn't have a shadow manager yet");
LayerManager::LayersBackend be;
PRInt32 maxTextureSize;
PLayersChild* shadowManager = remoteFrame->SendPLayersConstructor(&be, &maxTextureSize);
uint64_t id;
PLayersChild* shadowManager = remoteFrame->SendPLayersConstructor(&be, &maxTextureSize, &id);
if (!shadowManager) {
NS_WARNING("failed to construct LayersChild");
// This results in |remoteFrame| being deleted.
Expand Down
3 changes: 2 additions & 1 deletion gfx/layers/Layers.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class THEBES_API LayerManager {
LAYERS_LAST
};

LayerManager() : mDestroyed(false), mSnapEffectiveTransforms(true)
LayerManager() : mDestroyed(false), mSnapEffectiveTransforms(true), mId(0)
{
InitLog();
}
Expand Down Expand Up @@ -518,6 +518,7 @@ class THEBES_API LayerManager {

static void InitLog();
static PRLogModuleInfo* sLog;
uint64_t mId;
private:
TimeStamp mLastFrameTime;
nsTArray<float> mFrameTimes;
Expand Down
2 changes: 1 addition & 1 deletion gfx/layers/ipc/CompositorChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ CompositorChild::Destroy()
}

PLayersChild*
CompositorChild::AllocPLayers(const LayersBackend &aBackend, int* aMaxTextureSize)
CompositorChild::AllocPLayers(const LayersBackend &aBackend, const uint64_t& aId, int* aMaxTextureSize)
{
return new ShadowLayersChild();
}
Expand Down
2 changes: 1 addition & 1 deletion gfx/layers/ipc/CompositorChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CompositorChild : public PCompositorChild
void Destroy();

protected:
virtual PLayersChild* AllocPLayers(const LayersBackend &aBackend, int* aMaxTextureSize);
virtual PLayersChild* AllocPLayers(const LayersBackend &aBackend, const uint64_t& aId, int* aMaxTextureSize);
virtual bool DeallocPLayers(PLayersChild *aChild);

private:
Expand Down
10 changes: 7 additions & 3 deletions gfx/layers/ipc/CompositorParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,12 @@ CompositorParent::ShadowLayersUpdated(ShadowLayersParent* aLayerTree,
}

PLayersParent*
CompositorParent::AllocPLayers(const LayersBackend& aBackendType, int* aMaxTextureSize)
CompositorParent::AllocPLayers(const LayersBackend& aBackendType,
const uint64_t& aId,
int32_t* aMaxTextureSize)
{
MOZ_ASSERT(aId == 0);

// mWidget doesn't belong to the compositor thread, so it should be set to
// NULL before returning from this method, to avoid accessing it elsewhere.
nsIntRect rect;
Expand Down Expand Up @@ -569,7 +573,7 @@ CompositorParent::AllocPLayers(const LayersBackend& aBackendType, int* aMaxTextu
return NULL;
}
*aMaxTextureSize = layerManager->GetMaxTextureSize();
return new ShadowLayersParent(slm, this);
return new ShadowLayersParent(slm, this, 0);
} else if (aBackendType == LayerManager::LAYERS_BASIC) {
nsRefPtr<LayerManager> layerManager = new BasicShadowLayerManager(mWidget);
mWidget = NULL;
Expand All @@ -579,7 +583,7 @@ CompositorParent::AllocPLayers(const LayersBackend& aBackendType, int* aMaxTextu
return NULL;
}
*aMaxTextureSize = layerManager->GetMaxTextureSize();
return new ShadowLayersParent(slm, this);
return new ShadowLayersParent(slm, this, 0);
} else {
NS_ERROR("Unsupported backend selected for Async Compositor");
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion gfx/layers/ipc/CompositorParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class CompositorParent : public PCompositorParent,
static void ShutDown();

protected:
virtual PLayersParent* AllocPLayers(const LayersBackend& aBackendType, int* aMaxTextureSize);
virtual PLayersParent* AllocPLayers(const LayersBackend& aBackendType, const uint64_t& aId, int32_t* aMaxTextureSize);
virtual bool DeallocPLayers(PLayersParent* aLayers);
virtual void ScheduleTask(CancelableTask*, int);
virtual void Composite();
Expand Down
4 changes: 2 additions & 2 deletions gfx/layers/ipc/PCompositor.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ parent:
sync Pause();
sync Resume();

sync PLayers(LayersBackend backend)
returns (int maxTextureSize);
sync PLayers(LayersBackend backend, uint64_t id)
returns (int32_t maxTextureSize);
};

} // layers
Expand Down
8 changes: 6 additions & 2 deletions gfx/layers/ipc/ShadowLayersParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,12 @@ ShadowChild(const OpRemoveChild& op)
//--------------------------------------------------
// ShadowLayersParent
ShadowLayersParent::ShadowLayersParent(ShadowLayerManager* aManager,
ShadowLayersManager* aLayersManager)
: mLayerManager(aManager), mShadowLayersManager(aLayersManager), mDestroyed(false)
ShadowLayersManager* aLayersManager,
uint64_t aId)
: mLayerManager(aManager)
, mShadowLayersManager(aLayersManager)
, mId(aId)
, mDestroyed(false)
{
MOZ_COUNT_CTOR(ShadowLayersParent);
}
Expand Down
10 changes: 9 additions & 1 deletion gfx/layers/ipc/ShadowLayersParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ class ShadowLayersParent : public PLayersParent,
typedef InfallibleTArray<EditReply> EditReplyArray;

public:
ShadowLayersParent(ShadowLayerManager* aManager, ShadowLayersManager* aLayersManager);
ShadowLayersParent(ShadowLayerManager* aManager,
ShadowLayersManager* aLayersManager,
uint64_t aId);
~ShadowLayersParent();

void Destroy();

ShadowLayerManager* layer_manager() const { return mLayerManager; }

uint64_t GetId() const { return mId; }
ContainerLayer* GetRoot() const { return mRoot; }

virtual void DestroySharedSurface(gfxSharedImageSurface* aSurface);
Expand Down Expand Up @@ -69,6 +72,11 @@ class ShadowLayersParent : public PLayersParent,
// Hold the root because it might be grafted under various
// containers in the "real" layer tree
nsRefPtr<ContainerLayer> mRoot;
// When this is nonzero, it refers to a layer tree owned by the
// compositor thread. It is always true that
// mId != 0 => mRoot == null
// because the "real tree" is owned by the compositor.
uint64_t mId;
// When the widget/frame/browser stuff in this process begins its
// destruction process, we need to Disconnect() all the currently
// live shadow layers, because some of them might be orphaned from
Expand Down
15 changes: 13 additions & 2 deletions layout/ipc/PRenderFrame.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,19 @@ sync protocol PRenderFrame
manages PLayers;

parent:
sync PLayers()
returns (LayersBackend backend, int maxTextureSize);
/**
* Shadow layer trees can be grafted into the parent's in one of
* two ways
* - direct shadow tree: updates are sent to parent
* - indirect: the parent holds a reference (ID) to a shadow tree
* that's managed by the compositor. During composition, the
* shadow tree is looked up and grafted appropriately
*
* |id| is set to 0 in the "direct" case, and to a whole number
* in the "indirect" case.
*/
sync PLayers()
returns (LayersBackend backend, int32_t maxTextureSize, uint64_t layersId);

async __delete__();

Expand Down
3 changes: 2 additions & 1 deletion layout/ipc/RenderFrameChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ RenderFrameChild::Destroy()
}

PLayersChild*
RenderFrameChild::AllocPLayers(LayerManager::LayersBackend* aBackendType, int* aMaxTextureSize)
RenderFrameChild::AllocPLayers(LayerManager::LayersBackend* aBackendType,
int* aMaxTextureSize, uint64_t* aId)
{
return new ShadowLayersChild();
}
Expand Down
3 changes: 2 additions & 1 deletion layout/ipc/RenderFrameChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class RenderFrameChild : public PRenderFrameChild

protected:
NS_OVERRIDE
virtual PLayersChild* AllocPLayers(LayerManager::LayersBackend* aBackendType, int* aMaxTextureSize);
virtual PLayersChild* AllocPLayers(LayerManager::LayersBackend* aBackendType,
int* aMaxTextureSize, uint64_t* aId);
NS_OVERRIDE
virtual bool DeallocPLayers(PLayersChild* aLayers);
};
Expand Down
32 changes: 24 additions & 8 deletions layout/ipc/RenderFrameParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,25 +609,34 @@ RenderFrameParent::ActorDestroy(ActorDestroyReason why)
}

PLayersParent*
RenderFrameParent::AllocPLayers(LayerManager::LayersBackend* aBackendType, int* aMaxTextureSize)
RenderFrameParent::AllocPLayers(LayerManager::LayersBackend* aBackendType,
int* aMaxTextureSize,
uint64_t* aId)
{
*aBackendType = LayerManager::LAYERS_NONE;
*aMaxTextureSize = 0;
*aId = 0;

if (!mFrameLoader || mFrameLoaderDestroyed) {
*aBackendType = LayerManager::LAYERS_NONE;
*aMaxTextureSize = 0;
return nsnull;
}

nsRefPtr<LayerManager> lm =
nsContentUtils::LayerManagerForDocument(mFrameLoader->GetOwnerDoc());
nsIDocument* doc = mFrameLoader->GetOwnerDoc();
nsRefPtr<LayerManager> lm = nsContentUtils::LayerManagerForDocument(doc);
ShadowLayerManager* slm = lm->AsShadowManager();
if (!slm) {
*aBackendType = LayerManager::LAYERS_NONE;
*aMaxTextureSize = 0;
return nsnull;
}
*aBackendType = lm->GetBackendType();
*aMaxTextureSize = lm->GetMaxTextureSize();
return new ShadowLayersParent(slm, this);
#if 0 // Enabled in later patch
if (CompositorParent::CompositorLoop()) {
// Our remote frame will push layers updates to the compositor,
// and we'll keep an indirect reference to that tree.
*aId = CompositorParent::AllocateLayerTreeId();
}
#endif
return new ShadowLayersParent(slm, this, *aId);
}

bool
Expand Down Expand Up @@ -681,6 +690,13 @@ RenderFrameParent::GetShadowLayers() const
static_cast<ShadowLayersParent*>(shadowParents[0]) : nsnull;
}

uint64_t
RenderFrameParent::GetLayerTreeId() const
{
ShadowLayersParent* shadowLayers = GetShadowLayers();
return shadowLayers ? shadowLayers->GetId() : 0;
}

ContainerLayer*
RenderFrameParent::GetRootLayer() const
{
Expand Down
10 changes: 6 additions & 4 deletions layout/ipc/RenderFrameParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,18 @@ class RenderFrameParent : public PRenderFrameParent,
void SetBackgroundColor(nscolor aColor) { mBackgroundColor = gfxRGBA(aColor); };

protected:
NS_OVERRIDE void ActorDestroy(ActorDestroyReason why);
void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE;

NS_OVERRIDE virtual PLayersParent* AllocPLayers(LayerManager::LayersBackend* aBackendType,
int* aMaxTextureSize);
NS_OVERRIDE virtual bool DeallocPLayers(PLayersParent* aLayers);
virtual PLayersParent*
AllocPLayers(LayerManager::LayersBackend* aBackendType,
int* aMaxTextureSize, uint64_t* aLayersId) MOZ_OVERRIDE;
virtual bool DeallocPLayers(PLayersParent* aLayers) MOZ_OVERRIDE;

private:
void BuildViewMap();

ShadowLayersParent* GetShadowLayers() const;
uint64_t GetLayerTreeId() const;
ContainerLayer* GetRootLayer() const;

nsRefPtr<nsFrameLoader> mFrameLoader;
Expand Down
10 changes: 5 additions & 5 deletions widget/xpwidgets/nsBaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ void nsBaseWidget::BaseCreate(nsIWidget *aParent,
{
static bool gDisableNativeThemeCached = false;
if (!gDisableNativeThemeCached) {
mozilla::Preferences::AddBoolVarCache(&gDisableNativeTheme,
"mozilla.widget.disable-native-theme",
gDisableNativeTheme);
Preferences::AddBoolVarCache(&gDisableNativeTheme,
"mozilla.widget.disable-native-theme",
gDisableNativeTheme);
gDisableNativeThemeCached = true;
}

Expand Down Expand Up @@ -879,9 +879,9 @@ void nsBaseWidget::CreateCompositor()
PRInt32 maxTextureSize;
PLayersChild* shadowManager;
if (mUseAcceleratedRendering) {
shadowManager = mCompositorChild->SendPLayersConstructor(LayerManager::LAYERS_OPENGL, &maxTextureSize);
shadowManager = mCompositorChild->SendPLayersConstructor(LayerManager::LAYERS_OPENGL, 0, &maxTextureSize);
} else {
shadowManager = mCompositorChild->SendPLayersConstructor(LayerManager::LAYERS_BASIC, &maxTextureSize);
shadowManager = mCompositorChild->SendPLayersConstructor(LayerManager::LAYERS_BASIC, 0, &maxTextureSize);
}

if (shadowManager) {
Expand Down

0 comments on commit befb6c8

Please sign in to comment.