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

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

Issue 245963010: Move SkShader::fLocalMatrix into SkShader constructor. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add SkLocalMatrixShaderWrapper 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
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"
11 #include "SkPaint.h" 11 #include "SkPaint.h"
12 #include "SkPicture.h" 12 #include "SkPicture.h"
13 #include "SkPictureShader.h" 13 #include "SkPictureShader.h"
14 #include "SkScalar.h" 14 #include "SkScalar.h"
15 #include "SkShader.h" 15 #include "SkShader.h"
16 #include "SkWriteBuffer.h" 16 #include "SkWriteBuffer.h"
17 17
18 SkShader::SkShader() { 18 SkShader::SkShader(const SkMatrix* localMatrix) {
19 fLocalMatrix.reset(); 19 if (localMatrix) {
20 fLocalMatrix = *localMatrix;
21 } else {
22 fLocalMatrix.reset();
23 }
20 } 24 }
21 25
22 SkShader::SkShader(SkReadBuffer& buffer) 26 SkShader::SkShader(SkReadBuffer& buffer)
23 : INHERITED(buffer) { 27 : INHERITED(buffer) {
24 if (buffer.readBool()) { 28 if (buffer.readBool()) {
25 buffer.readMatrix(&fLocalMatrix); 29 buffer.readMatrix(&fLocalMatrix);
26 } else { 30 } else {
27 fLocalMatrix.reset(); 31 fLocalMatrix.reset();
28 } 32 }
29 } 33 }
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } 177 }
174 178
175 SkShader::GradientType SkShader::asAGradient(GradientInfo* info) const { 179 SkShader::GradientType SkShader::asAGradient(GradientInfo* info) const {
176 return kNone_GradientType; 180 return kNone_GradientType;
177 } 181 }
178 182
179 GrEffectRef* SkShader::asNewEffect(GrContext*, const SkPaint&) const { 183 GrEffectRef* SkShader::asNewEffect(GrContext*, const SkPaint&) const {
180 return NULL; 184 return NULL;
181 } 185 }
182 186
183 SkShader* SkShader::CreateBitmapShader(const SkBitmap& src, 187 SkShader* SkShader::CreateBitmapShader(const SkBitmap& src, TileMode tmx, TileMo de tmy,
184 TileMode tmx, TileMode tmy) { 188 const SkMatrix* localMatrix) {
185 return ::CreateBitmapShader(src, tmx, tmy, NULL); 189 return ::CreateBitmapShader(src, tmx, tmy, localMatrix, NULL);
186 } 190 }
187 191
188 SkShader* SkShader::CreatePictureShader(SkPicture* src, TileMode tmx, TileMode t my) { 192 SkShader* SkShader::CreatePictureShader(SkPicture* src, TileMode tmx, TileMode t my) {
189 return SkPictureShader::Create(src, tmx, tmy); 193 return SkPictureShader::Create(src, tmx, tmy);
190 } 194 }
191 195
196 SkShader* SkShader::CreateLocalMatrixWrapper(SkShader* shader, const SkMatrix& l ocalMatrix) {
197 return SkLocalMatrixShaderWrapper::Create(shader, localMatrix);
198 }
199
192 #ifndef SK_IGNORE_TO_STRING 200 #ifndef SK_IGNORE_TO_STRING
193 void SkShader::toString(SkString* str) const { 201 void SkShader::toString(SkString* str) const {
194 if (this->hasLocalMatrix()) { 202 if (this->hasLocalMatrix()) {
195 str->append(" "); 203 str->append(" ");
196 this->getLocalMatrix().toString(str); 204 this->getLocalMatrix().toString(str);
197 } 205 }
198 } 206 }
199 #endif 207 #endif
200 208
201 ////////////////////////////////////////////////////////////////////////////// 209 //////////////////////////////////////////////////////////////////////////////
202 210
211 SkLocalMatrixShaderWrapper::SkLocalMatrixShaderWrapper(SkShader* shader,
212 const SkMatrix& localMatr ix)
213 : INHERITED(&localMatrix)
214 , fShader(shader) {
scroggo 2014/04/24 17:02:53 nit: Brace should go on the next line.
Dominik Grewe 2014/04/24 17:16:47 Done.
215 SkASSERT(shader);
216 shader->ref();
217 }
218
219 SkLocalMatrixShaderWrapper::SkLocalMatrixShaderWrapper(SkReadBuffer& buffer)
220 : INHERITED(buffer) {
scroggo 2014/04/24 17:02:53 ditto
Dominik Grewe 2014/04/24 17:16:47 Done.
221 fShader.reset(buffer.readShader());
222 }
223
224 void SkLocalMatrixShaderWrapper::flatten(SkWriteBuffer& buffer) {
225 this->INHERITED::flatten(buffer);
226 buffer.writeFlattenable(fShader);
227 }
228
229
230 //////////////////////////////////////////////////////////////////////////////
231
203 #include "SkColorShader.h" 232 #include "SkColorShader.h"
204 #include "SkUtils.h" 233 #include "SkUtils.h"
205 234
206 SkColorShader::SkColorShader() 235 SkColorShader::SkColorShader(const SkMatrix* localMatrix)
207 : fColor() 236 : INHERITED(localMatrix)
237 , fColor()
208 , fInheritColor(true) { 238 , fInheritColor(true) {
209 } 239 }
210 240
211 SkColorShader::SkColorShader(SkColor c) 241 SkColorShader::SkColorShader(SkColor c, const SkMatrix* localMatrix)
212 : fColor(c) 242 : INHERITED(localMatrix)
243 , fColor(c)
213 , fInheritColor(false) { 244 , fInheritColor(false) {
214 } 245 }
215 246
216 bool SkColorShader::isOpaque() const { 247 bool SkColorShader::isOpaque() const {
217 if (fInheritColor) { 248 if (fInheritColor) {
218 return true; // using paint's alpha 249 return true; // using paint's alpha
219 } 250 }
220 return SkColorGetA(fColor) == 255; 251 return SkColorGetA(fColor) == 255;
221 } 252 }
222 253
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 #include "SkEmptyShader.h" 377 #include "SkEmptyShader.h"
347 378
348 void SkEmptyShader::toString(SkString* str) const { 379 void SkEmptyShader::toString(SkString* str) const {
349 str->append("SkEmptyShader: ("); 380 str->append("SkEmptyShader: (");
350 381
351 this->INHERITED::toString(str); 382 this->INHERITED::toString(str);
352 383
353 str->append(")"); 384 str->append(")");
354 } 385 }
355 #endif 386 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698