2010-07-22 01:17:33 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: sw=2 ts=8 et :
|
|
|
|
*/
|
2012-05-21 15:12:37 +04: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-22 01:17:33 +04:00
|
|
|
|
|
|
|
#include <set>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "gfxSharedImageSurface.h"
|
2012-05-26 08:38:17 +04:00
|
|
|
#include "gfxPlatform.h"
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2012-07-12 16:51:58 +04:00
|
|
|
#include "AutoOpenSurface.h"
|
2010-09-28 04:59:43 +04:00
|
|
|
#include "mozilla/ipc/SharedMemorySysV.h"
|
2010-07-22 01:17:33 +04:00
|
|
|
#include "mozilla/layers/PLayerChild.h"
|
|
|
|
#include "mozilla/layers/PLayersChild.h"
|
2010-07-22 01:17:33 +04:00
|
|
|
#include "mozilla/layers/PLayersParent.h"
|
2010-07-22 01:17:33 +04:00
|
|
|
#include "ShadowLayers.h"
|
2010-07-22 01:17:33 +04:00
|
|
|
#include "ShadowLayerChild.h"
|
2012-01-03 23:36:00 +04:00
|
|
|
#include "gfxipc/ShadowLayerUtils.h"
|
2012-02-28 20:24:24 +04:00
|
|
|
#include "RenderTrace.h"
|
2012-04-16 22:36:33 +04:00
|
|
|
#include "sampler.h"
|
2012-04-13 19:17:39 +04:00
|
|
|
#include "nsXULAppAPI.h"
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2010-09-28 04:59:43 +04:00
|
|
|
using namespace mozilla::ipc;
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
typedef nsTArray<SurfaceDescriptor> BufferArray;
|
2010-07-22 01:17:33 +04:00
|
|
|
typedef std::vector<Edit> EditVector;
|
|
|
|
typedef std::set<ShadowableLayer*> ShadowableLayerSet;
|
|
|
|
|
|
|
|
class Transaction
|
|
|
|
{
|
|
|
|
public:
|
2012-05-01 23:23:39 +04:00
|
|
|
Transaction()
|
2012-05-18 12:29:38 +04:00
|
|
|
: mSwapRequired(false)
|
|
|
|
, mOpen(false)
|
2012-05-01 23:23:39 +04:00
|
|
|
{}
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2012-07-24 23:01:09 +04:00
|
|
|
void Begin(const nsIntRect& aTargetBounds, ScreenRotation aRotation)
|
|
|
|
{
|
|
|
|
mOpen = true;
|
|
|
|
mTargetBounds = aTargetBounds;
|
|
|
|
mTargetRotation = aRotation;
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
|
|
|
|
void AddEdit(const Edit& aEdit)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(!Finished(), "forgot BeginTransaction?");
|
|
|
|
mCset.push_back(aEdit);
|
|
|
|
}
|
2010-09-16 01:03:13 +04:00
|
|
|
void AddPaint(const Edit& aPaint)
|
2012-05-01 23:23:39 +04:00
|
|
|
{
|
|
|
|
AddNoSwapPaint(aPaint);
|
|
|
|
mSwapRequired = true;
|
|
|
|
}
|
|
|
|
void AddNoSwapPaint(const Edit& aPaint)
|
2010-09-16 01:03:13 +04:00
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(!Finished(), "forgot BeginTransaction?");
|
|
|
|
mPaints.push_back(aPaint);
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
void AddMutant(ShadowableLayer* aLayer)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(!Finished(), "forgot BeginTransaction?");
|
|
|
|
mMutants.insert(aLayer);
|
|
|
|
}
|
2010-09-14 09:23:08 +04:00
|
|
|
void AddBufferToDestroy(gfxSharedImageSurface* aBuffer)
|
2010-09-14 09:23:08 +04:00
|
|
|
{
|
|
|
|
return AddBufferToDestroy(aBuffer->GetShmem());
|
|
|
|
}
|
|
|
|
void AddBufferToDestroy(const SurfaceDescriptor& aBuffer)
|
2010-09-14 09:23:08 +04:00
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(!Finished(), "forgot BeginTransaction?");
|
|
|
|
mDyingBuffers.AppendElement(aBuffer);
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
|
|
|
|
void End()
|
|
|
|
{
|
|
|
|
mCset.clear();
|
2010-09-16 01:03:13 +04:00
|
|
|
mPaints.clear();
|
2010-09-14 09:23:08 +04:00
|
|
|
mDyingBuffers.Clear();
|
2010-07-22 01:17:33 +04:00
|
|
|
mMutants.clear();
|
2011-10-17 18:59:28 +04:00
|
|
|
mOpen = false;
|
2012-05-01 23:23:39 +04:00
|
|
|
mSwapRequired = false;
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool Empty() const {
|
2010-09-16 01:03:13 +04:00
|
|
|
return mCset.empty() && mPaints.empty() && mMutants.empty();
|
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
bool Finished() const { return !mOpen && Empty(); }
|
2010-07-22 01:17:33 +04:00
|
|
|
|
|
|
|
EditVector mCset;
|
2010-09-16 01:03:13 +04:00
|
|
|
EditVector mPaints;
|
2010-09-14 09:23:08 +04:00
|
|
|
BufferArray mDyingBuffers;
|
2010-07-22 01:17:33 +04:00
|
|
|
ShadowableLayerSet mMutants;
|
2012-07-24 23:01:09 +04:00
|
|
|
nsIntRect mTargetBounds;
|
|
|
|
ScreenRotation mTargetRotation;
|
2012-05-01 23:23:39 +04:00
|
|
|
bool mSwapRequired;
|
2010-07-22 01:17:33 +04:00
|
|
|
|
|
|
|
private:
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mOpen;
|
2010-07-22 01:17:33 +04:00
|
|
|
|
|
|
|
// disabled
|
|
|
|
Transaction(const Transaction&);
|
|
|
|
Transaction& operator=(const Transaction&);
|
|
|
|
};
|
|
|
|
struct AutoTxnEnd {
|
|
|
|
AutoTxnEnd(Transaction* aTxn) : mTxn(aTxn) {}
|
|
|
|
~AutoTxnEnd() { mTxn->End(); }
|
|
|
|
Transaction* mTxn;
|
|
|
|
};
|
|
|
|
|
2010-12-31 10:40:19 +03:00
|
|
|
ShadowLayerForwarder::ShadowLayerForwarder()
|
|
|
|
: mShadowManager(NULL)
|
2012-05-23 03:15:16 +04:00
|
|
|
, mMaxTextureSize(0)
|
2012-07-18 20:31:40 +04:00
|
|
|
, mParentBackend(mozilla::layers::LAYERS_NONE)
|
2012-03-12 19:50:15 +04:00
|
|
|
, mIsFirstPaint(false)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
|
|
|
mTxn = new Transaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
ShadowLayerForwarder::~ShadowLayerForwarder()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(mTxn->Finished(), "unfinished transaction?");
|
|
|
|
delete mTxn;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-07-24 23:01:09 +04:00
|
|
|
ShadowLayerForwarder::BeginTransaction(const nsIntRect& aTargetBounds,
|
|
|
|
ScreenRotation aRotation)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(HasShadowManager(), "no manager to forward to");
|
|
|
|
NS_ABORT_IF_FALSE(mTxn->Finished(), "uncommitted txn?");
|
2012-07-24 23:01:09 +04:00
|
|
|
mTxn->Begin(aTargetBounds, aRotation);
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static PLayerChild*
|
|
|
|
Shadow(ShadowableLayer* aLayer)
|
|
|
|
{
|
|
|
|
return aLayer->GetShadow();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename OpCreateT>
|
|
|
|
static void
|
|
|
|
CreatedLayer(Transaction* aTxn, ShadowableLayer* aLayer)
|
|
|
|
{
|
|
|
|
aTxn->AddEdit(OpCreateT(NULL, Shadow(aLayer)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowLayerForwarder::CreatedThebesLayer(ShadowableLayer* aThebes)
|
|
|
|
{
|
|
|
|
CreatedLayer<OpCreateThebesLayer>(mTxn, aThebes);
|
|
|
|
}
|
|
|
|
void
|
|
|
|
ShadowLayerForwarder::CreatedContainerLayer(ShadowableLayer* aContainer)
|
|
|
|
{
|
|
|
|
CreatedLayer<OpCreateContainerLayer>(mTxn, aContainer);
|
|
|
|
}
|
|
|
|
void
|
|
|
|
ShadowLayerForwarder::CreatedImageLayer(ShadowableLayer* aImage)
|
|
|
|
{
|
|
|
|
CreatedLayer<OpCreateImageLayer>(mTxn, aImage);
|
|
|
|
}
|
|
|
|
void
|
|
|
|
ShadowLayerForwarder::CreatedColorLayer(ShadowableLayer* aColor)
|
|
|
|
{
|
|
|
|
CreatedLayer<OpCreateColorLayer>(mTxn, aColor);
|
|
|
|
}
|
|
|
|
void
|
|
|
|
ShadowLayerForwarder::CreatedCanvasLayer(ShadowableLayer* aCanvas)
|
|
|
|
{
|
|
|
|
CreatedLayer<OpCreateCanvasLayer>(mTxn, aCanvas);
|
|
|
|
}
|
2012-07-18 03:59:45 +04:00
|
|
|
void
|
|
|
|
ShadowLayerForwarder::CreatedRefLayer(ShadowableLayer* aRef)
|
|
|
|
{
|
|
|
|
CreatedLayer<OpCreateRefLayer>(mTxn, aRef);
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2011-10-11 03:43:56 +04:00
|
|
|
void
|
|
|
|
ShadowLayerForwarder::DestroyedThebesBuffer(ShadowableLayer* aThebes,
|
|
|
|
const SurfaceDescriptor& aBackBufferToDestroy)
|
|
|
|
{
|
|
|
|
mTxn->AddBufferToDestroy(aBackBufferToDestroy);
|
|
|
|
}
|
|
|
|
|
2010-09-03 07:05:01 +04:00
|
|
|
void
|
2010-07-22 01:17:33 +04:00
|
|
|
ShadowLayerForwarder::Mutated(ShadowableLayer* aMutant)
|
|
|
|
{
|
|
|
|
mTxn->AddMutant(aMutant);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowLayerForwarder::SetRoot(ShadowableLayer* aRoot)
|
|
|
|
{
|
|
|
|
mTxn->AddEdit(OpSetRoot(NULL, Shadow(aRoot)));
|
|
|
|
}
|
|
|
|
void
|
|
|
|
ShadowLayerForwarder::InsertAfter(ShadowableLayer* aContainer,
|
|
|
|
ShadowableLayer* aChild,
|
|
|
|
ShadowableLayer* aAfter)
|
|
|
|
{
|
|
|
|
if (aAfter)
|
|
|
|
mTxn->AddEdit(OpInsertAfter(NULL, Shadow(aContainer),
|
|
|
|
NULL, Shadow(aChild),
|
|
|
|
NULL, Shadow(aAfter)));
|
|
|
|
else
|
|
|
|
mTxn->AddEdit(OpAppendChild(NULL, Shadow(aContainer),
|
|
|
|
NULL, Shadow(aChild)));
|
|
|
|
}
|
|
|
|
void
|
|
|
|
ShadowLayerForwarder::RemoveChild(ShadowableLayer* aContainer,
|
|
|
|
ShadowableLayer* aChild)
|
|
|
|
{
|
|
|
|
mTxn->AddEdit(OpRemoveChild(NULL, Shadow(aContainer),
|
|
|
|
NULL, Shadow(aChild)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowLayerForwarder::PaintedThebesBuffer(ShadowableLayer* aThebes,
|
2010-09-14 09:23:08 +04:00
|
|
|
const nsIntRegion& aUpdatedRegion,
|
|
|
|
const nsIntRect& aBufferRect,
|
|
|
|
const nsIntPoint& aBufferRotation,
|
2010-09-14 09:23:08 +04:00
|
|
|
const SurfaceDescriptor& aNewFrontBuffer)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
2010-09-16 01:03:13 +04:00
|
|
|
mTxn->AddPaint(OpPaintThebesBuffer(NULL, Shadow(aThebes),
|
|
|
|
ThebesBuffer(aNewFrontBuffer,
|
|
|
|
aBufferRect,
|
|
|
|
aBufferRotation),
|
|
|
|
aUpdatedRegion));
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
2012-04-13 19:17:39 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
ShadowLayerForwarder::PaintedTiledLayerBuffer(ShadowableLayer* aLayer,
|
|
|
|
BasicTiledLayerBuffer* aTiledLayerBuffer)
|
|
|
|
{
|
|
|
|
if (XRE_GetProcessType() != GeckoProcessType_Default)
|
|
|
|
NS_RUNTIMEABORT("PaintedTiledLayerBuffer must be made IPC safe (not share pointers)");
|
2012-05-01 23:23:39 +04:00
|
|
|
mTxn->AddNoSwapPaint(OpPaintTiledLayerBuffer(NULL, Shadow(aLayer),
|
2012-04-13 19:17:39 +04:00
|
|
|
uintptr_t(aTiledLayerBuffer)));
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
void
|
|
|
|
ShadowLayerForwarder::PaintedImage(ShadowableLayer* aImage,
|
2011-04-21 08:38:39 +04:00
|
|
|
const SharedImage& aNewFrontImage)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
2010-09-16 01:03:13 +04:00
|
|
|
mTxn->AddPaint(OpPaintImage(NULL, Shadow(aImage),
|
2011-04-21 08:38:39 +04:00
|
|
|
aNewFrontImage));
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
void
|
|
|
|
ShadowLayerForwarder::PaintedCanvas(ShadowableLayer* aCanvas,
|
2011-09-28 02:19:28 +04:00
|
|
|
bool aNeedYFlip,
|
2011-04-21 01:45:57 +04:00
|
|
|
const SurfaceDescriptor& aNewFrontSurface)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
2010-09-16 01:03:13 +04:00
|
|
|
mTxn->AddPaint(OpPaintCanvas(NULL, Shadow(aCanvas),
|
2011-09-28 02:19:28 +04:00
|
|
|
aNewFrontSurface,
|
|
|
|
aNeedYFlip));
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-11-09 05:49:00 +03:00
|
|
|
ShadowLayerForwarder::EndTransaction(InfallibleTArray<EditReply>* aReplies)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
2012-04-16 22:36:33 +04:00
|
|
|
SAMPLE_LABEL("ShadowLayerForwarder", "EndTranscation");
|
2012-02-28 20:24:24 +04:00
|
|
|
RenderTraceScope rendertrace("Foward Transaction", "000091");
|
2010-07-22 01:17:33 +04:00
|
|
|
NS_ABORT_IF_FALSE(HasShadowManager(), "no manager to forward to");
|
|
|
|
NS_ABORT_IF_FALSE(!mTxn->Finished(), "forgot BeginTransaction?");
|
|
|
|
|
|
|
|
AutoTxnEnd _(mTxn);
|
|
|
|
|
|
|
|
if (mTxn->Empty()) {
|
|
|
|
MOZ_LAYERS_LOG(("[LayersForwarder] 0-length cset (?), skipping Update()"));
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
MOZ_LAYERS_LOG(("[LayersForwarder] destroying buffers..."));
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < mTxn->mDyingBuffers.Length(); ++i) {
|
2010-09-14 09:23:08 +04:00
|
|
|
DestroySharedSurface(&mTxn->mDyingBuffers[i]);
|
2010-09-14 09:23:08 +04:00
|
|
|
}
|
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
MOZ_LAYERS_LOG(("[LayersForwarder] building transaction..."));
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2010-09-16 01:03:13 +04:00
|
|
|
// We purposely add attribute-change ops to the final changeset
|
|
|
|
// before we add paint ops. This allows layers to record the
|
|
|
|
// attribute changes before new pixels arrive, which can be useful
|
|
|
|
// for setting up back/front buffers.
|
2012-02-28 20:24:24 +04:00
|
|
|
RenderTraceScope rendertrace2("Foward Transaction", "000092");
|
2010-07-22 01:17:33 +04:00
|
|
|
for (ShadowableLayerSet::const_iterator it = mTxn->mMutants.begin();
|
|
|
|
it != mTxn->mMutants.end(); ++it) {
|
|
|
|
ShadowableLayer* shadow = *it;
|
|
|
|
Layer* mutant = shadow->AsLayer();
|
|
|
|
NS_ABORT_IF_FALSE(!!mutant, "unshadowable layer?");
|
|
|
|
|
|
|
|
LayerAttributes attrs;
|
|
|
|
CommonLayerAttributes& common = attrs.common();
|
|
|
|
common.visibleRegion() = mutant->GetVisibleRegion();
|
2012-07-30 22:36:12 +04:00
|
|
|
common.transform() = mutant->GetTransform();
|
2010-09-02 13:18:40 +04:00
|
|
|
common.contentFlags() = mutant->GetContentFlags();
|
2010-07-22 01:17:33 +04:00
|
|
|
common.opacity() = mutant->GetOpacity();
|
|
|
|
common.useClipRect() = !!mutant->GetClipRect();
|
|
|
|
common.clipRect() = (common.useClipRect() ?
|
|
|
|
*mutant->GetClipRect() : nsIntRect());
|
2011-04-06 09:00:25 +04:00
|
|
|
common.isFixedPosition() = mutant->GetIsFixedPosition();
|
2012-06-27 19:43:57 +04:00
|
|
|
common.fixedPositionAnchor() = mutant->GetFixedPositionAnchor();
|
2012-03-19 03:02:38 +04:00
|
|
|
if (Layer* maskLayer = mutant->GetMaskLayer()) {
|
|
|
|
common.maskLayerChild() = Shadow(maskLayer->AsShadowableLayer());
|
|
|
|
} else {
|
|
|
|
common.maskLayerChild() = NULL;
|
|
|
|
}
|
|
|
|
common.maskLayerParent() = NULL;
|
2010-07-22 01:17:33 +04:00
|
|
|
attrs.specific() = null_t();
|
|
|
|
mutant->FillSpecificAttributes(attrs.specific());
|
|
|
|
|
|
|
|
mTxn->AddEdit(OpSetLayerAttributes(NULL, Shadow(shadow), attrs));
|
|
|
|
}
|
|
|
|
|
2010-11-09 05:49:00 +03:00
|
|
|
AutoInfallibleTArray<Edit, 10> cset;
|
2010-09-16 01:03:13 +04:00
|
|
|
size_t nCsets = mTxn->mCset.size() + mTxn->mPaints.size();
|
|
|
|
NS_ABORT_IF_FALSE(nCsets > 0, "should have bailed by now");
|
|
|
|
|
|
|
|
cset.SetCapacity(nCsets);
|
2010-09-20 23:40:30 +04:00
|
|
|
if (!mTxn->mCset.empty()) {
|
|
|
|
cset.AppendElements(&mTxn->mCset.front(), mTxn->mCset.size());
|
|
|
|
}
|
2010-09-16 01:03:13 +04:00
|
|
|
// Paints after non-paint ops, including attribute changes. See
|
|
|
|
// above.
|
2010-09-20 23:40:30 +04:00
|
|
|
if (!mTxn->mPaints.empty()) {
|
|
|
|
cset.AppendElements(&mTxn->mPaints.front(), mTxn->mPaints.size());
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2012-07-24 23:01:09 +04:00
|
|
|
TargetConfig targetConfig(mTxn->mTargetBounds, mTxn->mTargetRotation);
|
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
MOZ_LAYERS_LOG(("[LayersForwarder] syncing before send..."));
|
|
|
|
PlatformSyncBeforeUpdate();
|
|
|
|
|
2012-05-01 23:23:39 +04:00
|
|
|
if (mTxn->mSwapRequired) {
|
|
|
|
MOZ_LAYERS_LOG(("[LayersForwarder] sending transaction..."));
|
|
|
|
RenderTraceScope rendertrace3("Forward Transaction", "000093");
|
2012-07-24 23:01:09 +04:00
|
|
|
if (!mShadowManager->SendUpdate(cset, targetConfig, mIsFirstPaint,
|
|
|
|
aReplies)) {
|
2012-05-01 23:23:39 +04:00
|
|
|
MOZ_LAYERS_LOG(("[LayersForwarder] WARNING: sending transaction failed!"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If we don't require a swap we can call SendUpdateNoSwap which
|
|
|
|
// assumes that aReplies is empty (DEBUG assertion)
|
|
|
|
MOZ_LAYERS_LOG(("[LayersForwarder] sending no swap transaction..."));
|
|
|
|
RenderTraceScope rendertrace3("Forward NoSwap Transaction", "000093");
|
2012-07-24 23:01:09 +04:00
|
|
|
if (!mShadowManager->SendUpdateNoSwap(cset, targetConfig, mIsFirstPaint)) {
|
2012-05-01 23:23:39 +04:00
|
|
|
MOZ_LAYERS_LOG(("[LayersForwarder] WARNING: sending transaction failed!"));
|
|
|
|
return false;
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
|
2012-03-12 19:50:15 +04:00
|
|
|
mIsFirstPaint = false;
|
2010-07-22 01:17:33 +04:00
|
|
|
MOZ_LAYERS_LOG(("[LayersForwarder] ... done"));
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
|
2012-06-01 16:42:36 +04:00
|
|
|
bool
|
|
|
|
ShadowLayerForwarder::ShadowDrawToTarget(gfxContext* aTarget) {
|
|
|
|
|
|
|
|
SurfaceDescriptor descriptorIn, descriptorOut;
|
|
|
|
AllocBuffer(aTarget->OriginalSurface()->GetSize(),
|
|
|
|
aTarget->OriginalSurface()->GetContentType(),
|
|
|
|
&descriptorIn);
|
|
|
|
if (!mShadowManager->SendDrawToSurface(descriptorIn, &descriptorOut)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-12 16:51:58 +04:00
|
|
|
nsRefPtr<gfxASurface> surface = OpenDescriptor(OPEN_READ_WRITE, descriptorOut);
|
2012-06-01 16:42:36 +04:00
|
|
|
aTarget->SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
aTarget->DrawSurface(surface, surface->GetSize());
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
surface = nullptr;
|
2012-06-01 16:42:36 +04:00
|
|
|
DestroySharedSurface(&descriptorOut);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-13 23:38:09 +04:00
|
|
|
SharedMemory::SharedMemoryType
|
2010-09-28 04:59:43 +04:00
|
|
|
OptimalShmemType()
|
|
|
|
{
|
|
|
|
#if defined(MOZ_PLATFORM_MAEMO) && defined(MOZ_HAVE_SHAREDMEMORYSYSV)
|
|
|
|
// Use SysV memory because maemo5 on the N900 only allots 64MB to
|
|
|
|
// /dev/shm, even though it has 1GB(!!) of system memory. Sys V shm
|
|
|
|
// is allocated from a different pool. We don't want an arbitrary
|
|
|
|
// cap that's much much lower than available memory on the memory we
|
|
|
|
// use for layers.
|
|
|
|
return SharedMemory::TYPE_SYSV;
|
|
|
|
#else
|
|
|
|
return SharedMemory::TYPE_BASIC;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-12-31 10:40:31 +03:00
|
|
|
ShadowLayerForwarder::AllocBuffer(const gfxIntSize& aSize,
|
|
|
|
gfxASurface::gfxContentType aContent,
|
|
|
|
gfxSharedImageSurface** aBuffer)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(HasShadowManager(), "no manager to forward to");
|
|
|
|
|
2010-09-28 04:59:43 +04:00
|
|
|
SharedMemory::SharedMemoryType shmemType = OptimalShmemType();
|
2012-05-26 08:38:17 +04:00
|
|
|
gfxASurface::gfxImageFormat format = gfxPlatform::GetPlatform()->OptimalFormatForContent(aContent);
|
2010-09-28 04:59:43 +04:00
|
|
|
|
2011-01-04 19:40:54 +03:00
|
|
|
nsRefPtr<gfxSharedImageSurface> back =
|
|
|
|
gfxSharedImageSurface::CreateUnsafe(mShadowManager, aSize, format, shmemType);
|
|
|
|
if (!back)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*aBuffer = nullptr;
|
2010-12-31 10:40:31 +03:00
|
|
|
back.swap(*aBuffer);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-12-31 10:40:31 +03:00
|
|
|
ShadowLayerForwarder::AllocBuffer(const gfxIntSize& aSize,
|
|
|
|
gfxASurface::gfxContentType aContent,
|
|
|
|
SurfaceDescriptor* aBuffer)
|
2012-07-12 16:51:57 +04:00
|
|
|
{
|
|
|
|
return AllocBufferWithCaps(aSize, aContent, DEFAULT_BUFFER_CAPS, aBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ShadowLayerForwarder::AllocBufferWithCaps(const gfxIntSize& aSize,
|
|
|
|
gfxASurface::gfxContentType aContent,
|
|
|
|
uint32_t aCaps,
|
|
|
|
SurfaceDescriptor* aBuffer)
|
2010-12-31 10:40:31 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool tryPlatformSurface = true;
|
2010-12-31 10:40:31 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
tryPlatformSurface = !PR_GetEnv("MOZ_LAYERS_FORCE_SHMEM_SURFACES");
|
|
|
|
#endif
|
|
|
|
if (tryPlatformSurface &&
|
2012-07-12 16:51:57 +04:00
|
|
|
PlatformAllocBuffer(aSize, aContent, aCaps, aBuffer)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-12-31 10:40:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<gfxSharedImageSurface> buffer;
|
|
|
|
if (!AllocBuffer(aSize, aContent,
|
|
|
|
getter_AddRefs(buffer)))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-12-31 10:40:31 +03:00
|
|
|
|
|
|
|
*aBuffer = buffer->GetShmem();
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-12-31 10:40:31 +03:00
|
|
|
}
|
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
/*static*/ already_AddRefed<gfxASurface>
|
2012-07-12 16:51:58 +04:00
|
|
|
ShadowLayerForwarder::OpenDescriptor(OpenMode aMode,
|
|
|
|
const SurfaceDescriptor& aSurface)
|
2010-09-14 09:23:08 +04:00
|
|
|
{
|
2012-07-12 16:51:58 +04:00
|
|
|
nsRefPtr<gfxASurface> surf = PlatformOpenDescriptor(aMode, aSurface);
|
2010-09-14 09:23:08 +04:00
|
|
|
if (surf) {
|
|
|
|
return surf.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aSurface.type()) {
|
|
|
|
case SurfaceDescriptor::TShmem: {
|
2011-01-04 19:40:54 +03:00
|
|
|
surf = gfxSharedImageSurface::Open(aSurface.get_Shmem());
|
2010-09-14 09:23:08 +04:00
|
|
|
return surf.forget();
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
NS_RUNTIMEABORT("unexpected SurfaceDescriptor type!");
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-09-14 09:23:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-12 16:51:58 +04:00
|
|
|
/*static*/ gfxContentType
|
|
|
|
ShadowLayerForwarder::GetDescriptorSurfaceContentType(
|
|
|
|
const SurfaceDescriptor& aDescriptor, OpenMode aMode,
|
|
|
|
gfxASurface** aSurface)
|
|
|
|
{
|
|
|
|
gfxContentType content;
|
|
|
|
if (PlatformGetDescriptorSurfaceContentType(aDescriptor, aMode,
|
|
|
|
&content, aSurface)) {
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<gfxASurface> surface = OpenDescriptor(aMode, aDescriptor);
|
|
|
|
content = surface->GetContentType();
|
|
|
|
*aSurface = surface.forget().get();
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ gfxIntSize
|
|
|
|
ShadowLayerForwarder::GetDescriptorSurfaceSize(
|
|
|
|
const SurfaceDescriptor& aDescriptor, OpenMode aMode,
|
|
|
|
gfxASurface** aSurface)
|
|
|
|
{
|
|
|
|
gfxIntSize size;
|
|
|
|
if (PlatformGetDescriptorSurfaceSize(aDescriptor, aMode, &size, aSurface)) {
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<gfxASurface> surface = OpenDescriptor(aMode, aDescriptor);
|
|
|
|
size = surface->GetSize();
|
|
|
|
*aSurface = surface.forget().get();
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void
|
|
|
|
ShadowLayerForwarder::CloseDescriptor(const SurfaceDescriptor& aDescriptor)
|
|
|
|
{
|
|
|
|
PlatformCloseDescriptor(aDescriptor);
|
|
|
|
// There's no "close" needed for Shmem surfaces.
|
|
|
|
}
|
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
// Destroy the Shmem SurfaceDescriptor |aSurface|.
|
|
|
|
template<class ShmemDeallocator>
|
|
|
|
static void
|
|
|
|
DestroySharedShmemSurface(SurfaceDescriptor* aSurface,
|
|
|
|
ShmemDeallocator* aDeallocator)
|
|
|
|
{
|
|
|
|
switch (aSurface->type()) {
|
|
|
|
case SurfaceDescriptor::TShmem: {
|
|
|
|
aDeallocator->DeallocShmem(aSurface->get_Shmem());
|
|
|
|
*aSurface = SurfaceDescriptor();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
NS_RUNTIMEABORT("unexpected SurfaceDescriptor type!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowLayerForwarder::DestroySharedSurface(SurfaceDescriptor* aSurface)
|
|
|
|
{
|
|
|
|
if (PlatformDestroySharedSurface(aSurface)) {
|
|
|
|
return;
|
|
|
|
}
|
2011-09-28 02:19:26 +04:00
|
|
|
if (aSurface->type() == SurfaceDescriptor::TShmem) {
|
|
|
|
DestroySharedShmemSurface(aSurface, mShadowManager);
|
|
|
|
}
|
2010-09-14 09:23:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
PLayerChild*
|
|
|
|
ShadowLayerForwarder::ConstructShadowFor(ShadowableLayer* aLayer)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(HasShadowManager(), "no manager to forward to");
|
|
|
|
return mShadowManager->SendPLayerConstructor(new ShadowLayerChild(aLayer));
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
|
|
|
|
void
|
2010-09-25 02:41:31 +04:00
|
|
|
ShadowLayerManager::DestroySharedSurface(gfxSharedImageSurface* aSurface,
|
|
|
|
PLayersParent* aDeallocator)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
2010-09-25 02:41:31 +04:00
|
|
|
aDeallocator->DeallocShmem(aSurface->GetShmem());
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
void
|
2010-09-25 02:41:31 +04:00
|
|
|
ShadowLayerManager::DestroySharedSurface(SurfaceDescriptor* aSurface,
|
|
|
|
PLayersParent* aDeallocator)
|
2010-09-14 09:23:08 +04:00
|
|
|
{
|
|
|
|
if (PlatformDestroySharedSurface(aSurface)) {
|
|
|
|
return;
|
|
|
|
}
|
2011-09-28 02:19:26 +04:00
|
|
|
if (aSurface->type() == SurfaceDescriptor::TShmem) {
|
|
|
|
DestroySharedShmemSurface(aSurface, aDeallocator);
|
|
|
|
}
|
2010-09-14 09:23:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if !defined(MOZ_HAVE_PLATFORM_SPECIFIC_LAYER_BUFFERS)
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-12-31 10:40:31 +03:00
|
|
|
ShadowLayerForwarder::PlatformAllocBuffer(const gfxIntSize&,
|
|
|
|
gfxASurface::gfxContentType,
|
2012-07-12 16:51:57 +04:00
|
|
|
uint32_t,
|
2010-12-31 10:40:31 +03:00
|
|
|
SurfaceDescriptor*)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-12-31 10:40:31 +03:00
|
|
|
}
|
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
/*static*/ already_AddRefed<gfxASurface>
|
2012-07-12 16:51:58 +04:00
|
|
|
ShadowLayerForwarder::PlatformOpenDescriptor(OpenMode,
|
|
|
|
const SurfaceDescriptor&)
|
2010-09-14 09:23:08 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-09-14 09:23:08 +04:00
|
|
|
}
|
|
|
|
|
2012-07-12 16:51:58 +04:00
|
|
|
/*static*/ bool
|
|
|
|
ShadowLayerForwarder::PlatformCloseDescriptor(const SurfaceDescriptor&)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ bool
|
|
|
|
ShadowLayerForwarder::PlatformGetDescriptorSurfaceContentType(
|
|
|
|
const SurfaceDescriptor&,
|
|
|
|
OpenMode,
|
|
|
|
gfxContentType*,
|
|
|
|
gfxASurface**)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ bool
|
|
|
|
ShadowLayerForwarder::PlatformGetDescriptorSurfaceSize(
|
|
|
|
const SurfaceDescriptor&,
|
|
|
|
OpenMode,
|
|
|
|
gfxIntSize*,
|
|
|
|
gfxASurface**)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-09-14 09:23:08 +04:00
|
|
|
ShadowLayerForwarder::PlatformDestroySharedSurface(SurfaceDescriptor*)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-09-14 09:23:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void
|
|
|
|
ShadowLayerForwarder::PlatformSyncBeforeUpdate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-09-14 09:23:08 +04:00
|
|
|
ShadowLayerManager::PlatformDestroySharedSurface(SurfaceDescriptor*)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-09-14 09:23:08 +04:00
|
|
|
}
|
|
|
|
|
2012-07-24 03:58:37 +04:00
|
|
|
/*static*/ already_AddRefed<TextureImage>
|
|
|
|
ShadowLayerManager::OpenDescriptorForDirectTexturing(GLContext*,
|
|
|
|
const SurfaceDescriptor&,
|
|
|
|
GLenum)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-07-24 03:58:37 +04:00
|
|
|
}
|
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
/*static*/ void
|
|
|
|
ShadowLayerManager::PlatformSyncBeforeReplyUpdate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !defined(MOZ_HAVE_PLATFORM_SPECIFIC_LAYER_BUFFERS)
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-04-21 01:45:57 +04:00
|
|
|
IsSurfaceDescriptorValid(const SurfaceDescriptor& aSurface)
|
|
|
|
{
|
|
|
|
return SurfaceDescriptor::T__None != aSurface.type();
|
|
|
|
}
|
|
|
|
|
2012-07-12 16:51:58 +04:00
|
|
|
AutoOpenSurface::AutoOpenSurface(OpenMode aMode,
|
|
|
|
const SurfaceDescriptor& aDescriptor)
|
|
|
|
: mDescriptor(aDescriptor)
|
|
|
|
, mMode(aMode)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsSurfaceDescriptorValid(mDescriptor));
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoOpenSurface::~AutoOpenSurface()
|
|
|
|
{
|
|
|
|
if (mSurface) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mSurface = nullptr;
|
2012-07-12 16:51:58 +04:00
|
|
|
ShadowLayerForwarder::CloseDescriptor(mDescriptor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxContentType
|
|
|
|
AutoOpenSurface::ContentType()
|
|
|
|
{
|
|
|
|
if (mSurface) {
|
|
|
|
return mSurface->GetContentType();
|
|
|
|
}
|
|
|
|
return ShadowLayerForwarder::GetDescriptorSurfaceContentType(
|
|
|
|
mDescriptor, mMode, getter_AddRefs(mSurface));
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxIntSize
|
|
|
|
AutoOpenSurface::Size()
|
|
|
|
{
|
|
|
|
if (mSurface) {
|
|
|
|
return mSurface->GetSize();
|
|
|
|
}
|
|
|
|
return ShadowLayerForwarder::GetDescriptorSurfaceSize(
|
|
|
|
mDescriptor, mMode, getter_AddRefs(mSurface));
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxASurface*
|
|
|
|
AutoOpenSurface::Get()
|
|
|
|
{
|
|
|
|
if (!mSurface) {
|
|
|
|
mSurface = ShadowLayerForwarder::OpenDescriptor(mMode, mDescriptor);
|
|
|
|
}
|
|
|
|
return mSurface.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxImageSurface*
|
|
|
|
AutoOpenSurface::GetAsImage()
|
|
|
|
{
|
|
|
|
if (!mSurfaceAsImage) {
|
|
|
|
mSurfaceAsImage = Get()->GetAsImageSurface();
|
|
|
|
}
|
|
|
|
return mSurfaceAsImage.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|