| 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 "SkAtomics.h" | 8 #include "SkAtomics.h" |
| 9 #include "SkBitmapProcShader.h" | 9 #include "SkBitmapProcShader.h" |
| 10 #include "SkColorShader.h" | 10 #include "SkColorShader.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 112 } |
| 113 | 113 |
| 114 SkShader::Context::~Context() {} | 114 SkShader::Context::~Context() {} |
| 115 | 115 |
| 116 SkShader::Context::ShadeProc SkShader::Context::asAShadeProc(void** ctx) { | 116 SkShader::Context::ShadeProc SkShader::Context::asAShadeProc(void** ctx) { |
| 117 return nullptr; | 117 return nullptr; |
| 118 } | 118 } |
| 119 | 119 |
| 120 #include "SkColorPriv.h" | 120 #include "SkColorPriv.h" |
| 121 | 121 |
| 122 void SkShader::Context::shadeSpan16(int x, int y, uint16_t span16[], int count)
{ | |
| 123 SkASSERT(span16); | |
| 124 SkASSERT(count > 0); | |
| 125 SkASSERT(this->canCallShadeSpan16()); | |
| 126 | |
| 127 // basically, if we get here, the subclass screwed up | |
| 128 SkDEBUGFAIL("kHasSpan16 flag is set, but shadeSpan16() not implemented"); | |
| 129 } | |
| 130 | |
| 131 #define kTempColorQuadCount 6 // balance between speed (larger) and saving sta
ck-space | 122 #define kTempColorQuadCount 6 // balance between speed (larger) and saving sta
ck-space |
| 132 #define kTempColorCount (kTempColorQuadCount << 2) | 123 #define kTempColorCount (kTempColorQuadCount << 2) |
| 133 | 124 |
| 134 #ifdef SK_CPU_BENDIAN | 125 #ifdef SK_CPU_BENDIAN |
| 135 #define SkU32BitShiftToByteOffset(shift) (3 - ((shift) >> 3)) | 126 #define SkU32BitShiftToByteOffset(shift) (3 - ((shift) >> 3)) |
| 136 #else | 127 #else |
| 137 #define SkU32BitShiftToByteOffset(shift) ((shift) >> 3) | 128 #define SkU32BitShiftToByteOffset(shift) ((shift) >> 3) |
| 138 #endif | 129 #endif |
| 139 | 130 |
| 140 void SkShader::Context::shadeSpanAlpha(int x, int y, uint8_t alpha[], int count)
{ | 131 void SkShader::Context::shadeSpanAlpha(int x, int y, uint8_t alpha[], int count)
{ |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 } | 250 } |
| 260 | 251 |
| 261 void SkColorShader::flatten(SkWriteBuffer& buffer) const { | 252 void SkColorShader::flatten(SkWriteBuffer& buffer) const { |
| 262 buffer.writeColor(fColor); | 253 buffer.writeColor(fColor); |
| 263 } | 254 } |
| 264 | 255 |
| 265 uint32_t SkColorShader::ColorShaderContext::getFlags() const { | 256 uint32_t SkColorShader::ColorShaderContext::getFlags() const { |
| 266 return fFlags; | 257 return fFlags; |
| 267 } | 258 } |
| 268 | 259 |
| 269 uint8_t SkColorShader::ColorShaderContext::getSpan16Alpha() const { | |
| 270 return SkGetPackedA32(fPMColor); | |
| 271 } | |
| 272 | |
| 273 SkShader::Context* SkColorShader::onCreateContext(const ContextRec& rec, void* s
torage) const { | 260 SkShader::Context* SkColorShader::onCreateContext(const ContextRec& rec, void* s
torage) const { |
| 274 return new (storage) ColorShaderContext(*this, rec); | 261 return new (storage) ColorShaderContext(*this, rec); |
| 275 } | 262 } |
| 276 | 263 |
| 277 SkColorShader::ColorShaderContext::ColorShaderContext(const SkColorShader& shade
r, | 264 SkColorShader::ColorShaderContext::ColorShaderContext(const SkColorShader& shade
r, |
| 278 const ContextRec& rec) | 265 const ContextRec& rec) |
| 279 : INHERITED(shader, rec) | 266 : INHERITED(shader, rec) |
| 280 { | 267 { |
| 281 SkColor color = shader.fColor; | 268 SkColor color = shader.fColor; |
| 282 unsigned a = SkAlphaMul(SkColorGetA(color), SkAlpha255To256(rec.fPaint->getA
lpha())); | 269 unsigned a = SkAlphaMul(SkColorGetA(color), SkAlpha255To256(rec.fPaint->getA
lpha())); |
| 283 | 270 |
| 284 unsigned r = SkColorGetR(color); | 271 unsigned r = SkColorGetR(color); |
| 285 unsigned g = SkColorGetG(color); | 272 unsigned g = SkColorGetG(color); |
| 286 unsigned b = SkColorGetB(color); | 273 unsigned b = SkColorGetB(color); |
| 287 | 274 |
| 288 // we want this before we apply any alpha | |
| 289 fColor16 = SkPack888ToRGB16(r, g, b); | |
| 290 | |
| 291 if (a != 255) { | 275 if (a != 255) { |
| 292 r = SkMulDiv255Round(r, a); | 276 r = SkMulDiv255Round(r, a); |
| 293 g = SkMulDiv255Round(g, a); | 277 g = SkMulDiv255Round(g, a); |
| 294 b = SkMulDiv255Round(b, a); | 278 b = SkMulDiv255Round(b, a); |
| 295 } | 279 } |
| 296 fPMColor = SkPackARGB32(a, r, g, b); | 280 fPMColor = SkPackARGB32(a, r, g, b); |
| 297 | 281 |
| 298 fFlags = kConstInY32_Flag; | 282 fFlags = kConstInY32_Flag; |
| 299 if (255 == a) { | 283 if (255 == a) { |
| 300 fFlags |= kOpaqueAlpha_Flag; | 284 fFlags |= kOpaqueAlpha_Flag; |
| 301 if (rec.fPaint->isDither() == false) { | |
| 302 fFlags |= kHasSpan16_Flag; | |
| 303 } | |
| 304 } | 285 } |
| 305 } | 286 } |
| 306 | 287 |
| 307 void SkColorShader::ColorShaderContext::shadeSpan(int x, int y, SkPMColor span[]
, int count) { | 288 void SkColorShader::ColorShaderContext::shadeSpan(int x, int y, SkPMColor span[]
, int count) { |
| 308 sk_memset32(span, fPMColor, count); | 289 sk_memset32(span, fPMColor, count); |
| 309 } | 290 } |
| 310 | 291 |
| 311 void SkColorShader::ColorShaderContext::shadeSpan16(int x, int y, uint16_t span[
], int count) { | |
| 312 sk_memset16(span, fColor16, count); | |
| 313 } | |
| 314 | |
| 315 void SkColorShader::ColorShaderContext::shadeSpanAlpha(int x, int y, uint8_t alp
ha[], int count) { | 292 void SkColorShader::ColorShaderContext::shadeSpanAlpha(int x, int y, uint8_t alp
ha[], int count) { |
| 316 memset(alpha, SkGetPackedA32(fPMColor), count); | 293 memset(alpha, SkGetPackedA32(fPMColor), count); |
| 317 } | 294 } |
| 318 | 295 |
| 319 SkShader::GradientType SkColorShader::asAGradient(GradientInfo* info) const { | 296 SkShader::GradientType SkColorShader::asAGradient(GradientInfo* info) const { |
| 320 if (info) { | 297 if (info) { |
| 321 if (info->fColors && info->fColorCount >= 1) { | 298 if (info->fColors && info->fColorCount >= 1) { |
| 322 info->fColors[0] = fColor; | 299 info->fColors[0] = fColor; |
| 323 } | 300 } |
| 324 info->fColorCount = 1; | 301 info->fColorCount = 1; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 #include "SkEmptyShader.h" | 340 #include "SkEmptyShader.h" |
| 364 | 341 |
| 365 void SkEmptyShader::toString(SkString* str) const { | 342 void SkEmptyShader::toString(SkString* str) const { |
| 366 str->append("SkEmptyShader: ("); | 343 str->append("SkEmptyShader: ("); |
| 367 | 344 |
| 368 this->INHERITED::toString(str); | 345 this->INHERITED::toString(str); |
| 369 | 346 |
| 370 str->append(")"); | 347 str->append(")"); |
| 371 } | 348 } |
| 372 #endif | 349 #endif |
| OLD | NEW |