Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 this->getLocalMatrix().toString(str); | 192 this->getLocalMatrix().toString(str); |
| 193 } | 193 } |
| 194 } | 194 } |
| 195 #endif | 195 #endif |
| 196 | 196 |
| 197 ////////////////////////////////////////////////////////////////////////////// | 197 ////////////////////////////////////////////////////////////////////////////// |
| 198 | 198 |
| 199 #include "SkColorShader.h" | 199 #include "SkColorShader.h" |
| 200 #include "SkUtils.h" | 200 #include "SkUtils.h" |
| 201 | 201 |
| 202 SkColorShader::SkColorShader() { | |
| 203 fFlags = 0; | |
| 204 fInheritColor = true; | |
| 205 } | |
| 206 | |
| 207 SkColorShader::SkColorShader(SkColor c) { | 202 SkColorShader::SkColorShader(SkColor c) { |
| 208 fFlags = 0; | 203 fFlags = 0; |
| 209 fColor = c; | 204 fColor = c; |
| 210 fInheritColor = false; | |
| 211 } | 205 } |
| 212 | 206 |
| 213 SkColorShader::~SkColorShader() {} | 207 SkColorShader::~SkColorShader() {} |
| 214 | 208 |
| 215 bool SkColorShader::isOpaque() const { | 209 bool SkColorShader::isOpaque() const { |
| 216 if (fInheritColor) { | |
| 217 return true; // using paint's alpha | |
| 218 } | |
| 219 return SkColorGetA(fColor) == 255; | 210 return SkColorGetA(fColor) == 255; |
| 220 } | 211 } |
| 221 | 212 |
| 222 SkColorShader::SkColorShader(SkReadBuffer& b) : INHERITED(b) { | 213 SkColorShader::SkColorShader(SkReadBuffer& b) : INHERITED(b) { |
| 223 fFlags = 0; // computed in setContext | 214 fFlags = 0; // computed in setContext |
| 224 | 215 |
| 225 fInheritColor = b.readBool(); | 216 // An older version had a boolean to make the color shader inherit the paint 's color. We don't |
|
mtklein
2014/04/22 21:49:07
Can you add // V25_COMPATIBILITY_CODE here to make
| |
| 226 if (fInheritColor) { | 217 // support that any more. |
| 227 return; | 218 if (b.pictureVersion() < 26 && 0 != b.pictureVersion()) { |
| 219 if (b.readBool()) { | |
|
mtklein
2014/04/22 21:49:07
Replace with SkAssertResult(!b.readBool())?
bsalomon
2014/04/23 15:22:29
I added an SkDebugFail just after sending out the
| |
| 220 fColor = SK_ColorWHITE; | |
| 221 return; | |
| 222 } | |
| 228 } | 223 } |
| 229 fColor = b.readColor(); | 224 fColor = b.readColor(); |
| 230 } | 225 } |
| 231 | 226 |
| 232 void SkColorShader::flatten(SkWriteBuffer& buffer) const { | 227 void SkColorShader::flatten(SkWriteBuffer& buffer) const { |
| 233 this->INHERITED::flatten(buffer); | 228 this->INHERITED::flatten(buffer); |
| 234 buffer.writeBool(fInheritColor); | |
| 235 if (fInheritColor) { | |
| 236 return; | |
| 237 } | |
| 238 buffer.writeColor(fColor); | 229 buffer.writeColor(fColor); |
| 239 } | 230 } |
| 240 | 231 |
| 241 uint32_t SkColorShader::getFlags() { | 232 uint32_t SkColorShader::getFlags() { |
| 242 return fFlags; | 233 return fFlags; |
| 243 } | 234 } |
| 244 | 235 |
| 245 uint8_t SkColorShader::getSpan16Alpha() const { | 236 uint8_t SkColorShader::getSpan16Alpha() const { |
| 246 return SkGetPackedA32(fPMColor); | 237 return SkGetPackedA32(fPMColor); |
| 247 } | 238 } |
| 248 | 239 |
| 249 bool SkColorShader::setContext(const SkBitmap& device, const SkPaint& paint, | 240 bool SkColorShader::setContext(const SkBitmap& device, const SkPaint& paint, |
| 250 const SkMatrix& matrix) { | 241 const SkMatrix& matrix) { |
| 251 if (!this->INHERITED::setContext(device, paint, matrix)) { | 242 if (!this->INHERITED::setContext(device, paint, matrix)) { |
| 252 return false; | 243 return false; |
| 253 } | 244 } |
| 254 | 245 |
| 255 unsigned a; | 246 unsigned a; |
| 256 | 247 |
| 257 if (fInheritColor) { | 248 a = SkAlphaMul(SkColorGetA(fColor), SkAlpha255To256(paint.getAlpha())); |
| 258 fColor = paint.getColor(); | |
| 259 a = SkColorGetA(fColor); | |
| 260 } else { | |
| 261 a = SkAlphaMul(SkColorGetA(fColor), SkAlpha255To256(paint.getAlpha())); | |
| 262 } | |
| 263 | 249 |
| 264 unsigned r = SkColorGetR(fColor); | 250 unsigned r = SkColorGetR(fColor); |
| 265 unsigned g = SkColorGetG(fColor); | 251 unsigned g = SkColorGetG(fColor); |
| 266 unsigned b = SkColorGetB(fColor); | 252 unsigned b = SkColorGetB(fColor); |
| 267 | 253 |
| 268 // we want this before we apply any alpha | 254 // we want this before we apply any alpha |
| 269 fColor16 = SkPack888ToRGB16(r, g, b); | 255 fColor16 = SkPack888ToRGB16(r, g, b); |
| 270 | 256 |
| 271 if (a != 255) { | 257 if (a != 255) { |
| 272 r = SkMulDiv255Round(r, a); | 258 r = SkMulDiv255Round(r, a); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 info->fColorCount = 1; | 298 info->fColorCount = 1; |
| 313 info->fTileMode = SkShader::kRepeat_TileMode; | 299 info->fTileMode = SkShader::kRepeat_TileMode; |
| 314 } | 300 } |
| 315 return kColor_GradientType; | 301 return kColor_GradientType; |
| 316 } | 302 } |
| 317 | 303 |
| 318 #ifndef SK_IGNORE_TO_STRING | 304 #ifndef SK_IGNORE_TO_STRING |
| 319 void SkColorShader::toString(SkString* str) const { | 305 void SkColorShader::toString(SkString* str) const { |
| 320 str->append("SkColorShader: ("); | 306 str->append("SkColorShader: ("); |
| 321 | 307 |
| 322 if (fInheritColor) { | 308 str->append("Color: "); |
| 323 str->append("Color: inherited from paint"); | 309 str->appendHex(fColor); |
| 324 } else { | |
| 325 str->append("Color: "); | |
| 326 str->appendHex(fColor); | |
| 327 } | |
| 328 | 310 |
| 329 this->INHERITED::toString(str); | 311 this->INHERITED::toString(str); |
| 330 | 312 |
| 331 str->append(")"); | 313 str->append(")"); |
| 332 } | 314 } |
| 333 #endif | 315 #endif |
| 334 | 316 |
| 335 /////////////////////////////////////////////////////////////////////////////// | 317 /////////////////////////////////////////////////////////////////////////////// |
| 336 | 318 |
| 337 #include "SkEmptyShader.h" | 319 #include "SkEmptyShader.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 356 | 338 |
| 357 #ifndef SK_IGNORE_TO_STRING | 339 #ifndef SK_IGNORE_TO_STRING |
| 358 void SkEmptyShader::toString(SkString* str) const { | 340 void SkEmptyShader::toString(SkString* str) const { |
| 359 str->append("SkEmptyShader: ("); | 341 str->append("SkEmptyShader: ("); |
| 360 | 342 |
| 361 this->INHERITED::toString(str); | 343 this->INHERITED::toString(str); |
| 362 | 344 |
| 363 str->append(")"); | 345 str->append(")"); |
| 364 } | 346 } |
| 365 #endif | 347 #endif |
| OLD | NEW |