Remove GrContext from GrClipMaskCache
Review URL: https://codereview.chromium.org/1144013007
This commit is contained in:
parent
c4fba51ea6
commit
edd77a112d
@ -8,9 +8,9 @@
|
||||
|
||||
#include "GrClipMaskCache.h"
|
||||
|
||||
GrClipMaskCache::GrClipMaskCache()
|
||||
: fContext(NULL)
|
||||
, fStack(sizeof(GrClipStackFrame)) {
|
||||
GrClipMaskCache::GrClipMaskCache(GrResourceProvider* resourceProvider)
|
||||
: fStack(sizeof(GrClipStackFrame))
|
||||
, fResourceProvider(resourceProvider) {
|
||||
// We need an initial frame to capture the clip state prior to
|
||||
// any pushes
|
||||
SkNEW_PLACEMENT(fStack.push_back(), GrClipStackFrame);
|
||||
|
@ -8,7 +8,7 @@
|
||||
#ifndef GrClipMaskCache_DEFINED
|
||||
#define GrClipMaskCache_DEFINED
|
||||
|
||||
#include "GrContext.h"
|
||||
#include "GrResourceProvider.h"
|
||||
#include "SkClipStack.h"
|
||||
#include "SkTypes.h"
|
||||
|
||||
@ -20,10 +20,9 @@ class GrTexture;
|
||||
*/
|
||||
class GrClipMaskCache : SkNoncopyable {
|
||||
public:
|
||||
GrClipMaskCache();
|
||||
GrClipMaskCache(GrResourceProvider*);
|
||||
|
||||
~GrClipMaskCache() {
|
||||
|
||||
while (!fStack.empty()) {
|
||||
GrClipStackFrame* temp = (GrClipStackFrame*) fStack.back();
|
||||
temp->~GrClipStackFrame();
|
||||
@ -124,7 +123,7 @@ public:
|
||||
|
||||
GrClipStackFrame* back = (GrClipStackFrame*) fStack.back();
|
||||
|
||||
back->acquireMask(fContext, clipGenID, desc, bound);
|
||||
back->acquireMask(fResourceProvider, clipGenID, desc, bound);
|
||||
}
|
||||
|
||||
int getLastMaskWidth() const {
|
||||
@ -172,14 +171,6 @@ public:
|
||||
*bound = back->fLastBound;
|
||||
}
|
||||
|
||||
void setContext(GrContext* context) {
|
||||
fContext = context;
|
||||
}
|
||||
|
||||
GrContext* getContext() {
|
||||
return fContext;
|
||||
}
|
||||
|
||||
// TODO: Remove this when we hold cache keys instead of refs to textures.
|
||||
void purgeResources() {
|
||||
SkDeque::F2BIter iter(fStack);
|
||||
@ -197,7 +188,7 @@ private:
|
||||
this->reset();
|
||||
}
|
||||
|
||||
void acquireMask(GrContext* context,
|
||||
void acquireMask(GrResourceProvider* resourceProvider,
|
||||
int32_t clipGenID,
|
||||
const GrSurfaceDesc& desc,
|
||||
const SkIRect& bound) {
|
||||
@ -206,7 +197,7 @@ private:
|
||||
|
||||
// HACK: set the last param to true to indicate that this request is at
|
||||
// flush time and therefore we require a scratch texture with no pending IO operations.
|
||||
fLastMask.reset(context->textureProvider()->refScratchTexture(
|
||||
fLastMask.reset(resourceProvider->refScratchTexture(
|
||||
desc, GrTextureProvider::kApprox_ScratchTexMatch, /*flushing=*/true));
|
||||
|
||||
fLastBound = bound;
|
||||
@ -231,8 +222,8 @@ private:
|
||||
SkIRect fLastBound;
|
||||
};
|
||||
|
||||
GrContext* fContext;
|
||||
SkDeque fStack;
|
||||
SkDeque fStack;
|
||||
GrResourceProvider* fResourceProvider;
|
||||
|
||||
typedef SkNoncopyable INHERITED;
|
||||
};
|
||||
|
@ -77,6 +77,15 @@ bool path_needs_SW_renderer(GrContext* context,
|
||||
}
|
||||
}
|
||||
|
||||
GrClipMaskManager::GrClipMaskManager(GrClipTarget* clipTarget)
|
||||
: fCurrClipMaskType(kNone_ClipMaskType)
|
||||
, fAACache(clipTarget->getContext()->resourceProvider())
|
||||
, fClipTarget(clipTarget)
|
||||
, fClipMode(kIgnoreClip_StencilClipMode) {
|
||||
}
|
||||
|
||||
GrContext* GrClipMaskManager::getContext() { return fClipTarget->getContext(); }
|
||||
|
||||
/*
|
||||
* This method traverses the clip stack to see if the GrSoftwarePathRenderer
|
||||
* will be used on any element. If so, it returns true to indicate that the
|
||||
@ -1110,11 +1119,6 @@ void GrClipMaskManager::purgeResources() {
|
||||
fAACache.purgeResources();
|
||||
}
|
||||
|
||||
void GrClipMaskManager::setClipTarget(GrClipTarget* clipTarget) {
|
||||
fClipTarget = clipTarget;
|
||||
fAACache.setContext(clipTarget->getContext());
|
||||
}
|
||||
|
||||
void GrClipMaskManager::adjustPathStencilParams(const GrStencilAttachment* stencilAttachment,
|
||||
GrStencilSettings* settings) {
|
||||
if (stencilAttachment) {
|
||||
|
@ -8,7 +8,6 @@
|
||||
#define GrClipMaskManager_DEFINED
|
||||
|
||||
#include "GrClipMaskCache.h"
|
||||
#include "GrContext.h"
|
||||
#include "GrPipelineBuilder.h"
|
||||
#include "GrReducedClip.h"
|
||||
#include "GrStencil.h"
|
||||
@ -35,11 +34,7 @@ class SkPath;
|
||||
*/
|
||||
class GrClipMaskManager : SkNoncopyable {
|
||||
public:
|
||||
GrClipMaskManager()
|
||||
: fCurrClipMaskType(kNone_ClipMaskType)
|
||||
, fClipTarget(NULL)
|
||||
, fClipMode(kIgnoreClip_StencilClipMode) {
|
||||
}
|
||||
GrClipMaskManager(GrClipTarget* owner);
|
||||
|
||||
/**
|
||||
* Creates a clip mask if necessary as a stencil buffer or alpha texture
|
||||
@ -68,15 +63,13 @@ public:
|
||||
return kAlpha_ClipMaskType == fCurrClipMaskType;
|
||||
}
|
||||
|
||||
GrContext* getContext() {
|
||||
return fAACache.getContext();
|
||||
}
|
||||
|
||||
void setClipTarget(GrClipTarget*);
|
||||
|
||||
void adjustPathStencilParams(const GrStencilAttachment*, GrStencilSettings*);
|
||||
|
||||
private:
|
||||
inline GrContext* getContext();
|
||||
|
||||
/**
|
||||
* Informs the helper function adjustStencilParams() about how the stencil
|
||||
* buffer clip is being used.
|
||||
@ -190,7 +183,7 @@ private:
|
||||
} fCurrClipMaskType;
|
||||
|
||||
GrClipMaskCache fAACache; // cache for the AA path
|
||||
GrClipTarget* fClipTarget;
|
||||
GrClipTarget* fClipTarget; // This is our owning clip target.
|
||||
StencilClipMode fClipMode;
|
||||
|
||||
typedef SkNoncopyable INHERITED;
|
||||
|
@ -540,15 +540,25 @@ GrDrawTarget::PipelineInfo::PipelineInfo(GrPipelineBuilder* pipelineBuilder,
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
GrClipTarget::GrClipTarget(GrContext* context) : INHERITED(context) {
|
||||
fClipMaskManager.reset(SkNEW_ARGS(GrClipMaskManager, (this)));
|
||||
}
|
||||
|
||||
|
||||
bool GrClipTarget::setupClip(GrPipelineBuilder* pipelineBuilder,
|
||||
GrPipelineBuilder::AutoRestoreFragmentProcessors* arfp,
|
||||
GrPipelineBuilder::AutoRestoreStencil* ars,
|
||||
GrScissorState* scissorState,
|
||||
const SkRect* devBounds) {
|
||||
return fClipMaskManager.setupClipping(pipelineBuilder,
|
||||
return fClipMaskManager->setupClipping(pipelineBuilder,
|
||||
arfp,
|
||||
ars,
|
||||
scissorState,
|
||||
devBounds);
|
||||
}
|
||||
|
||||
void GrClipTarget::purgeResources() {
|
||||
// The clip mask manager can rebuild all its clip masks so just
|
||||
// get rid of them all.
|
||||
fClipMaskManager->purgeResources();
|
||||
};
|
||||
|
@ -329,10 +329,7 @@ private:
|
||||
*/
|
||||
class GrClipTarget : public GrDrawTarget {
|
||||
public:
|
||||
GrClipTarget(GrContext* context)
|
||||
: INHERITED(context) {
|
||||
fClipMaskManager.setClipTarget(this);
|
||||
}
|
||||
GrClipTarget(GrContext*);
|
||||
|
||||
/* Clip mask manager needs access to the context.
|
||||
* TODO we only need a very small subset of context in the CMM.
|
||||
@ -352,17 +349,13 @@ public:
|
||||
* Release any resources that are cached but not currently in use. This
|
||||
* is intended to give an application some recourse when resources are low.
|
||||
*/
|
||||
void purgeResources() override {
|
||||
// The clip mask manager can rebuild all its clip masks so just
|
||||
// get rid of them all.
|
||||
fClipMaskManager.purgeResources();
|
||||
};
|
||||
void purgeResources() override;
|
||||
|
||||
protected:
|
||||
GrClipMaskManager fClipMaskManager;
|
||||
SkAutoTDelete<GrClipMaskManager> fClipMaskManager;
|
||||
|
||||
private:
|
||||
GrClipMaskManager* clipMaskManager() override { return &fClipMaskManager; }
|
||||
GrClipMaskManager* clipMaskManager() override { return fClipMaskManager; }
|
||||
|
||||
virtual bool setupClip(GrPipelineBuilder*,
|
||||
GrPipelineBuilder::AutoRestoreFragmentProcessors*,
|
||||
|
@ -8,6 +8,7 @@
|
||||
#ifndef GrResourceProvider_DEFINED
|
||||
#define GrResourceProvider_DEFINED
|
||||
|
||||
#include "GrIndexBuffer.h"
|
||||
#include "GrTextureProvider.h"
|
||||
#include "GrPathRange.h"
|
||||
|
||||
|
@ -17,7 +17,7 @@ static const int Y_SIZE = 12;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// note: this is unused
|
||||
static GrTexture* createTexture(GrContext* context) {
|
||||
static GrTexture* create_texture(GrContext* context) {
|
||||
unsigned char textureData[X_SIZE][Y_SIZE][4];
|
||||
|
||||
memset(textureData, 0, 4* X_SIZE * Y_SIZE);
|
||||
@ -133,11 +133,9 @@ static void check_empty_state(skiatest::Reporter* reporter,
|
||||
static void test_cache(skiatest::Reporter* reporter, GrContext* context) {
|
||||
|
||||
if (false) { // avoid bit rot, suppress warning
|
||||
createTexture(context);
|
||||
create_texture(context);
|
||||
}
|
||||
GrClipMaskCache cache;
|
||||
|
||||
cache.setContext(context);
|
||||
GrClipMaskCache cache(context->resourceProvider());
|
||||
|
||||
// check initial state
|
||||
check_empty_state(reporter, cache);
|
||||
|
Loading…
Reference in New Issue
Block a user