2012-04-16 16:02:45 -07: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/. */
|
|
|
|
|
|
|
|
#ifndef GFX_BASICTILEDTHEBESLAYER_H
|
|
|
|
#define GFX_BASICTILEDTHEBESLAYER_H
|
|
|
|
|
|
|
|
#include "TiledLayerBuffer.h"
|
|
|
|
#include "gfxReusableSurfaceWrapper.h"
|
|
|
|
#include "mozilla/layers/ShadowLayers.h"
|
|
|
|
#include "BasicLayers.h"
|
|
|
|
#include "BasicImplData.h"
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represent a single tile in tiled buffer. It's backed
|
|
|
|
* by a gfxReusableSurfaceWrapper that implements a
|
|
|
|
* copy-on-write mechanism while locked. The tile should be
|
|
|
|
* locked before being sent to the compositor and unlocked
|
|
|
|
* as soon as it is uploaded to prevent a copy.
|
|
|
|
* Ideal place to store per tile debug information.
|
|
|
|
*/
|
|
|
|
struct BasicTiledLayerTile {
|
|
|
|
nsRefPtr<gfxReusableSurfaceWrapper> mSurface;
|
|
|
|
#ifdef GFX_TILEDLAYER_DEBUG_OVERLAY
|
|
|
|
TimeStamp mLastUpdate;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Placeholder
|
|
|
|
BasicTiledLayerTile()
|
|
|
|
: mSurface(NULL)
|
|
|
|
{}
|
|
|
|
explicit BasicTiledLayerTile(gfxImageSurface* aSurface)
|
|
|
|
: mSurface(new gfxReusableSurfaceWrapper(aSurface))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
BasicTiledLayerTile(const BasicTiledLayerTile& o) {
|
|
|
|
mSurface = o.mSurface;
|
|
|
|
#ifdef GFX_TILEDLAYER_DEBUG_OVERLAY
|
|
|
|
mLastUpdate = o.mLastUpdate;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
BasicTiledLayerTile& operator=(const BasicTiledLayerTile& o) {
|
|
|
|
if (this == &o) return *this;
|
|
|
|
mSurface = o.mSurface;
|
|
|
|
#ifdef GFX_TILEDLAYER_DEBUG_OVERLAY
|
|
|
|
mLastUpdate = o.mLastUpdate;
|
|
|
|
#endif
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
bool operator== (const BasicTiledLayerTile& o) const {
|
|
|
|
return mSurface == o.mSurface;
|
|
|
|
}
|
|
|
|
bool operator!= (const BasicTiledLayerTile& o) const {
|
|
|
|
return mSurface != o.mSurface;
|
|
|
|
}
|
|
|
|
void ReadUnlock() {
|
|
|
|
mSurface->ReadUnlock();
|
|
|
|
}
|
|
|
|
void ReadLock() {
|
|
|
|
mSurface->ReadLock();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class BasicTiledThebesLayer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provide an instance of TiledLayerBuffer backed by image surfaces.
|
|
|
|
* This buffer provides an implementation to ValidateTile using a
|
|
|
|
* thebes callback and can support painting using a single paint buffer
|
|
|
|
* which is much faster then painting directly into the tiles.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class BasicTiledLayerBuffer : public TiledLayerBuffer<BasicTiledLayerBuffer, BasicTiledLayerTile>
|
|
|
|
{
|
|
|
|
friend class TiledLayerBuffer<BasicTiledLayerBuffer, BasicTiledLayerTile>;
|
|
|
|
|
|
|
|
public:
|
2012-04-23 17:08:18 -07:00
|
|
|
BasicTiledLayerBuffer()
|
|
|
|
{}
|
|
|
|
|
2012-04-16 16:02:45 -07:00
|
|
|
void PaintThebes(BasicTiledThebesLayer* aLayer,
|
|
|
|
const nsIntRegion& aNewValidRegion,
|
|
|
|
const nsIntRegion& aPaintRegion,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
2012-03-18 16:02:38 -07:00
|
|
|
void* aCallbackData);
|
2012-04-16 16:02:45 -07:00
|
|
|
|
|
|
|
BasicTiledLayerTile GetPlaceholderTile() const {
|
|
|
|
return mPlaceholder;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReadUnlock() {
|
|
|
|
for (size_t i = 0; i < mRetainedTiles.Length(); i++) {
|
|
|
|
if (mRetainedTiles[i] == GetPlaceholderTile()) continue;
|
|
|
|
mRetainedTiles[i].ReadUnlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReadLock() {
|
|
|
|
for (size_t i = 0; i < mRetainedTiles.Length(); i++) {
|
|
|
|
if (mRetainedTiles[i] == GetPlaceholderTile()) continue;
|
|
|
|
mRetainedTiles[i].ReadLock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-06 11:02:10 -07:00
|
|
|
const gfxSize& GetResolution() { return mResolution; }
|
|
|
|
void SetResolution(const gfxSize& aResolution) { mResolution = aResolution; }
|
|
|
|
|
2012-04-16 16:02:45 -07:00
|
|
|
protected:
|
|
|
|
BasicTiledLayerTile ValidateTile(BasicTiledLayerTile aTile,
|
|
|
|
const nsIntPoint& aTileRect,
|
|
|
|
const nsIntRegion& dirtyRect);
|
|
|
|
|
|
|
|
// If this returns true, we perform the paint operation into a single large
|
|
|
|
// buffer and copy it out to the tiles instead of calling PaintThebes() on
|
|
|
|
// each tile individually. Somewhat surprisingly, this turns out to be faster
|
|
|
|
// on Android.
|
|
|
|
bool UseSinglePaintBuffer() { return true; }
|
|
|
|
|
|
|
|
void ReleaseTile(BasicTiledLayerTile aTile) { /* No-op. */ }
|
|
|
|
|
|
|
|
void SwapTiles(BasicTiledLayerTile& aTileA, BasicTiledLayerTile& aTileB) {
|
|
|
|
std::swap(aTileA, aTileB);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-04-16 16:04:24 -07:00
|
|
|
gfxASurface::gfxImageFormat GetFormat() const;
|
2012-04-16 16:02:45 -07:00
|
|
|
BasicTiledThebesLayer* mThebesLayer;
|
|
|
|
LayerManager::DrawThebesLayerCallback mCallback;
|
|
|
|
void* mCallbackData;
|
2012-07-06 11:02:10 -07:00
|
|
|
gfxSize mResolution;
|
2012-04-16 16:02:45 -07:00
|
|
|
|
|
|
|
// The buffer we use when UseSinglePaintBuffer() above is true.
|
|
|
|
nsRefPtr<gfxImageSurface> mSinglePaintBuffer;
|
|
|
|
nsIntPoint mSinglePaintBufferOffset;
|
|
|
|
|
|
|
|
BasicTiledLayerTile mPlaceholder;
|
|
|
|
|
|
|
|
BasicTiledLayerTile ValidateTileInternal(BasicTiledLayerTile aTile,
|
|
|
|
const nsIntPoint& aTileOrigin,
|
|
|
|
const nsIntRect& aDirtyRect);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An implementation of ThebesLayer that ONLY supports remote
|
|
|
|
* composition that is backed by tiles. This thebes layer implementation
|
|
|
|
* is better suited to mobile hardware to work around slow implementation
|
|
|
|
* of glTexImage2D (for OGL compositors), and restrait memory bandwidth.
|
|
|
|
*/
|
|
|
|
class BasicTiledThebesLayer : public ThebesLayer,
|
|
|
|
public BasicImplData,
|
|
|
|
public BasicShadowableLayer
|
|
|
|
{
|
|
|
|
typedef ThebesLayer Base;
|
|
|
|
|
|
|
|
public:
|
|
|
|
BasicTiledThebesLayer(BasicShadowLayerManager* const aManager)
|
|
|
|
: ThebesLayer(aManager, static_cast<BasicImplData*>(this))
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicTiledThebesLayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
~BasicTiledThebesLayer()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(BasicTiledThebesLayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Thebes Layer
|
|
|
|
virtual Layer* AsLayer() { return this; }
|
|
|
|
virtual void InvalidateRegion(const nsIntRegion& aRegion) {
|
2012-07-03 17:24:55 -07:00
|
|
|
mValidRegion.Sub(mValidRegion, aRegion);
|
2012-04-16 16:02:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Shadow methods
|
|
|
|
virtual void FillSpecificAttributes(SpecificLayerAttributes& aAttrs);
|
|
|
|
virtual ShadowableLayer* AsShadowableLayer() { return this; }
|
|
|
|
|
|
|
|
virtual void Disconnect()
|
|
|
|
{
|
|
|
|
BasicShadowableLayer::Disconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void PaintThebes(gfxContext* aContext,
|
Backout 61fd66629c4f, 7c8121f8d3af & 2a2e9cf8fd41 (bug 539356), e31a5e6545d3 (bug 761884), 85fa80bd9792, a284ccb25b83, 2865904db9fc, 34e07b09c426, e9b3d41e0360, cef00ebcd6c8, f943b729ac14 & 783f298401b6 (bug 539356), 330a086f1570 (bug 741682), d80219c8842c (bug 739671), e8c96b4fd4da, 313af486e68d, 0adc41ff56dc, 0cd288a38085, f1d43208825c, 4859876972f3, eec8ef3ebe48, f7f29fcd1845, 6079b229d306, f23c3a7e7ce0, 9824458a41e2 & 6748b5496059 (bug 539356) for mochitest-4 orange & talos regressions on multiple platforms
2012-06-11 02:08:32 -07:00
|
|
|
Layer* aMaskLayer,
|
2012-04-16 16:02:45 -07:00
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
|
|
|
void* aCallbackData,
|
|
|
|
ReadbackProcessor* aReadback);
|
|
|
|
|
|
|
|
private:
|
|
|
|
BasicShadowLayerManager* BasicManager()
|
|
|
|
{
|
|
|
|
return static_cast<BasicShadowLayerManager*>(mManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
// BasicImplData
|
|
|
|
virtual void
|
|
|
|
PaintBuffer(gfxContext* aContext,
|
|
|
|
const nsIntRegion& aRegionToDraw,
|
|
|
|
const nsIntRegion& aExtendedRegionToDraw,
|
|
|
|
const nsIntRegion& aRegionToInvalidate,
|
|
|
|
bool aDidSelfCopy,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
|
|
|
void* aCallbackData)
|
|
|
|
{ NS_RUNTIMEABORT("Not reached."); }
|
|
|
|
|
|
|
|
// Members
|
|
|
|
BasicTiledLayerBuffer mTiledBuffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // layers
|
|
|
|
} // mozilla
|
|
|
|
|
|
|
|
#endif
|