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

Side by Side Diff: src/core/SkComposeShader.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/SkBlitter.cpp ('k') | src/core/SkDraw.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 "SkComposeShader.h" 10 #include "SkComposeShader.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 buffer.writeFlattenable(fShaderA); 71 buffer.writeFlattenable(fShaderA);
72 buffer.writeFlattenable(fShaderB); 72 buffer.writeFlattenable(fShaderB);
73 buffer.writeFlattenable(fMode); 73 buffer.writeFlattenable(fMode);
74 } 74 }
75 75
76 /* We call validContext/createContext on our two worker shaders. 76 /* We call validContext/createContext on our two worker shaders.
77 However, we always let them see opaque alpha, and if the paint 77 However, we always let them see opaque alpha, and if the paint
78 really is translucent, then we apply that after the fact. 78 really is translucent, then we apply that after the fact.
79 79
80 */ 80 */
81 bool SkComposeShader::validContext(const SkBitmap& device, 81 bool SkComposeShader::validContext(const ContextRec& rec, SkMatrix* totalInverse ) const {
82 const SkPaint& paint, 82 if (!this->INHERITED::validContext(rec, totalInverse)) {
83 const SkMatrix& matrix,
84 SkMatrix* totalInverse) const {
85 if (!this->INHERITED::validContext(device, paint, matrix, totalInverse)) {
86 return false; 83 return false;
87 } 84 }
88 85
89 // we preconcat our localMatrix (if any) with the device matrix 86 // we preconcat our localMatrix (if any) with the device matrix
90 // before calling our sub-shaders 87 // before calling our sub-shaders
91 88
92 SkMatrix tmpM; 89 SkMatrix tmpM;
90 tmpM.setConcat(*rec.fMatrix, this->getLocalMatrix());
93 91
94 tmpM.setConcat(matrix, this->getLocalMatrix()); 92 ContextRec newRec(rec);
93 newRec.fMatrix = &tmpM;
95 94
96 return fShaderA->validContext(device, paint, tmpM) && 95 return fShaderA->validContext(newRec) && fShaderB->validContext(newRec);
97 fShaderB->validContext(device, paint, tmpM);
98 } 96 }
99 97
100 SkShader::Context* SkComposeShader::createContext(const SkBitmap& device, const SkPaint& paint, 98 SkShader::Context* SkComposeShader::createContext(const ContextRec& rec, void* s torage) const {
101 const SkMatrix& matrix, void* storage) const { 99 if (!this->validContext(rec)) {
102 if (!this->validContext(device, paint, matrix)) {
103 return NULL; 100 return NULL;
104 } 101 }
105 102
106 // we preconcat our localMatrix (if any) with the device matrix 103 // TODO : must fix this to not "cheat" and modify fPaint
107 // before calling our sub-shaders 104 SkAutoAlphaRestore restore(const_cast<SkPaint*>(rec.fPaint), 0xFF);
108
109 SkMatrix tmpM;
110
111 tmpM.setConcat(matrix, this->getLocalMatrix());
112
113 SkAutoAlphaRestore restore(const_cast<SkPaint*>(&paint), 0xFF);
114 105
115 char* aStorage = (char*) storage + sizeof(ComposeShaderContext); 106 char* aStorage = (char*) storage + sizeof(ComposeShaderContext);
116 char* bStorage = aStorage + fShaderA->contextSize(); 107 char* bStorage = aStorage + fShaderA->contextSize();
117 108
118 SkShader::Context* contextA = fShaderA->createContext(device, paint, tmpM, a Storage); 109 // we preconcat our localMatrix (if any) with the device matrix
119 SkShader::Context* contextB = fShaderB->createContext(device, paint, tmpM, b Storage); 110 // before calling our sub-shaders
111
112 SkMatrix tmpM;
113 tmpM.setConcat(*rec.fMatrix, this->getLocalMatrix());
114
115 ContextRec newRec(rec);
116 newRec.fMatrix = &tmpM;
117
118 SkShader::Context* contextA = fShaderA->createContext(newRec, aStorage);
119 SkShader::Context* contextB = fShaderB->createContext(newRec, bStorage);
120 120
121 // Both functions must succeed; otherwise validContext should have returned 121 // Both functions must succeed; otherwise validContext should have returned
122 // false. 122 // false.
123 SkASSERT(contextA); 123 SkASSERT(contextA);
124 SkASSERT(contextB); 124 SkASSERT(contextB);
125 125
126 return SkNEW_PLACEMENT_ARGS(storage, ComposeShaderContext, 126 return SkNEW_PLACEMENT_ARGS(storage, ComposeShaderContext, (*this, rec, cont extA, contextB));
127 (*this, device, paint, matrix, contextA, context B));
128 } 127 }
129 128
130 SkComposeShader::ComposeShaderContext::ComposeShaderContext( 129 SkComposeShader::ComposeShaderContext::ComposeShaderContext(
131 const SkComposeShader& shader, const SkBitmap& device, 130 const SkComposeShader& shader, const ContextRec& rec,
132 const SkPaint& paint, const SkMatrix& matrix,
133 SkShader::Context* contextA, SkShader::Context* contextB) 131 SkShader::Context* contextA, SkShader::Context* contextB)
134 : INHERITED(shader, device, paint, matrix) 132 : INHERITED(shader, rec)
135 , fShaderContextA(contextA) 133 , fShaderContextA(contextA)
136 , fShaderContextB(contextB) {} 134 , fShaderContextB(contextB) {}
137 135
138 SkComposeShader::ComposeShaderContext::~ComposeShaderContext() { 136 SkComposeShader::ComposeShaderContext::~ComposeShaderContext() {
139 fShaderContextA->~Context(); 137 fShaderContextA->~Context();
140 fShaderContextB->~Context(); 138 fShaderContextB->~Context();
141 } 139 }
142 140
143 // larger is better (fewer times we have to loop), but we shouldn't 141 // larger is better (fewer times we have to loop), but we shouldn't
144 // take up too much stack-space (each element is 4 bytes) 142 // take up too much stack-space (each element is 4 bytes)
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 str->append(" ShaderB: "); 210 str->append(" ShaderB: ");
213 fShaderB->toString(str); 211 fShaderB->toString(str);
214 str->append(" Xfermode: "); 212 str->append(" Xfermode: ");
215 fMode->toString(str); 213 fMode->toString(str);
216 214
217 this->INHERITED::toString(str); 215 this->INHERITED::toString(str);
218 216
219 str->append(")"); 217 str->append(")");
220 } 218 }
221 #endif 219 #endif
OLDNEW
« no previous file with comments | « src/core/SkBlitter.cpp ('k') | src/core/SkDraw.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698