| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkComposeShader.h" | 8 #include "SkComposeShader.h" |
| 9 #include "SkColorFilter.h" | 9 #include "SkColorFilter.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 fMode = mode; | 23 fMode = mode; |
| 24 SkSafeRef(mode); | 24 SkSafeRef(mode); |
| 25 } | 25 } |
| 26 | 26 |
| 27 SkComposeShader::~SkComposeShader() { | 27 SkComposeShader::~SkComposeShader() { |
| 28 SkSafeUnref(fMode); | 28 SkSafeUnref(fMode); |
| 29 fShaderB->unref(); | 29 fShaderB->unref(); |
| 30 fShaderA->unref(); | 30 fShaderA->unref(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 size_t SkComposeShader::contextSize() const { | 33 size_t SkComposeShader::contextSize(const ContextRec& rec) const { |
| 34 return sizeof(ComposeShaderContext) + fShaderA->contextSize() + fShaderB->co
ntextSize(); | 34 return sizeof(ComposeShaderContext) |
| 35 + fShaderA->contextSize(rec) |
| 36 + fShaderB->contextSize(rec); |
| 35 } | 37 } |
| 36 | 38 |
| 37 class SkAutoAlphaRestore { | 39 class SkAutoAlphaRestore { |
| 38 public: | 40 public: |
| 39 SkAutoAlphaRestore(SkPaint* paint, uint8_t newAlpha) { | 41 SkAutoAlphaRestore(SkPaint* paint, uint8_t newAlpha) { |
| 40 fAlpha = paint->getAlpha(); | 42 fAlpha = paint->getAlpha(); |
| 41 fPaint = paint; | 43 fPaint = paint; |
| 42 paint->setAlpha(newAlpha); | 44 paint->setAlpha(newAlpha); |
| 43 } | 45 } |
| 44 | 46 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 68 } | 70 } |
| 69 | 71 |
| 70 template <typename T> void safe_call_destructor(T* obj) { | 72 template <typename T> void safe_call_destructor(T* obj) { |
| 71 if (obj) { | 73 if (obj) { |
| 72 obj->~T(); | 74 obj->~T(); |
| 73 } | 75 } |
| 74 } | 76 } |
| 75 | 77 |
| 76 SkShader::Context* SkComposeShader::onCreateContext(const ContextRec& rec, void*
storage) const { | 78 SkShader::Context* SkComposeShader::onCreateContext(const ContextRec& rec, void*
storage) const { |
| 77 char* aStorage = (char*) storage + sizeof(ComposeShaderContext); | 79 char* aStorage = (char*) storage + sizeof(ComposeShaderContext); |
| 78 char* bStorage = aStorage + fShaderA->contextSize(); | 80 char* bStorage = aStorage + fShaderA->contextSize(rec); |
| 79 | 81 |
| 80 // we preconcat our localMatrix (if any) with the device matrix | 82 // we preconcat our localMatrix (if any) with the device matrix |
| 81 // before calling our sub-shaders | 83 // before calling our sub-shaders |
| 82 SkMatrix tmpM; | 84 SkMatrix tmpM; |
| 83 tmpM.setConcat(*rec.fMatrix, this->getLocalMatrix()); | 85 tmpM.setConcat(*rec.fMatrix, this->getLocalMatrix()); |
| 84 | 86 |
| 85 // Our sub-shaders need to see opaque, so by combining them we don't double-
alphatize the | 87 // Our sub-shaders need to see opaque, so by combining them we don't double-
alphatize the |
| 86 // result. ComposeShader itself will respect the alpha, and post-apply it af
ter calling the | 88 // result. ComposeShader itself will respect the alpha, and post-apply it af
ter calling the |
| 87 // sub-shaders. | 89 // sub-shaders. |
| 88 SkPaint opaquePaint(*rec.fPaint); | 90 SkPaint opaquePaint(*rec.fPaint); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 if (!dst || !src) { | 259 if (!dst || !src) { |
| 258 return nullptr; | 260 return nullptr; |
| 259 } | 261 } |
| 260 return new SkComposeShader(dst, src, xfer); | 262 return new SkComposeShader(dst, src, xfer); |
| 261 } | 263 } |
| 262 | 264 |
| 263 SkShader* SkShader::CreateComposeShader(SkShader* dst, SkShader* src, SkXfermode
::Mode mode) { | 265 SkShader* SkShader::CreateComposeShader(SkShader* dst, SkShader* src, SkXfermode
::Mode mode) { |
| 264 SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(mode)); | 266 SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(mode)); |
| 265 return CreateComposeShader(dst, src, xfer); | 267 return CreateComposeShader(dst, src, xfer); |
| 266 } | 268 } |
| OLD | NEW |