Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: src/effects/SkTransparentShader.cpp

Issue 246403013: Revert of Revert of Extract most of the mutable state of SkShader into a separate Context object. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/effects/SkPerlinNoiseShader.cpp ('k') | src/effects/gradients/SkGradientShader.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 SkTransparentShader::TransparentShaderContext::TransparentShaderContext(
30 const SkTransparentShader& shader, const SkBitmap& device,
31 const SkPaint& paint, const SkMatrix& matrix)
32 : INHERITED(shader, device, paint, matrix)
33 , fDevice(&device) {}
34
35 SkTransparentShader::TransparentShaderContext::~TransparentShaderContext() {}
36
37 uint32_t SkTransparentShader::TransparentShaderContext::getFlags() const {
24 uint32_t flags = this->INHERITED::getFlags(); 38 uint32_t flags = this->INHERITED::getFlags();
25 39
26 switch (fDevice->colorType()) { 40 switch (fDevice->colorType()) {
27 case kRGB_565_SkColorType: 41 case kRGB_565_SkColorType:
28 flags |= kHasSpan16_Flag; 42 flags |= kHasSpan16_Flag;
29 if (fAlpha == 255) 43 if (this->getPaintAlpha() == 255)
30 flags |= kOpaqueAlpha_Flag; 44 flags |= kOpaqueAlpha_Flag;
31 break; 45 break;
32 case kN32_SkColorType: 46 case kN32_SkColorType:
33 if (fAlpha == 255 && fDevice->isOpaque()) 47 if (this->getPaintAlpha() == 255 && fDevice->isOpaque())
34 flags |= kOpaqueAlpha_Flag; 48 flags |= kOpaqueAlpha_Flag;
35 break; 49 break;
36 default: 50 default:
37 break; 51 break;
38 } 52 }
39 return flags; 53 return flags;
40 } 54 }
41 55
42 void SkTransparentShader::shadeSpan(int x, int y, SkPMColor span[], int count) { 56 void SkTransparentShader::TransparentShaderContext::shadeSpan(int x, int y, SkPM Color span[],
43 unsigned scale = SkAlpha255To256(fAlpha); 57 int count) {
58 unsigned scale = SkAlpha255To256(this->getPaintAlpha());
44 59
45 switch (fDevice->colorType()) { 60 switch (fDevice->colorType()) {
46 case kN32_SkColorType: 61 case kN32_SkColorType:
47 if (scale == 256) { 62 if (scale == 256) {
48 SkPMColor* src = fDevice->getAddr32(x, y); 63 SkPMColor* src = fDevice->getAddr32(x, y);
49 if (src != span) { 64 if (src != span) {
50 memcpy(span, src, count * sizeof(SkPMColor)); 65 memcpy(span, src, count * sizeof(SkPMColor));
51 } 66 }
52 } else { 67 } else {
53 const SkPMColor* src = fDevice->getAddr32(x, y); 68 const SkPMColor* src = fDevice->getAddr32(x, y);
54 for (int i = count - 1; i >= 0; --i) { 69 for (int i = count - 1; i >= 0; --i) {
55 span[i] = SkAlphaMulQ(src[i], scale); 70 span[i] = SkAlphaMulQ(src[i], scale);
56 } 71 }
57 } 72 }
58 break; 73 break;
59 case kRGB_565_SkColorType: { 74 case kRGB_565_SkColorType: {
60 const uint16_t* src = fDevice->getAddr16(x, y); 75 const uint16_t* src = fDevice->getAddr16(x, y);
61 if (scale == 256) { 76 if (scale == 256) {
62 for (int i = count - 1; i >= 0; --i) { 77 for (int i = count - 1; i >= 0; --i) {
63 span[i] = SkPixel16ToPixel32(src[i]); 78 span[i] = SkPixel16ToPixel32(src[i]);
64 } 79 }
65 } else { 80 } else {
66 unsigned alpha = fAlpha; 81 unsigned alpha = this->getPaintAlpha();
67 for (int i = count - 1; i >= 0; --i) { 82 for (int i = count - 1; i >= 0; --i) {
68 uint16_t c = src[i]; 83 uint16_t c = src[i];
69 unsigned r = SkPacked16ToR32(c); 84 unsigned r = SkPacked16ToR32(c);
70 unsigned g = SkPacked16ToG32(c); 85 unsigned g = SkPacked16ToG32(c);
71 unsigned b = SkPacked16ToB32(c); 86 unsigned b = SkPacked16ToB32(c);
72 87
73 span[i] = SkPackARGB32( alpha, 88 span[i] = SkPackARGB32( alpha,
74 SkAlphaMul(r, scale), 89 SkAlphaMul(r, scale),
75 SkAlphaMul(g, scale), 90 SkAlphaMul(g, scale),
76 SkAlphaMul(b, scale)); 91 SkAlphaMul(b, scale));
(...skipping 13 matching lines...) Expand all
90 } 105 }
91 } 106 }
92 break; 107 break;
93 } 108 }
94 default: 109 default:
95 SkDEBUGFAIL("colorType not supported as a destination device"); 110 SkDEBUGFAIL("colorType not supported as a destination device");
96 break; 111 break;
97 } 112 }
98 } 113 }
99 114
100 void SkTransparentShader::shadeSpan16(int x, int y, uint16_t span[], int count) { 115 void SkTransparentShader::TransparentShaderContext::shadeSpan16(int x, int y, ui nt16_t span[],
116 int count) {
101 SkASSERT(fDevice->colorType() == kRGB_565_SkColorType); 117 SkASSERT(fDevice->colorType() == kRGB_565_SkColorType);
102 118
103 uint16_t* src = fDevice->getAddr16(x, y); 119 uint16_t* src = fDevice->getAddr16(x, y);
104 if (src != span) { 120 if (src != span) {
105 memcpy(span, src, count << 1); 121 memcpy(span, src, count << 1);
106 } 122 }
107 } 123 }
108 124
109 #ifndef SK_IGNORE_TO_STRING 125 #ifndef SK_IGNORE_TO_STRING
110 void SkTransparentShader::toString(SkString* str) const { 126 void SkTransparentShader::toString(SkString* str) const {
111 str->append("SkTransparentShader: ("); 127 str->append("SkTransparentShader: (");
112 128
113 this->INHERITED::toString(str); 129 this->INHERITED::toString(str);
114 130
115 str->append(")"); 131 str->append(")");
116 } 132 }
117 #endif 133 #endif
OLDNEW
« no previous file with comments | « src/effects/SkPerlinNoiseShader.cpp ('k') | src/effects/gradients/SkGradientShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698