| 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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 | 245 |
| 246 #ifndef SK_IGNORE_TO_STRING | 246 #ifndef SK_IGNORE_TO_STRING |
| 247 void SkShader::toString(SkString* str) const { | 247 void SkShader::toString(SkString* str) const { |
| 248 if (!fLocalMatrix.isIdentity()) { | 248 if (!fLocalMatrix.isIdentity()) { |
| 249 str->append(" "); | 249 str->append(" "); |
| 250 fLocalMatrix.toString(str); | 250 fLocalMatrix.toString(str); |
| 251 } | 251 } |
| 252 } | 252 } |
| 253 #endif | 253 #endif |
| 254 | 254 |
| 255 ////////////////////////////////////////////////////////////////////////////// | 255 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 256 | |
| 257 #include "SkUtils.h" | |
| 258 | |
| 259 SkColorShader::SkColorShader(SkColor c) | |
| 260 : fColor(c) { | |
| 261 } | |
| 262 | |
| 263 bool SkColorShader::isOpaque() const { | |
| 264 return SkColorGetA(fColor) == 255; | |
| 265 } | |
| 266 | |
| 267 sk_sp<SkFlattenable> SkColorShader::CreateProc(SkReadBuffer& buffer) { | |
| 268 return sk_make_sp<SkColorShader>(buffer.readColor()); | |
| 269 } | |
| 270 | |
| 271 void SkColorShader::flatten(SkWriteBuffer& buffer) const { | |
| 272 buffer.writeColor(fColor); | |
| 273 } | |
| 274 | |
| 275 uint32_t SkColorShader::ColorShaderContext::getFlags() const { | |
| 276 return fFlags; | |
| 277 } | |
| 278 | |
| 279 SkShader::Context* SkColorShader::onCreateContext(const ContextRec& rec, void* s
torage) const { | |
| 280 return new (storage) ColorShaderContext(*this, rec); | |
| 281 } | |
| 282 | |
| 283 SkColorShader::ColorShaderContext::ColorShaderContext(const SkColorShader& shade
r, | |
| 284 const ContextRec& rec) | |
| 285 : INHERITED(shader, rec) | |
| 286 { | |
| 287 SkColor color = shader.fColor; | |
| 288 unsigned a = SkAlphaMul(SkColorGetA(color), SkAlpha255To256(rec.fPaint->getA
lpha())); | |
| 289 | |
| 290 unsigned r = SkColorGetR(color); | |
| 291 unsigned g = SkColorGetG(color); | |
| 292 unsigned b = SkColorGetB(color); | |
| 293 | |
| 294 if (a != 255) { | |
| 295 r = SkMulDiv255Round(r, a); | |
| 296 g = SkMulDiv255Round(g, a); | |
| 297 b = SkMulDiv255Round(b, a); | |
| 298 } | |
| 299 fPMColor = SkPackARGB32(a, r, g, b); | |
| 300 | |
| 301 SkColor4f c4 = SkColor4f::FromColor(shader.fColor); | |
| 302 c4.fA *= rec.fPaint->getAlpha() / 255.0f; | |
| 303 fPM4f = c4.premul(); | |
| 304 | |
| 305 fFlags = kConstInY32_Flag; | |
| 306 if (255 == a) { | |
| 307 fFlags |= kOpaqueAlpha_Flag; | |
| 308 } | |
| 309 } | |
| 310 | |
| 311 void SkColorShader::ColorShaderContext::shadeSpan(int x, int y, SkPMColor span[]
, int count) { | |
| 312 sk_memset32(span, fPMColor, count); | |
| 313 } | |
| 314 | |
| 315 void SkColorShader::ColorShaderContext::shadeSpanAlpha(int x, int y, uint8_t alp
ha[], int count) { | |
| 316 memset(alpha, SkGetPackedA32(fPMColor), count); | |
| 317 } | |
| 318 | |
| 319 void SkColorShader::ColorShaderContext::shadeSpan4f(int x, int y, SkPM4f span[],
int count) { | |
| 320 for (int i = 0; i < count; ++i) { | |
| 321 span[i] = fPM4f; | |
| 322 } | |
| 323 } | |
| 324 | |
| 325 SkShader::GradientType SkColorShader::asAGradient(GradientInfo* info) const { | |
| 326 if (info) { | |
| 327 if (info->fColors && info->fColorCount >= 1) { | |
| 328 info->fColors[0] = fColor; | |
| 329 } | |
| 330 info->fColorCount = 1; | |
| 331 info->fTileMode = SkShader::kRepeat_TileMode; | |
| 332 } | |
| 333 return kColor_GradientType; | |
| 334 } | |
| 335 | |
| 336 #if SK_SUPPORT_GPU | |
| 337 | |
| 338 #include "SkGr.h" | |
| 339 #include "effects/GrConstColorProcessor.h" | |
| 340 const GrFragmentProcessor* SkColorShader::asFragmentProcessor(GrContext*, const
SkMatrix&, | |
| 341 const SkMatrix*, | |
| 342 SkFilterQuality) c
onst { | |
| 343 GrColor color = SkColorToPremulGrColor(fColor); | |
| 344 return GrConstColorProcessor::Create(color, GrConstColorProcessor::kModulate
A_InputMode); | |
| 345 } | |
| 346 | |
| 347 #endif | |
| 348 | |
| 349 #ifndef SK_IGNORE_TO_STRING | |
| 350 void SkColorShader::toString(SkString* str) const { | |
| 351 str->append("SkColorShader: ("); | |
| 352 | |
| 353 str->append("Color: "); | |
| 354 str->appendHex(fColor); | |
| 355 | |
| 356 this->INHERITED::toString(str); | |
| 357 | |
| 358 str->append(")"); | |
| 359 } | |
| 360 #endif | |
| 361 | |
| 362 /////////////////////////////////////////////////////////////////////////////// | |
| 363 | |
| 364 static void D32_BlitBW(SkShader::Context::BlitState* state, int x, int y, const
SkPixmap& dst, | |
| 365 int count) { | |
| 366 SkXfermode::D32Proc proc = (SkXfermode::D32Proc)state->fStorage[0]; | |
| 367 const SkPM4f* src = (const SkPM4f*)state->fStorage[1]; | |
| 368 proc(state->fXfer, dst.writable_addr32(x, y), src, count, nullptr); | |
| 369 } | |
| 370 | |
| 371 static void D32_BlitAA(SkShader::Context::BlitState* state, int x, int y, const
SkPixmap& dst, | |
| 372 int count, const SkAlpha aa[]) { | |
| 373 SkXfermode::D32Proc proc = (SkXfermode::D32Proc)state->fStorage[0]; | |
| 374 const SkPM4f* src = (const SkPM4f*)state->fStorage[1]; | |
| 375 proc(state->fXfer, dst.writable_addr32(x, y), src, count, aa); | |
| 376 } | |
| 377 | |
| 378 static void F16_BlitBW(SkShader::Context::BlitState* state, int x, int y, const
SkPixmap& dst, | |
| 379 int count) { | |
| 380 SkXfermode::F16Proc proc = (SkXfermode::F16Proc)state->fStorage[0]; | |
| 381 const SkPM4f* src = (const SkPM4f*)state->fStorage[1]; | |
| 382 proc(state->fXfer, dst.writable_addr64(x, y), src, count, nullptr); | |
| 383 } | |
| 384 | |
| 385 static void F16_BlitAA(SkShader::Context::BlitState* state, int x, int y, const
SkPixmap& dst, | |
| 386 int count, const SkAlpha aa[]) { | |
| 387 SkXfermode::F16Proc proc = (SkXfermode::F16Proc)state->fStorage[0]; | |
| 388 const SkPM4f* src = (const SkPM4f*)state->fStorage[1]; | |
| 389 proc(state->fXfer, dst.writable_addr64(x, y), src, count, aa); | |
| 390 } | |
| 391 | |
| 392 bool SkColorShader::ColorShaderContext::onChooseBlitProcs(const SkImageInfo& inf
o, | |
| 393 BlitState* state) { | |
| 394 uint32_t flags = SkXfermode::kSrcIsSingle_D32Flag; | |
| 395 if (fPM4f.a() == 1) { | |
| 396 flags |= SkXfermode::kSrcIsOpaque_D32Flag; | |
| 397 } | |
| 398 switch (info.colorType()) { | |
| 399 case kN32_SkColorType: | |
| 400 if (info.isSRGB()) { | |
| 401 flags |= SkXfermode::kDstIsSRGB_D32Flag; | |
| 402 } | |
| 403 state->fStorage[0] = (void*)SkXfermode::GetD32Proc(state->fXfer, fla
gs); | |
| 404 state->fStorage[1] = &fPM4f; | |
| 405 state->fBlitBW = D32_BlitBW; | |
| 406 state->fBlitAA = D32_BlitAA; | |
| 407 return true; | |
| 408 case kRGBA_F16_SkColorType: | |
| 409 state->fStorage[0] = (void*)SkXfermode::GetF16Proc(state->fXfer, fla
gs); | |
| 410 state->fStorage[1] = &fPM4f; | |
| 411 state->fBlitBW = F16_BlitBW; | |
| 412 state->fBlitAA = F16_BlitAA; | |
| 413 return true; | |
| 414 default: | |
| 415 return false; | |
| 416 } | |
| 417 } | |
| 418 | |
| 419 /////////////////////////////////////////////////////////////////////////////// | |
| 420 | 256 |
| 421 sk_sp<SkFlattenable> SkEmptyShader::CreateProc(SkReadBuffer&) { | 257 sk_sp<SkFlattenable> SkEmptyShader::CreateProc(SkReadBuffer&) { |
| 422 return SkShader::MakeEmptyShader(); | 258 return SkShader::MakeEmptyShader(); |
| 423 } | 259 } |
| 424 | 260 |
| 425 #ifndef SK_IGNORE_TO_STRING | 261 #ifndef SK_IGNORE_TO_STRING |
| 426 #include "SkEmptyShader.h" | 262 #include "SkEmptyShader.h" |
| 427 | 263 |
| 428 void SkEmptyShader::toString(SkString* str) const { | 264 void SkEmptyShader::toString(SkString* str) const { |
| 429 str->append("SkEmptyShader: ("); | 265 str->append("SkEmptyShader: ("); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 453 } | 289 } |
| 454 #endif | 290 #endif |
| 455 | 291 |
| 456 #ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR | 292 #ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR |
| 457 #include "SkXfermode.h" | 293 #include "SkXfermode.h" |
| 458 sk_sp<SkShader> SkShader::MakeComposeShader(sk_sp<SkShader> dst, sk_sp<SkShader>
src, | 294 sk_sp<SkShader> SkShader::MakeComposeShader(sk_sp<SkShader> dst, sk_sp<SkShader>
src, |
| 459 SkXfermode* xfer) { | 295 SkXfermode* xfer) { |
| 460 return MakeComposeShader(std::move(dst), std::move(src), sk_ref_sp(xfer)); | 296 return MakeComposeShader(std::move(dst), std::move(src), sk_ref_sp(xfer)); |
| 461 } | 297 } |
| 462 #endif | 298 #endif |
| OLD | NEW |