Bug 1034528, part 1 - Get rid of gfxCachedTempSurface and the Thebes backed gfxContext that it creates. r=Bas

This commit is contained in:
Jonathan Watt 2014-07-07 09:05:15 +01:00
parent 4994f97eec
commit 008f42576c
6 changed files with 4 additions and 228 deletions

View File

@ -18,7 +18,6 @@
#include "basic/BasicLayers.h" // for BasicLayerManager, etc
#include "gfx3DMatrix.h" // for gfx3DMatrix
#include "gfxASurface.h" // for gfxASurface, etc
#include "gfxCachedTempSurface.h" // for gfxCachedTempSurface
#include "gfxColor.h" // for gfxRGBA
#include "gfxContext.h" // for gfxContext, etc
#include "gfxImageSurface.h" // for gfxImageSurface
@ -98,7 +97,8 @@ BasicLayerManager::PushGroupForLayer(gfxContext* aContext, Layer* aLayer,
// clipped precisely to the visible region.
*aNeedsClipToVisibleRegion = !didCompleteClip || aRegion.GetNumRects() > 1;
MOZ_ASSERT(!aContext->IsCairo());
result = PushGroupWithCachedSurface(aContext, gfxContentType::COLOR);
aContext->PushGroup(gfxContentType::COLOR);
result = aContext;
} else {
*aNeedsClipToVisibleRegion = false;
result = aContext;
@ -235,7 +235,6 @@ BasicLayerManager::BasicLayerManager(nsIWidget* aWidget) :
mPhase(PHASE_NONE),
mWidget(aWidget)
, mDoubleBuffering(BufferMode::BUFFER_NONE), mUsingDefaultTarget(false)
, mCachedSurfaceInUse(false)
, mTransactionIncomplete(false)
, mCompositorMightResample(false)
{
@ -247,7 +246,6 @@ BasicLayerManager::BasicLayerManager() :
mPhase(PHASE_NONE),
mWidget(nullptr)
, mDoubleBuffering(BufferMode::BUFFER_NONE), mUsingDefaultTarget(false)
, mCachedSurfaceInUse(false)
, mTransactionIncomplete(false)
{
MOZ_COUNT_CTOR(BasicLayerManager);
@ -286,53 +284,6 @@ BasicLayerManager::BeginTransaction()
BeginTransactionWithTarget(mDefaultTarget);
}
already_AddRefed<gfxContext>
BasicLayerManager::PushGroupWithCachedSurface(gfxContext *aTarget,
gfxContentType aContent)
{
nsRefPtr<gfxContext> ctx;
// We can't cache Azure DrawTargets at this point.
if (!mCachedSurfaceInUse && aTarget->IsCairo()) {
gfxContextMatrixAutoSaveRestore saveMatrix(aTarget);
aTarget->IdentityMatrix();
nsRefPtr<gfxASurface> currentSurf = aTarget->CurrentSurface();
gfxRect clip = aTarget->GetClipExtents();
clip.RoundOut();
ctx = mCachedSurface.Get(aContent, clip, currentSurf);
if (ctx) {
mCachedSurfaceInUse = true;
/* Align our buffer for the original surface */
ctx->SetMatrix(saveMatrix.Matrix());
return ctx.forget();
}
}
ctx = aTarget;
ctx->PushGroup(aContent);
return ctx.forget();
}
void
BasicLayerManager::PopGroupToSourceWithCachedSurface(gfxContext *aTarget, gfxContext *aPushed)
{
if (!aTarget)
return;
if (aTarget->IsCairo()) {
nsRefPtr<gfxASurface> current = aPushed->CurrentSurface();
if (mCachedSurface.IsSurface(current)) {
gfxContextMatrixAutoSaveRestore saveMatrix(aTarget);
aTarget->IdentityMatrix();
aTarget->SetSource(current);
mCachedSurfaceInUse = false;
return;
}
}
aTarget->PopGroupToSource();
}
void
BasicLayerManager::BeginTransactionWithTarget(gfxContext* aTarget)
{
@ -924,7 +875,7 @@ BasicLayerManager::PaintLayer(gfxContext* aTarget,
nsRefPtr<gfxContext> groupTarget = PushGroupForLayer(aTarget, aLayer, aLayer->GetEffectiveVisibleRegion(),
&needsClipToVisibleRegion);
PaintSelfOrChildren(paintLayerContext, groupTarget);
PopGroupToSourceWithCachedSurface(aTarget, groupTarget);
aTarget->PopGroupToSource();
FlushGroup(paintLayerContext, needsClipToVisibleRegion);
} else {
PaintSelfOrChildren(paintLayerContext, aTarget);
@ -988,7 +939,6 @@ BasicLayerManager::ClearCachedResources(Layer* aSubtree)
} else if (mRoot) {
ClearLayer(mRoot);
}
mCachedSurface.Expire();
}
void
BasicLayerManager::ClearLayer(Layer* aLayer)

View File

@ -9,7 +9,6 @@
#include <stdint.h> // for INT32_MAX, int32_t
#include "Layers.h" // for Layer (ptr only), etc
#include "gfxTypes.h"
#include "gfxCachedTempSurface.h" // for gfxCachedTempSurface
#include "gfxContext.h" // for gfxContext
#include "mozilla/Attributes.h" // for MOZ_OVERRIDE
#include "mozilla/WidgetUtils.h" // for ScreenRotation
@ -136,9 +135,6 @@ public:
already_AddRefed<gfxContext> PushGroupForLayer(gfxContext* aContext, Layer* aLayer,
const nsIntRegion& aRegion,
bool* aNeedsClipToVisibleRegion);
already_AddRefed<gfxContext> PushGroupWithCachedSurface(gfxContext *aTarget,
gfxContentType aContent);
void PopGroupToSourceWithCachedSurface(gfxContext *aTarget, gfxContext *aPushed);
virtual bool IsCompositingCheap() { return false; }
virtual int32_t GetMaxTextureSize() const { return INT32_MAX; }
@ -186,12 +182,8 @@ protected:
// Image factory we use.
nsRefPtr<ImageFactory> mFactory;
// Cached surface for double buffering
gfxCachedTempSurface mCachedSurface;
BufferMode mDoubleBuffering;
bool mUsingDefaultTarget;
bool mCachedSurfaceInUse;
bool mTransactionIncomplete;
bool mCompositorMightResample;
};

View File

@ -93,7 +93,7 @@ BasicThebesLayer::PaintThebes(gfxContext* aContext,
SetAntialiasingFlags(this, groupContext);
aCallback(this, groupContext, toDraw, DrawRegionClip::CLIP_NONE, nsIntRegion(), aCallbackData);
if (needsGroup) {
BasicManager()->PopGroupToSourceWithCachedSurface(aContext, groupContext);
aContext->PopGroupToSource();
if (needsClipToVisibleRegion) {
gfxUtils::ClipToRegion(aContext, toDraw);
}

View File

@ -1,106 +0,0 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* 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/. */
#include "gfxCachedTempSurface.h"
#include "gfxContext.h"
#include "mozilla/Attributes.h"
class CachedSurfaceExpirationTracker MOZ_FINAL :
public nsExpirationTracker<gfxCachedTempSurface,2> {
public:
// With K = 2, this means that surfaces will be released when they are not
// used for 1-2 seconds.
enum { TIMEOUT_MS = 1000 };
CachedSurfaceExpirationTracker()
: nsExpirationTracker<gfxCachedTempSurface,2>(TIMEOUT_MS) {}
~CachedSurfaceExpirationTracker() {
AgeAllGenerations();
}
virtual void NotifyExpired(gfxCachedTempSurface* aSurface) {
RemoveObject(aSurface);
aSurface->Expire();
}
static void MarkSurfaceUsed(gfxCachedTempSurface* aSurface)
{
if (aSurface->GetExpirationState()->IsTracked()) {
sExpirationTracker->MarkUsed(aSurface);
return;
}
if (!sExpirationTracker) {
sExpirationTracker = new CachedSurfaceExpirationTracker();
}
sExpirationTracker->AddObject(aSurface);
}
static void RemoveSurface(gfxCachedTempSurface* aSurface)
{
if (!sExpirationTracker)
return;
if (aSurface->GetExpirationState()->IsTracked()) {
sExpirationTracker->RemoveObject(aSurface);
}
if (sExpirationTracker->IsEmpty()) {
delete sExpirationTracker;
sExpirationTracker = nullptr;
}
}
private:
static CachedSurfaceExpirationTracker* sExpirationTracker;
};
CachedSurfaceExpirationTracker*
CachedSurfaceExpirationTracker::sExpirationTracker = nullptr;
gfxCachedTempSurface::~gfxCachedTempSurface()
{
CachedSurfaceExpirationTracker::RemoveSurface(this);
}
already_AddRefed<gfxContext>
gfxCachedTempSurface::Get(gfxContentType aContentType,
const gfxRect& aRect,
gfxASurface* aSimilarTo)
{
if (mSurface) {
/* Verify the current buffer is valid for this purpose */
if (mSize.width < aRect.width || mSize.height < aRect.height
|| mSurface->GetContentType() != aContentType
|| mType != aSimilarTo->GetType()) {
mSurface = nullptr;
}
}
bool cleared = false;
if (!mSurface) {
mSize = gfxIntSize(int32_t(ceil(aRect.width)), int32_t(ceil(aRect.height)));
mSurface = aSimilarTo->CreateSimilarSurface(aContentType, mSize);
if (!mSurface)
return nullptr;
cleared = true;
mType = aSimilarTo->GetType();
}
mSurface->SetDeviceOffset(-aRect.TopLeft());
nsRefPtr<gfxContext> ctx = new gfxContext(mSurface);
ctx->Rectangle(aRect);
ctx->Clip();
if (!cleared && aContentType != gfxContentType::COLOR) {
ctx->SetOperator(gfxContext::OPERATOR_CLEAR);
ctx->Paint();
ctx->SetOperator(gfxContext::OPERATOR_OVER);
}
CachedSurfaceExpirationTracker::MarkSurfaceUsed(this);
return ctx.forget();
}

View File

@ -1,58 +0,0 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* 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_CACHED_TEMP_SURFACE_H
#define GFX_CACHED_TEMP_SURFACE_H
#include "gfxASurface.h"
#include "nsExpirationTracker.h"
#include "nsSize.h"
class gfxContext;
/**
* This class can be used to cache double-buffering back surfaces.
*
* Large resource allocations may have an overhead that can be avoided by
* caching. Caching also alows the system to use history in deciding whether
* to manage the surfaces in video or system memory.
*
* However, because we don't want to set aside megabytes of unused resources
* unncessarily, these surfaces are released on a timer.
*/
class gfxCachedTempSurface {
public:
/**
* Returns a context for a surface that can be efficiently copied to
* |aSimilarTo|.
*
* When |aContentType| has an alpha component, the surface will be cleared.
* For opaque surfaces, the initial surface contents are undefined.
* When |aContentType| differs in different invocations this is handled
* appropriately, creating a new surface if necessary.
*
* Because the cached surface may have been created during a previous
* invocation, this will not be efficient if the new |aSimilarTo| has a
* different format, size, or gfxSurfaceType.
*/
already_AddRefed<gfxContext> Get(gfxContentType aContentType,
const gfxRect& aRect,
gfxASurface* aSimilarTo);
void Expire() { mSurface = nullptr; }
nsExpirationState* GetExpirationState() { return &mExpirationState; }
~gfxCachedTempSurface();
bool IsSurface(gfxASurface* aSurface) { return mSurface == aSurface; }
private:
nsRefPtr<gfxASurface> mSurface;
gfxIntSize mSize;
nsExpirationState mExpirationState;
gfxSurfaceType mType;
};
#endif /* GFX_CACHED_TEMP_SURFACE_H */

View File

@ -12,7 +12,6 @@ EXPORTS += [
'gfxASurface.h',
'gfxBaseSharedMemorySurface.h',
'gfxBlur.h',
'gfxCachedTempSurface.h',
'gfxColor.h',
'gfxContext.h',
'gfxDrawable.h',
@ -223,7 +222,6 @@ UNIFIED_SOURCES += [
'gfxAlphaRecovery.cpp',
'gfxBaseSharedMemorySurface.cpp',
'gfxBlur.cpp',
'gfxCachedTempSurface.cpp',
'gfxContext.cpp',
'gfxFontFeatures.cpp',
'gfxFontInfoLoader.cpp',