| 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 13 matching lines...) Expand all Loading... |
| 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 ContextRec& rec) const { | 33 size_t SkComposeShader::contextSize(const ContextRec& rec) const { |
| 34 return sizeof(ComposeShaderContext) | 34 return SkAlign16(sizeof(ComposeShaderContext)) |
| 35 + fShaderA->contextSize(rec) | 35 + SkAlign16(fShaderA->contextSize(rec)) |
| 36 + fShaderB->contextSize(rec); | 36 + SkAlign16(fShaderB->contextSize(rec)); |
| 37 } | 37 } |
| 38 | 38 |
| 39 class SkAutoAlphaRestore { | 39 class SkAutoAlphaRestore { |
| 40 public: | 40 public: |
| 41 SkAutoAlphaRestore(SkPaint* paint, uint8_t newAlpha) { | 41 SkAutoAlphaRestore(SkPaint* paint, uint8_t newAlpha) { |
| 42 fAlpha = paint->getAlpha(); | 42 fAlpha = paint->getAlpha(); |
| 43 fPaint = paint; | 43 fPaint = paint; |
| 44 paint->setAlpha(newAlpha); | 44 paint->setAlpha(newAlpha); |
| 45 } | 45 } |
| 46 | 46 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 69 buffer.writeFlattenable(fMode); | 69 buffer.writeFlattenable(fMode); |
| 70 } | 70 } |
| 71 | 71 |
| 72 template <typename T> void safe_call_destructor(T* obj) { | 72 template <typename T> void safe_call_destructor(T* obj) { |
| 73 if (obj) { | 73 if (obj) { |
| 74 obj->~T(); | 74 obj->~T(); |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 | 77 |
| 78 SkShader::Context* SkComposeShader::onCreateContext(const ContextRec& rec, void*
storage) const { | 78 SkShader::Context* SkComposeShader::onCreateContext(const ContextRec& rec, void*
storage) const { |
| 79 char* aStorage = (char*) storage + sizeof(ComposeShaderContext); | 79 char* aStorage = (char*) storage + SkAlign16(sizeof(ComposeShaderContext)); |
| 80 char* bStorage = aStorage + fShaderA->contextSize(rec); | 80 char* bStorage = aStorage + SkAlign16(fShaderA->contextSize(rec)); |
| 81 | 81 |
| 82 // we preconcat our localMatrix (if any) with the device matrix | 82 // we preconcat our localMatrix (if any) with the device matrix |
| 83 // before calling our sub-shaders | 83 // before calling our sub-shaders |
| 84 SkMatrix tmpM; | 84 SkMatrix tmpM; |
| 85 tmpM.setConcat(*rec.fMatrix, this->getLocalMatrix()); | 85 tmpM.setConcat(*rec.fMatrix, this->getLocalMatrix()); |
| 86 | 86 |
| 87 // 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 |
| 88 // 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 |
| 89 // sub-shaders. | 89 // sub-shaders. |
| 90 SkPaint opaquePaint(*rec.fPaint); | 90 SkPaint opaquePaint(*rec.fPaint); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 if (!dst || !src) { | 259 if (!dst || !src) { |
| 260 return nullptr; | 260 return nullptr; |
| 261 } | 261 } |
| 262 return new SkComposeShader(dst, src, xfer); | 262 return new SkComposeShader(dst, src, xfer); |
| 263 } | 263 } |
| 264 | 264 |
| 265 SkShader* SkShader::CreateComposeShader(SkShader* dst, SkShader* src, SkXfermode
::Mode mode) { | 265 SkShader* SkShader::CreateComposeShader(SkShader* dst, SkShader* src, SkXfermode
::Mode mode) { |
| 266 SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(mode)); | 266 SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(mode)); |
| 267 return CreateComposeShader(dst, src, xfer); | 267 return CreateComposeShader(dst, src, xfer); |
| 268 } | 268 } |
| OLD | NEW |