diff options
author | 2014-05-20 15:06:29 +0000 | |
---|---|---|
committer | 2014-05-20 15:06:29 +0000 | |
commit | 9e967ad6e54c1e2e5ffb9d6e9eb8414e6b36b0e3 (patch) | |
tree | 90ba2e173f0b2916fee8d8cf79bd4af51b42bf7d /src | |
parent | 28f070d2a492976d29e95ab724e7c423275616ec (diff) |
Preserve GrContext's matrix when calling SkShader::asNewEffect.
R=robertphillips@google.com
Author: bsalomon@google.com
Review URL: https://codereview.chromium.org/298713002
git-svn-id: http://skia.googlecode.com/svn/trunk@14801 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/SkGr.cpp | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index 78df53e38a..6bd04dec3a 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -378,6 +378,26 @@ void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, bool ju } } +/** + * Unlike GrContext::AutoMatrix, this doesn't require setting a new matrix. GrContext::AutoMatrix + * likes to set the new matrix in its constructor because it is usually necessary to simulataneously + * update a GrPaint. This AutoMatrix is used while initially setting up GrPaint, however. + */ +class AutoMatrix { +public: + AutoMatrix(GrContext* context) { + fMatrix = context->getMatrix(); + fContext = context; + } + ~AutoMatrix() { + SkASSERT(NULL != fContext); + fContext->setMatrix(fMatrix); + } +private: + GrContext* fContext; + SkMatrix fMatrix; +}; + void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint, bool constantColor, GrPaint* grPaint) { SkShader* shader = skPaint.getShader(); @@ -386,9 +406,12 @@ void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint, return; } - // SkShader::asNewEffect() may do offscreen rendering. Setup default drawing state and require - // the shader to set a render target. - GrContext::AutoWideOpenIdentityDraw awo(context, NULL); + // SkShader::asNewEffect() may do offscreen rendering. Save off the current RT, clip, and + // matrix. We don't reset the matrix on the context because SkShader::asNewEffect may use + // GrContext::getMatrix() to know the transformation from local coords to device space. + GrContext::AutoRenderTarget art(context, NULL); + GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialClip); + AutoMatrix am(context); // setup the shader as the first color effect on the paint SkAutoTUnref<GrEffectRef> effect(shader->asNewEffect(context, skPaint, NULL)); |