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

Side by Side Diff: src/core/SkFilterShader.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/SkFilterShader.h ('k') | src/core/SkPictureShader.h » ('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 2013 Google Inc. 2 * Copyright 2013 Google Inc.
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 "SkFilterShader.h" 8 #include "SkFilterShader.h"
9 9
10 #include "SkColorFilter.h" 10 #include "SkColorFilter.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 if (!(filterF & SkColorFilter::kHasFilter16_Flag)) { 48 if (!(filterF & SkColorFilter::kHasFilter16_Flag)) {
49 shaderF &= ~SkShader::kHasSpan16_Flag; 49 shaderF &= ~SkShader::kHasSpan16_Flag;
50 } 50 }
51 // if the filter might change alpha, clear the opaque flag in the shader 51 // if the filter might change alpha, clear the opaque flag in the shader
52 if (!(filterF & SkColorFilter::kAlphaUnchanged_Flag)) { 52 if (!(filterF & SkColorFilter::kAlphaUnchanged_Flag)) {
53 shaderF &= ~(SkShader::kOpaqueAlpha_Flag | SkShader::kHasSpan16_Flag); 53 shaderF &= ~(SkShader::kOpaqueAlpha_Flag | SkShader::kHasSpan16_Flag);
54 } 54 }
55 return shaderF; 55 return shaderF;
56 } 56 }
57 57
58 SkShader::Context* SkFilterShader::createContext(const SkBitmap& device, 58 SkShader::Context* SkFilterShader::createContext(const ContextRec& rec, void* st orage) const {
59 const SkPaint& paint, 59 if (!this->validContext(rec, NULL)) {
60 const SkMatrix& matrix,
61 void* storage) const {
62 if (!this->validContext(device, paint, matrix)) {
63 return NULL; 60 return NULL;
64 } 61 }
65 62
66 char* shaderContextStorage = (char*)storage + sizeof(FilterShaderContext); 63 char* shaderContextStorage = (char*)storage + sizeof(FilterShaderContext);
67 SkShader::Context* shaderContext = fShader->createContext(device, paint, mat rix, 64 SkShader::Context* shaderContext = fShader->createContext(rec, shaderContext Storage);
68 shaderContextStora ge);
69 SkASSERT(shaderContext); 65 SkASSERT(shaderContext);
70 66
71 return SkNEW_PLACEMENT_ARGS(storage, FilterShaderContext, 67 return SkNEW_PLACEMENT_ARGS(storage, FilterShaderContext, (*this, shaderCont ext, rec));
72 (*this, shaderContext, device, paint, matrix));
73 } 68 }
74 69
75 size_t SkFilterShader::contextSize() const { 70 size_t SkFilterShader::contextSize() const {
76 return sizeof(FilterShaderContext) + fShader->contextSize(); 71 return sizeof(FilterShaderContext) + fShader->contextSize();
77 } 72 }
78 73
79 bool SkFilterShader::validContext(const SkBitmap& device, 74 bool SkFilterShader::validContext(const ContextRec& rec, SkMatrix* totalInverse) const {
80 const SkPaint& paint, 75 return this->INHERITED::validContext(rec, totalInverse) && fShader->validCon text(rec);
81 const SkMatrix& matrix,
82 SkMatrix* totalInverse) const {
83 return this->INHERITED::validContext(device, paint, matrix, totalInverse) &&
84 fShader->validContext(device, paint, matrix);
85 } 76 }
86 77
87 SkFilterShader::FilterShaderContext::FilterShaderContext(const SkFilterShader& f ilterShader, 78 SkFilterShader::FilterShaderContext::FilterShaderContext(const SkFilterShader& f ilterShader,
88 SkShader::Context* shad erContext, 79 SkShader::Context* shad erContext,
89 const SkBitmap& device, 80 const ContextRec& rec)
90 const SkPaint& paint, 81 : INHERITED(filterShader, rec)
91 const SkMatrix& matrix)
92 : INHERITED(filterShader, device, paint, matrix)
93 , fShaderContext(shaderContext) {} 82 , fShaderContext(shaderContext) {}
94 83
95 SkFilterShader::FilterShaderContext::~FilterShaderContext() { 84 SkFilterShader::FilterShaderContext::~FilterShaderContext() {
96 fShaderContext->~Context(); 85 fShaderContext->~Context();
97 } 86 }
98 87
99 void SkFilterShader::FilterShaderContext::shadeSpan(int x, int y, SkPMColor resu lt[], int count) { 88 void SkFilterShader::FilterShaderContext::shadeSpan(int x, int y, SkPMColor resu lt[], int count) {
100 const SkFilterShader& filterShader = static_cast<const SkFilterShader&>(fSha der); 89 const SkFilterShader& filterShader = static_cast<const SkFilterShader&>(fSha der);
101 90
102 fShaderContext->shadeSpan(x, y, result, count); 91 fShaderContext->shadeSpan(x, y, result, count);
(...skipping 17 matching lines...) Expand all
120 str->append("Shader: "); 109 str->append("Shader: ");
121 fShader->toString(str); 110 fShader->toString(str);
122 str->append(" Filter: "); 111 str->append(" Filter: ");
123 // TODO: add "fFilter->toString(str);" once SkColorFilter::toString is added 112 // TODO: add "fFilter->toString(str);" once SkColorFilter::toString is added
124 113
125 this->INHERITED::toString(str); 114 this->INHERITED::toString(str);
126 115
127 str->append(")"); 116 str->append(")");
128 } 117 }
129 #endif 118 #endif
OLDNEW
« no previous file with comments | « src/core/SkFilterShader.h ('k') | src/core/SkPictureShader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698