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

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

Issue 248033003: Remove support for inheriting the paint color from SkColorShader (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: fColor -> color 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 | Annotate | Revision Log
« no previous file with comments | « src/core/SkBlitter.cpp ('k') | tests/ShaderOpacityTest.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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 this->getLocalMatrix().toString(str); 196 this->getLocalMatrix().toString(str);
197 } 197 }
198 } 198 }
199 #endif 199 #endif
200 200
201 ////////////////////////////////////////////////////////////////////////////// 201 //////////////////////////////////////////////////////////////////////////////
202 202
203 #include "SkColorShader.h" 203 #include "SkColorShader.h"
204 #include "SkUtils.h" 204 #include "SkUtils.h"
205 205
206 SkColorShader::SkColorShader()
207 : fColor()
208 , fInheritColor(true) {
209 }
210
211 SkColorShader::SkColorShader(SkColor c) 206 SkColorShader::SkColorShader(SkColor c)
212 : fColor(c) 207 : fColor(c) {
213 , fInheritColor(false) {
214 } 208 }
215 209
216 bool SkColorShader::isOpaque() const { 210 bool SkColorShader::isOpaque() const {
217 if (fInheritColor) {
218 return true; // using paint's alpha
219 }
220 return SkColorGetA(fColor) == 255; 211 return SkColorGetA(fColor) == 255;
221 } 212 }
222 213
223 SkColorShader::SkColorShader(SkReadBuffer& b) : INHERITED(b) { 214 SkColorShader::SkColorShader(SkReadBuffer& b) : INHERITED(b) {
224 fInheritColor = b.readBool(); 215 // V25_COMPATIBILITY_CODE We had a boolean to make the color shader inherit the paint's
225 if (fInheritColor) { 216 // color. We don't support that any more.
226 return; 217 if (b.pictureVersion() < 26 && 0 != b.pictureVersion()) {
218 if (b.readBool()) {
219 SkDEBUGFAIL("We shouldn't have pictures that recorded the inherited case.");
220 fColor = SK_ColorWHITE;
221 return;
222 }
227 } 223 }
228 fColor = b.readColor(); 224 fColor = b.readColor();
229 } 225 }
230 226
231 void SkColorShader::flatten(SkWriteBuffer& buffer) const { 227 void SkColorShader::flatten(SkWriteBuffer& buffer) const {
232 this->INHERITED::flatten(buffer); 228 this->INHERITED::flatten(buffer);
233 buffer.writeBool(fInheritColor);
234 if (fInheritColor) {
235 return;
236 }
237 buffer.writeColor(fColor); 229 buffer.writeColor(fColor);
238 } 230 }
239 231
240 uint32_t SkColorShader::ColorShaderContext::getFlags() const { 232 uint32_t SkColorShader::ColorShaderContext::getFlags() const {
241 return fFlags; 233 return fFlags;
242 } 234 }
243 235
244 uint8_t SkColorShader::ColorShaderContext::getSpan16Alpha() const { 236 uint8_t SkColorShader::ColorShaderContext::getSpan16Alpha() const {
245 return SkGetPackedA32(fPMColor); 237 return SkGetPackedA32(fPMColor);
246 } 238 }
247 239
248 SkShader::Context* SkColorShader::createContext(const SkBitmap& device, const Sk Paint& paint, 240 SkShader::Context* SkColorShader::createContext(const SkBitmap& device, const Sk Paint& paint,
249 const SkMatrix& matrix, void* st orage) const { 241 const SkMatrix& matrix, void* st orage) const {
250 if (!this->validContext(device, paint, matrix)) { 242 if (!this->validContext(device, paint, matrix)) {
251 return NULL; 243 return NULL;
252 } 244 }
253 245
254 return SkNEW_PLACEMENT_ARGS(storage, ColorShaderContext, (*this, device, pai nt, matrix)); 246 return SkNEW_PLACEMENT_ARGS(storage, ColorShaderContext, (*this, device, pai nt, matrix));
255 } 247 }
256 248
257 SkColorShader::ColorShaderContext::ColorShaderContext(const SkColorShader& shade r, 249 SkColorShader::ColorShaderContext::ColorShaderContext(const SkColorShader& shade r,
258 const SkBitmap& device, 250 const SkBitmap& device,
259 const SkPaint& paint, 251 const SkPaint& paint,
260 const SkMatrix& matrix) 252 const SkMatrix& matrix)
261 : INHERITED(shader, device, paint, matrix) 253 : INHERITED(shader, device, paint, matrix)
262 { 254 {
255 SkColor color;
263 unsigned a; 256 unsigned a;
264 257
265 SkColor color; 258 color = shader.fColor;
266 if (shader.fInheritColor) { 259 a = SkAlphaMul(SkColorGetA(color), SkAlpha255To256(paint.getAlpha()));
267 color = paint.getColor();
268 a = SkColorGetA(color);
269 } else {
270 color = shader.fColor;
271 a = SkAlphaMul(SkColorGetA(color), SkAlpha255To256(paint.getAlpha()));
272 }
273 260
274 unsigned r = SkColorGetR(color); 261 unsigned r = SkColorGetR(color);
275 unsigned g = SkColorGetG(color); 262 unsigned g = SkColorGetG(color);
276 unsigned b = SkColorGetB(color); 263 unsigned b = SkColorGetB(color);
277 264
278 // we want this before we apply any alpha 265 // we want this before we apply any alpha
279 fColor16 = SkPack888ToRGB16(r, g, b); 266 fColor16 = SkPack888ToRGB16(r, g, b);
280 267
281 if (a != 255) { 268 if (a != 255) {
282 r = SkMulDiv255Round(r, a); 269 r = SkMulDiv255Round(r, a);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 info->fColorCount = 1; 307 info->fColorCount = 1;
321 info->fTileMode = SkShader::kRepeat_TileMode; 308 info->fTileMode = SkShader::kRepeat_TileMode;
322 } 309 }
323 return kColor_GradientType; 310 return kColor_GradientType;
324 } 311 }
325 312
326 #ifndef SK_IGNORE_TO_STRING 313 #ifndef SK_IGNORE_TO_STRING
327 void SkColorShader::toString(SkString* str) const { 314 void SkColorShader::toString(SkString* str) const {
328 str->append("SkColorShader: ("); 315 str->append("SkColorShader: (");
329 316
330 if (fInheritColor) { 317 str->append("Color: ");
331 str->append("Color: inherited from paint"); 318 str->appendHex(fColor);
332 } else {
333 str->append("Color: ");
334 str->appendHex(fColor);
335 }
336 319
337 this->INHERITED::toString(str); 320 this->INHERITED::toString(str);
338 321
339 str->append(")"); 322 str->append(")");
340 } 323 }
341 #endif 324 #endif
342 325
343 /////////////////////////////////////////////////////////////////////////////// 326 ///////////////////////////////////////////////////////////////////////////////
344 327
345 #ifndef SK_IGNORE_TO_STRING 328 #ifndef SK_IGNORE_TO_STRING
346 #include "SkEmptyShader.h" 329 #include "SkEmptyShader.h"
347 330
348 void SkEmptyShader::toString(SkString* str) const { 331 void SkEmptyShader::toString(SkString* str) const {
349 str->append("SkEmptyShader: ("); 332 str->append("SkEmptyShader: (");
350 333
351 this->INHERITED::toString(str); 334 this->INHERITED::toString(str);
352 335
353 str->append(")"); 336 str->append(")");
354 } 337 }
355 #endif 338 #endif
OLDNEW
« no previous file with comments | « src/core/SkBlitter.cpp ('k') | tests/ShaderOpacityTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698