diff options
author | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-08-27 12:53:13 +0000 |
---|---|---|
committer | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-08-27 12:53:13 +0000 |
commit | a04e8e842450e606dd938ddae17857849bd504d4 (patch) | |
tree | 5378470c55006b5e88dc22959280049c2fe77b5c /include | |
parent | b7b5d93359fdd3c5b2c48be7c5bbc4c978538af5 (diff) |
Do premul and r/b swap conversions in a custom effect
Review URL: https://codereview.appspot.com/6473060/
git-svn-id: http://skia.googlecode.com/svn/trunk@5284 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include')
-rw-r--r-- | include/gpu/GrContext.h | 67 | ||||
-rw-r--r-- | include/gpu/GrSamplerState.h | 19 |
2 files changed, 61 insertions, 25 deletions
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index 8ee326c974..7ee1dd3e8b 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -609,12 +609,13 @@ public: class AutoRenderTarget : ::GrNoncopyable { public: AutoRenderTarget(GrContext* context, GrRenderTarget* target) { - fContext = NULL; fPrevTarget = context->getRenderTarget(); - if (fPrevTarget != target) { - context->setRenderTarget(target); - fContext = context; - } + context->setRenderTarget(target); + fContext = context; + } + AutoRenderTarget(GrContext* context) { + fPrevTarget = context->getRenderTarget(); + fContext = context; } ~AutoRenderTarget() { if (fContext) { @@ -631,14 +632,31 @@ public: */ class AutoMatrix : GrNoncopyable { public: + enum InitialMatrix { + kPreserve_InitialMatrix, + kIdentity_InitialMatrix, + }; + AutoMatrix() : fContext(NULL) {} - AutoMatrix(GrContext* ctx) : fContext(ctx) { + + AutoMatrix(GrContext* ctx, InitialMatrix initialState) : fContext(ctx) { fMatrix = ctx->getMatrix(); + switch (initialState) { + case kPreserve_InitialMatrix: + break; + case kIdentity_InitialMatrix: + ctx->setMatrix(GrMatrix::I()); + break; + default: + GrCrash("Unexpected initial matrix state"); + } } + AutoMatrix(GrContext* ctx, const GrMatrix& matrix) : fContext(ctx) { fMatrix = ctx->getMatrix(); ctx->setMatrix(matrix); } + void set(GrContext* ctx) { if (NULL != fContext) { fContext->setMatrix(fMatrix); @@ -646,6 +664,7 @@ public: fMatrix = ctx->getMatrix(); fContext = ctx; } + void set(GrContext* ctx, const GrMatrix& matrix) { if (NULL != fContext) { fContext->setMatrix(fMatrix); @@ -654,6 +673,7 @@ public: ctx->setMatrix(matrix); fContext = ctx; } + ~AutoMatrix() { if (NULL != fContext) { fContext->setMatrix(fMatrix); @@ -667,6 +687,21 @@ public: class AutoClip : GrNoncopyable { public: + // This enum exists to require a caller of the constructor to acknowledge that the clip will + // initially be wide open. It also could be extended if there are other desirable initial + // clip states. + enum InitialClip { + kWideOpen_InitialClip, + }; + + AutoClip(GrContext* context, InitialClip initialState) { + GrAssert(kWideOpen_InitialClip == initialState); + fOldClip = context->getClip(); + fNewClipData.fClipStack = &fNewClipStack; + context->setClip(&fNewClipData); + fContext = context; + } + AutoClip(GrContext* context, const GrRect& newClipRect) : fContext(context) , fNewClipStack(newClipRect) { @@ -689,6 +724,19 @@ public: GrClipData fNewClipData; }; + class AutoWideOpenIdentityDraw { + public: + AutoWideOpenIdentityDraw(GrContext* ctx, GrRenderTarget* rt) + : fAutoClip(ctx, AutoClip::kWideOpen_InitialClip) + , fAutoRT(ctx, rt) + , fAutoMatrix(ctx, AutoMatrix::kIdentity_InitialMatrix) { + } + private: + AutoClip fAutoClip; + AutoRenderTarget fAutoRT; + AutoMatrix fAutoMatrix; + }; + /////////////////////////////////////////////////////////////////////////// // Functions intended for internal use only. GrGpu* getGpu() { return fGpu; } @@ -742,6 +790,10 @@ private: GrAARectRenderer* fAARectRenderer; + bool fDidTestPMConversions; + int fPMToUPMConversion; + int fUPMToPMConversion; + GrContext(GrGpu* gpu); void setupDrawBuffer(); @@ -771,6 +823,9 @@ private: // for use with textures released from an GrAutoScratchTexture. void addExistingTextureToCache(GrTexture* texture); + GrCustomStage* createPMToUPMEffect(GrTexture* texture, bool swapRAndB); + GrCustomStage* createUPMToPMEffect(GrTexture* texture, bool swapRAndB); + typedef GrRefCnt INHERITED; }; diff --git a/include/gpu/GrSamplerState.h b/include/gpu/GrSamplerState.h index 12c0937dfd..e8182f9787 100644 --- a/include/gpu/GrSamplerState.h +++ b/include/gpu/GrSamplerState.h @@ -121,7 +121,6 @@ public: // memcpy() breaks refcounting fTextureParams = s.fTextureParams; fMatrix = s.fMatrix; - fSwapRAndB = s.fSwapRAndB; GrSafeAssign(fCustomStage, s.fCustomStage); @@ -129,8 +128,6 @@ public: } const GrMatrix& getMatrix() const { return fMatrix; } - bool swapsRAndB() const { return fSwapRAndB; } - bool premultiply() const { return fPremultiply; } GrTextureParams* textureParams() { return &fTextureParams; } const GrTextureParams& getTextureParams() const { return fTextureParams; } @@ -141,18 +138,6 @@ public: GrMatrix* matrix() { return &fMatrix; } /** - * Swaps the R and B components when reading from the texture. Has no effect - * if the texture is alpha only. - */ - void setRAndBSwap(bool swap) { fSwapRAndB = swap; } - - /** - * If the texture is RGBA/BGRA 8888 config then its rgb components will be - * multiplied by its a component after the texture read. - **/ - void setPremultiply(bool premul) { fPremultiply = premul; } - - /** * Multiplies the current sampler matrix a matrix * * After this call M' = M*m where M is the old matrix, m is the parameter @@ -169,8 +154,6 @@ public: const GrMatrix& matrix) { fTextureParams.reset(tileXAndY, filter); fMatrix = matrix; - fSwapRAndB = false; - fPremultiply = false; GrSafeSetNull(fCustomStage); } void reset(SkShader::TileMode wrapXAndY, bool filter) { @@ -191,8 +174,6 @@ public: private: GrTextureParams fTextureParams; - bool fSwapRAndB; - bool fPremultiply; // temporary, will be replaced soon by a custom stage. GrMatrix fMatrix; GrCustomStage* fCustomStage; |