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

Side by Side Diff: src/core/SkShader.cpp

Issue 264843006: create struct to hold all the params passed around for shader::context (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: address review comments Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « src/core/SkPictureShader.cpp ('k') | src/effects/SkPerlinNoiseShader.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 * 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 "SkBitmapProcShader.h" 8 #include "SkBitmapProcShader.h"
9 #include "SkReadBuffer.h" 9 #include "SkReadBuffer.h"
10 #include "SkMallocPixelRef.h" 10 #include "SkMallocPixelRef.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 SkMatrix total; 49 SkMatrix total;
50 50
51 if (this->hasLocalMatrix()) { 51 if (this->hasLocalMatrix()) {
52 total.setConcat(matrix, this->getLocalMatrix()); 52 total.setConcat(matrix, this->getLocalMatrix());
53 m = &total; 53 m = &total;
54 } 54 }
55 55
56 return m->invert(totalInverse); 56 return m->invert(totalInverse);
57 } 57 }
58 58
59 bool SkShader::validContext(const SkBitmap& device, 59 bool SkShader::validContext(const ContextRec& rec, SkMatrix* totalInverse) const {
60 const SkPaint& paint, 60 return this->computeTotalInverse(*rec.fMatrix, totalInverse);
61 const SkMatrix& matrix,
62 SkMatrix* totalInverse) const {
63 return this->computeTotalInverse(matrix, totalInverse);
64 } 61 }
65 62
66 SkShader::Context* SkShader::createContext(const SkBitmap&, const SkPaint&, cons t SkMatrix&, 63 SkShader::Context* SkShader::createContext(const ContextRec&, void* storage) con st {
67 void* storage) const {
68 return NULL; 64 return NULL;
69 } 65 }
70 66
71 size_t SkShader::contextSize() const { 67 size_t SkShader::contextSize() const {
72 return 0; 68 return 0;
73 } 69 }
74 70
75 SkShader::Context::Context(const SkShader& shader, const SkBitmap& device, 71 SkShader::Context::Context(const SkShader& shader, const ContextRec& rec)
76 const SkPaint& paint, const SkMatrix& matrix)
77 : fShader(shader) 72 : fShader(shader)
78 { 73 {
79 SkASSERT(fShader.validContext(device, paint, matrix)); 74 SkASSERT(fShader.validContext(rec));
80 75
81 // Because the context parameters must be valid at this point, we know that the matrix is 76 // Because the context parameters must be valid at this point, we know that the matrix is
82 // invertible. 77 // invertible.
83 SkAssertResult(fShader.computeTotalInverse(matrix, &fTotalInverse)); 78 SkAssertResult(fShader.computeTotalInverse(*rec.fMatrix, &fTotalInverse));
84 fTotalInverseClass = (uint8_t)ComputeMatrixClass(fTotalInverse); 79 fTotalInverseClass = (uint8_t)ComputeMatrixClass(fTotalInverse);
85 80
86 fPaintAlpha = paint.getAlpha(); 81 fPaintAlpha = rec.fPaint->getAlpha();
87 } 82 }
88 83
89 SkShader::Context::~Context() {} 84 SkShader::Context::~Context() {}
90 85
91 SkShader::Context::ShadeProc SkShader::Context::asAShadeProc(void** ctx) { 86 SkShader::Context::ShadeProc SkShader::Context::asAShadeProc(void** ctx) {
92 return NULL; 87 return NULL;
93 } 88 }
94 89
95 #include "SkColorPriv.h" 90 #include "SkColorPriv.h"
96 91
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 } 238 }
244 239
245 uint32_t SkColorShader::ColorShaderContext::getFlags() const { 240 uint32_t SkColorShader::ColorShaderContext::getFlags() const {
246 return fFlags; 241 return fFlags;
247 } 242 }
248 243
249 uint8_t SkColorShader::ColorShaderContext::getSpan16Alpha() const { 244 uint8_t SkColorShader::ColorShaderContext::getSpan16Alpha() const {
250 return SkGetPackedA32(fPMColor); 245 return SkGetPackedA32(fPMColor);
251 } 246 }
252 247
253 SkShader::Context* SkColorShader::createContext(const SkBitmap& device, const Sk Paint& paint, 248 SkShader::Context* SkColorShader::createContext(const ContextRec& rec, void* sto rage) const {
254 const SkMatrix& matrix, void* st orage) const { 249 if (!this->validContext(rec)) {
255 if (!this->validContext(device, paint, matrix)) {
256 return NULL; 250 return NULL;
257 } 251 }
258 252
259 return SkNEW_PLACEMENT_ARGS(storage, ColorShaderContext, (*this, device, pai nt, matrix)); 253 return SkNEW_PLACEMENT_ARGS(storage, ColorShaderContext, (*this, rec));
260 } 254 }
261 255
262 SkColorShader::ColorShaderContext::ColorShaderContext(const SkColorShader& shade r, 256 SkColorShader::ColorShaderContext::ColorShaderContext(const SkColorShader& shade r,
263 const SkBitmap& device, 257 const ContextRec& rec)
264 const SkPaint& paint, 258 : INHERITED(shader, rec)
265 const SkMatrix& matrix)
266 : INHERITED(shader, device, paint, matrix)
267 { 259 {
268 SkColor color = shader.fColor; 260 SkColor color = shader.fColor;
269 unsigned a = SkAlphaMul(SkColorGetA(color), SkAlpha255To256(paint.getAlpha() )); 261 unsigned a = SkAlphaMul(SkColorGetA(color), SkAlpha255To256(rec.fPaint->getA lpha()));
270 262
271 unsigned r = SkColorGetR(color); 263 unsigned r = SkColorGetR(color);
272 unsigned g = SkColorGetG(color); 264 unsigned g = SkColorGetG(color);
273 unsigned b = SkColorGetB(color); 265 unsigned b = SkColorGetB(color);
274 266
275 // we want this before we apply any alpha 267 // we want this before we apply any alpha
276 fColor16 = SkPack888ToRGB16(r, g, b); 268 fColor16 = SkPack888ToRGB16(r, g, b);
277 269
278 if (a != 255) { 270 if (a != 255) {
279 r = SkMulDiv255Round(r, a); 271 r = SkMulDiv255Round(r, a);
280 g = SkMulDiv255Round(g, a); 272 g = SkMulDiv255Round(g, a);
281 b = SkMulDiv255Round(b, a); 273 b = SkMulDiv255Round(b, a);
282 } 274 }
283 fPMColor = SkPackARGB32(a, r, g, b); 275 fPMColor = SkPackARGB32(a, r, g, b);
284 276
285 fFlags = kConstInY32_Flag; 277 fFlags = kConstInY32_Flag;
286 if (255 == a) { 278 if (255 == a) {
287 fFlags |= kOpaqueAlpha_Flag; 279 fFlags |= kOpaqueAlpha_Flag;
288 if (paint.isDither() == false) { 280 if (rec.fPaint->isDither() == false) {
289 fFlags |= kHasSpan16_Flag; 281 fFlags |= kHasSpan16_Flag;
290 } 282 }
291 } 283 }
292 } 284 }
293 285
294 void SkColorShader::ColorShaderContext::shadeSpan(int x, int y, SkPMColor span[] , int count) { 286 void SkColorShader::ColorShaderContext::shadeSpan(int x, int y, SkPMColor span[] , int count) {
295 sk_memset32(span, fPMColor, count); 287 sk_memset32(span, fPMColor, count);
296 } 288 }
297 289
298 void SkColorShader::ColorShaderContext::shadeSpan16(int x, int y, uint16_t span[ ], int count) { 290 void SkColorShader::ColorShaderContext::shadeSpan16(int x, int y, uint16_t span[ ], int count) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 #include "SkEmptyShader.h" 331 #include "SkEmptyShader.h"
340 332
341 void SkEmptyShader::toString(SkString* str) const { 333 void SkEmptyShader::toString(SkString* str) const {
342 str->append("SkEmptyShader: ("); 334 str->append("SkEmptyShader: (");
343 335
344 this->INHERITED::toString(str); 336 this->INHERITED::toString(str);
345 337
346 str->append(")"); 338 str->append(")");
347 } 339 }
348 #endif 340 #endif
OLDNEW
« no previous file with comments | « src/core/SkPictureShader.cpp ('k') | src/effects/SkPerlinNoiseShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698