Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "SkTransparentShader.h" | 10 #include "SkTransparentShader.h" |
| 11 #include "SkColorPriv.h" | 11 #include "SkColorPriv.h" |
| 12 #include "SkString.h" | 12 #include "SkString.h" |
| 13 | 13 |
| 14 bool SkTransparentShader::setContext(const SkBitmap& device, | 14 SkShader::Context* SkTransparentShader::createContext(const SkBitmap& device, |
| 15 const SkPaint& paint, | 15 const SkPaint& paint, |
| 16 const SkMatrix& matrix) { | 16 const SkMatrix& matrix, |
| 17 fDevice = &device; | 17 void* storage) const { |
| 18 fAlpha = paint.getAlpha(); | 18 if (!this->validContext(device, paint, matrix)) { |
| 19 return NULL; | |
| 20 } | |
| 19 | 21 |
| 20 return this->INHERITED::setContext(device, paint, matrix); | 22 return SkNEW_PLACEMENT_ARGS(storage, TransparentShaderContext, (*this, devic e, paint, matrix)); |
| 21 } | 23 } |
| 22 | 24 |
| 23 uint32_t SkTransparentShader::getFlags() { | 25 size_t SkTransparentShader::contextSize() const { |
| 26 return sizeof(TransparentShaderContext); | |
| 27 } | |
| 28 | |
| 29 bool SkTransparentShader::validContext(const SkBitmap& device, | |
|
scroggo
2014/03/24 21:24:46
Why did you override this if all you do is call in
Dominik Grewe
2014/03/26 17:22:22
Removed it.
| |
| 30 const SkPaint& paint, | |
| 31 const SkMatrix& matrix) const { | |
| 32 return this->INHERITED::validContext(device, paint, matrix); | |
| 33 } | |
| 34 | |
| 35 SkTransparentShader::TransparentShaderContext::TransparentShaderContext( | |
| 36 const SkTransparentShader& shader, const SkBitmap& device, | |
|
scroggo
2014/03/24 21:24:46
nit: 8 space indent.
Dominik Grewe
2014/03/26 17:22:22
Done.
| |
| 37 const SkPaint& paint, const SkMatrix& matrix) | |
| 38 : INHERITED(shader, device, paint, matrix) | |
| 39 , fDevice(&device) | |
| 40 , fAlpha(paint.getAlpha()) {} | |
|
scroggo
2014/03/24 21:24:46
fAlpha wasn't created by you, but as long as we're
Dominik Grewe
2014/03/26 17:22:22
Done.
| |
| 41 | |
| 42 SkTransparentShader::TransparentShaderContext::~TransparentShaderContext() {} | |
| 43 | |
| 44 uint32_t SkTransparentShader::TransparentShaderContext::getFlags() const { | |
| 24 uint32_t flags = this->INHERITED::getFlags(); | 45 uint32_t flags = this->INHERITED::getFlags(); |
| 25 | 46 |
| 26 switch (fDevice->colorType()) { | 47 switch (fDevice->colorType()) { |
| 27 case kRGB_565_SkColorType: | 48 case kRGB_565_SkColorType: |
| 28 flags |= kHasSpan16_Flag; | 49 flags |= kHasSpan16_Flag; |
| 29 if (fAlpha == 255) | 50 if (fAlpha == 255) |
| 30 flags |= kOpaqueAlpha_Flag; | 51 flags |= kOpaqueAlpha_Flag; |
| 31 break; | 52 break; |
| 32 case kPMColor_SkColorType: | 53 case kPMColor_SkColorType: |
| 33 if (fAlpha == 255 && fDevice->isOpaque()) | 54 if (fAlpha == 255 && fDevice->isOpaque()) |
| 34 flags |= kOpaqueAlpha_Flag; | 55 flags |= kOpaqueAlpha_Flag; |
| 35 break; | 56 break; |
| 36 default: | 57 default: |
| 37 break; | 58 break; |
| 38 } | 59 } |
| 39 return flags; | 60 return flags; |
| 40 } | 61 } |
| 41 | 62 |
| 42 void SkTransparentShader::shadeSpan(int x, int y, SkPMColor span[], int count) { | 63 void SkTransparentShader::TransparentShaderContext::shadeSpan( |
| 64 int x, int y, SkPMColor span[], int count) { | |
|
scroggo
2014/03/24 21:24:46
nit: The parameters that fit on the same line shou
| |
| 43 unsigned scale = SkAlpha255To256(fAlpha); | 65 unsigned scale = SkAlpha255To256(fAlpha); |
| 44 | 66 |
| 45 switch (fDevice->colorType()) { | 67 switch (fDevice->colorType()) { |
| 46 case kPMColor_SkColorType: | 68 case kPMColor_SkColorType: |
| 47 if (scale == 256) { | 69 if (scale == 256) { |
| 48 SkPMColor* src = fDevice->getAddr32(x, y); | 70 SkPMColor* src = fDevice->getAddr32(x, y); |
| 49 if (src != span) { | 71 if (src != span) { |
| 50 memcpy(span, src, count * sizeof(SkPMColor)); | 72 memcpy(span, src, count * sizeof(SkPMColor)); |
| 51 } | 73 } |
| 52 } else { | 74 } else { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 } | 112 } |
| 91 } | 113 } |
| 92 break; | 114 break; |
| 93 } | 115 } |
| 94 default: | 116 default: |
| 95 SkDEBUGFAIL("colorType not supported as a destination device"); | 117 SkDEBUGFAIL("colorType not supported as a destination device"); |
| 96 break; | 118 break; |
| 97 } | 119 } |
| 98 } | 120 } |
| 99 | 121 |
| 100 void SkTransparentShader::shadeSpan16(int x, int y, uint16_t span[], int count) { | 122 void SkTransparentShader::TransparentShaderContext::shadeSpan16( |
| 123 int x, int y, uint16_t span[], int count) { | |
|
scroggo
2014/03/24 21:24:46
same.
| |
| 101 SkASSERT(fDevice->colorType() == kRGB_565_SkColorType); | 124 SkASSERT(fDevice->colorType() == kRGB_565_SkColorType); |
| 102 | 125 |
| 103 uint16_t* src = fDevice->getAddr16(x, y); | 126 uint16_t* src = fDevice->getAddr16(x, y); |
| 104 if (src != span) { | 127 if (src != span) { |
| 105 memcpy(span, src, count << 1); | 128 memcpy(span, src, count << 1); |
| 106 } | 129 } |
| 107 } | 130 } |
| 108 | 131 |
| 109 #ifdef SK_DEVELOPER | 132 #ifdef SK_DEVELOPER |
| 110 void SkTransparentShader::toString(SkString* str) const { | 133 void SkTransparentShader::toString(SkString* str) const { |
| 111 str->append("SkTransparentShader: ("); | 134 str->append("SkTransparentShader: ("); |
| 112 | 135 |
| 113 this->INHERITED::toString(str); | 136 this->INHERITED::toString(str); |
| 114 | 137 |
| 115 str->append(")"); | 138 str->append(")"); |
| 116 } | 139 } |
| 117 #endif | 140 #endif |
| OLD | NEW |