Plumbing to propagate save & restore from SkCanvas down to GrContext & lower

http://codereview.appspot.com/6203067/



git-svn-id: http://skia.googlecode.com/svn/trunk@4034 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
robertphillips@google.com 2012-05-23 11:44:08 +00:00
parent af46cff4ee
commit 49d9fd5fdb
11 changed files with 86 additions and 11 deletions

View File

@ -351,6 +351,20 @@ private:
friend class SkDeviceFilteredPaint;
friend class DeviceImageFilterProxy;
/**
* postSave is called by SkCanvas to inform the device that it has
* just completed a save operation. This allows derived
* classes to initialize their state-dependent caches.
*/
virtual void postSave() {};
/**
* preRestore is called by SkCanvas right before it executes a restore
* operation. As the partner of postSave, it allows
* derived classes to clear their state-dependent caches.
*/
virtual void preRestore() {};
// just called by SkCanvas when built as a layer
void setOrigin(int x, int y) { fOrigin.set(x, y); }
// just called by SkCanvas for saveLayer

View File

@ -680,6 +680,18 @@ public:
void unlockStencilBuffer(GrResourceEntry* sbEntry);
GrStencilBuffer* findStencilBuffer(int width, int height, int sampleCnt);
/*
* postClipPush acts as a hint to this and lower-level classes (e.g.,
* GrGpu) that the clip stack has changed.
*/
virtual void postClipPush();
/*
* preClipPop acts as a hint that the clip stack has been restored to an
* earlier state.
*/
virtual void preClipPop();
GrPathRenderer* getPathRenderer(const SkPath& path,
GrPathFill fill,
const GrDrawTarget* target,

View File

@ -146,11 +146,18 @@ private:
// used by createCompatibleDevice
SkGpuDevice(GrContext*, GrTexture* texture, TexCache, bool needClear);
// override from SkDevice
// overrides from SkDevice
virtual void postSave() SK_OVERRIDE {
fContext->postClipPush();
}
virtual void preRestore() SK_OVERRIDE {
fContext->preClipPop();
}
virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config config,
int width, int height,
bool isOpaque,
Usage usage);
Usage usage) SK_OVERRIDE;
SkDrawProcs* initDrawForText(GrTextContext*);
bool bindDeviceAsTexture(GrPaint* paint);

View File

@ -700,6 +700,14 @@ int SkCanvas::internalSave(SaveFlags flags) {
fClipStack.save();
SkASSERT(fClipStack.getSaveCount() == this->getSaveCount() - 1);
for (DeviceCM* curLayer = fMCRec->fTopLayer;
curLayer;
curLayer = curLayer->fNext) {
if (NULL != curLayer->fDevice) {
curLayer->fDevice->postSave();
}
}
return saveCount;
}
@ -870,6 +878,14 @@ void SkCanvas::restore() {
void SkCanvas::internalRestore() {
SkASSERT(fMCStack.count() != 0);
for (DeviceCM* curLayer = fMCRec->fTopLayer;
curLayer;
curLayer = curLayer->fNext) {
if (NULL != curLayer->fDevice) {
curLayer->fDevice->preRestore();
}
}
fDeviceCMDirty = true;
fLocalBoundsCompareTypeDirty = true;
fLocalBoundsCompareTypeDirtyBW = true;

View File

@ -300,6 +300,17 @@ public:
fClipMaskInStencil = false;
}
void postClipPush() {
// TODO: make sure that, if the clip stack is unaltered, the
// prior clip mask is reused (i.e., a push w/ no change to the
// clip stack)
fAACache.push();
}
void preClipPop() {
fAACache.pop();
}
void setContext(GrContext* context) {
fAACache.setContext(context);
}

View File

@ -2216,4 +2216,12 @@ GrTexture* GrContext::applyMorphology(GrTexture* srcTexture,
return srcTexture;
}
void GrContext::postClipPush() {
fGpu->postClipPush();
}
void GrContext::preClipPop() {
fGpu->preClipPop();
};
///////////////////////////////////////////////////////////////////////////////

View File

@ -1103,9 +1103,6 @@ GrVertexLayout GrDrawTarget::GetRectVertexLayout(StageMask stageMask,
return layout;
}
void GrDrawTarget::clipWillBeSet(const GrClip& clip) {
}
void GrDrawTarget::SetRectVertices(const GrRect& rect,
const GrMatrix* matrix,
const GrRect* srcRects[],

View File

@ -190,6 +190,9 @@ public:
return 1 << (stage + (texCoordIdx * GrDrawState::kNumStages));
}
virtual void postClipPush() {};
virtual void preClipPop() {};
private:
static const int TEX_COORD_BIT_CNT = GrDrawState::kNumStages *
GrDrawState::kMaxTexCoords;
@ -1041,7 +1044,7 @@ protected:
int vertexCount) = 0;
// subclass overrides to be notified when clip is set. Must call
// INHERITED::clipwillBeSet
virtual void clipWillBeSet(const GrClip& clip);
virtual void clipWillBeSet(const GrClip& clip) {}
// Helpers for drawRect, protected so subclasses that override drawRect
// can use them.

View File

@ -365,6 +365,13 @@ public:
// clipping.
};
virtual void postClipPush() SK_OVERRIDE {
fClipMaskManager.postClipPush();
}
virtual void preClipPop() SK_OVERRIDE {
fClipMaskManager.preClipPop();
}
protected:
// prepares clip flushes gpu state before a draw
bool setupClipAndFlushState(GrPrimitiveType type);

View File

@ -223,7 +223,7 @@ void GrInOrderDrawBuffer::drawIndexedInstances(GrPrimitiveType type,
bool clipChanged = this->needsNewClip();
bool stateChanged = this->needsNewState();
if (clipChanged) {
this->pushClip();
this->storeClip();
}
if (stateChanged) {
this->pushState();
@ -342,7 +342,7 @@ void GrInOrderDrawBuffer::onDrawIndexed(GrPrimitiveType primitiveType,
draw.fClipChanged = this->needsNewClip();
if (draw.fClipChanged) {
this->pushClip();
this->storeClip();
}
draw.fStateChanged = this->needsNewState();
@ -409,7 +409,7 @@ void GrInOrderDrawBuffer::onDrawNonIndexed(GrPrimitiveType primitiveType,
draw.fClipChanged = this->needsNewClip();
if (draw.fClipChanged) {
this->pushClip();
this->storeClip();
}
draw.fStateChanged = this->needsNewState();
@ -801,7 +801,7 @@ bool GrInOrderDrawBuffer::needsNewClip() const {
return false;
}
void GrInOrderDrawBuffer::pushClip() {
void GrInOrderDrawBuffer::storeClip() {
fClips.push_back() = fClip;
fClipSet = false;
}

View File

@ -167,7 +167,7 @@ private:
bool needsNewClip() const;
void pushState();
void pushClip();
void storeClip();
// call this to invalidate the tracking data that is used to concatenate
// multiple draws into a single draw.