OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
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 "SkGr.h" | 8 #include "SkGr.h" |
| 9 #include "SkColorFilter.h" |
9 #include "SkConfig8888.h" | 10 #include "SkConfig8888.h" |
| 11 #include "SkGpuDevice.h" |
10 #include "SkMessageBus.h" | 12 #include "SkMessageBus.h" |
11 #include "SkPixelRef.h" | 13 #include "SkPixelRef.h" |
12 #include "GrResourceCache.h" | 14 #include "GrResourceCache.h" |
13 | 15 |
14 /* Fill out buffer with the compressed format Ganesh expects from a colortable | 16 /* Fill out buffer with the compressed format Ganesh expects from a colortable |
15 based bitmap. [palette (colortable) + indices]. | 17 based bitmap. [palette (colortable) + indices]. |
16 | 18 |
17 At the moment Ganesh only supports 8bit version. If Ganesh allowed we others | 19 At the moment Ganesh only supports 8bit version. If Ganesh allowed we others |
18 we could detect that the colortable.count is <= 16, and then repack the | 20 we could detect that the colortable.count is <= 16, and then repack the |
19 indices as nibbles to save RAM, but it would take more time (i.e. a lot | 21 indices as nibbles to save RAM, but it would take more time (i.e. a lot |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 ct = kBGRA_8888_SkColorType; | 318 ct = kBGRA_8888_SkColorType; |
317 break; | 319 break; |
318 default: | 320 default: |
319 return false; | 321 return false; |
320 } | 322 } |
321 if (ctOut) { | 323 if (ctOut) { |
322 *ctOut = ct; | 324 *ctOut = ct; |
323 } | 325 } |
324 return true; | 326 return true; |
325 } | 327 } |
| 328 |
| 329 /////////////////////////////////////////////////////////////////////////////// |
| 330 |
| 331 void SkPaint2GrPaintNoShader(SkGpuDevice* dev, const SkPaint& skPaint, bool just
Alpha, |
| 332 bool constantColor, GrPaint* grPaint) { |
| 333 |
| 334 grPaint->setDither(skPaint.isDither()); |
| 335 grPaint->setAntiAlias(skPaint.isAntiAlias()); |
| 336 |
| 337 SkXfermode::Coeff sm; |
| 338 SkXfermode::Coeff dm; |
| 339 |
| 340 SkXfermode* mode = skPaint.getXfermode(); |
| 341 GrEffectRef* xferEffect = NULL; |
| 342 if (SkXfermode::AsNewEffectOrCoeff(mode, &xferEffect, &sm, &dm)) { |
| 343 if (NULL != xferEffect) { |
| 344 grPaint->addColorEffect(xferEffect)->unref(); |
| 345 sm = SkXfermode::kOne_Coeff; |
| 346 dm = SkXfermode::kZero_Coeff; |
| 347 } |
| 348 } else { |
| 349 //SkDEBUGCODE(SkDebugf("Unsupported xfer mode.\n");) |
| 350 // Fall back to src-over |
| 351 sm = SkXfermode::kOne_Coeff; |
| 352 dm = SkXfermode::kISA_Coeff; |
| 353 } |
| 354 grPaint->setBlendFunc(sk_blend_to_grblend(sm), sk_blend_to_grblend(dm)); |
| 355 |
| 356 if (justAlpha) { |
| 357 uint8_t alpha = skPaint.getAlpha(); |
| 358 grPaint->setColor(GrColorPackRGBA(alpha, alpha, alpha, alpha)); |
| 359 // justAlpha is currently set to true only if there is a texture, |
| 360 // so constantColor should not also be true. |
| 361 SkASSERT(!constantColor); |
| 362 } else { |
| 363 grPaint->setColor(SkColor2GrColor(skPaint.getColor())); |
| 364 } |
| 365 |
| 366 SkColorFilter* colorFilter = skPaint.getColorFilter(); |
| 367 if (NULL != colorFilter) { |
| 368 // if the source color is a constant then apply the filter here once rat
her than per pixel |
| 369 // in a shader. |
| 370 if (constantColor) { |
| 371 SkColor filtered = colorFilter->filterColor(skPaint.getColor()); |
| 372 grPaint->setColor(SkColor2GrColor(filtered)); |
| 373 } else { |
| 374 SkAutoTUnref<GrEffectRef> effect(colorFilter->asNewEffect(dev->conte
xt())); |
| 375 if (NULL != effect.get()) { |
| 376 grPaint->addColorEffect(effect); |
| 377 } |
| 378 } |
| 379 } |
| 380 } |
| 381 |
| 382 void SkPaint2GrPaintShader(SkGpuDevice* dev, const SkPaint& skPaint, |
| 383 bool constantColor, GrPaint* grPaint) { |
| 384 SkShader* shader = skPaint.getShader(); |
| 385 if (NULL == shader) { |
| 386 SkPaint2GrPaintNoShader(dev, skPaint, false, constantColor, grPaint); |
| 387 return; |
| 388 } |
| 389 |
| 390 // SkShader::asNewEffect() may do offscreen rendering. Setup default drawing
state and require |
| 391 // the shader to set a render target. |
| 392 GrContext::AutoWideOpenIdentityDraw awo(dev->context(), NULL); |
| 393 |
| 394 // setup the shader as the first color effect on the paint |
| 395 SkAutoTUnref<GrEffectRef> effect(shader->asNewEffect(dev->context(), skPaint
, NULL)); |
| 396 if (NULL != effect.get()) { |
| 397 grPaint->addColorEffect(effect); |
| 398 // Now setup the rest of the paint. |
| 399 SkPaint2GrPaintNoShader(dev, skPaint, true, false, grPaint); |
| 400 } else { |
| 401 // We still don't have SkColorShader::asNewEffect() implemented. |
| 402 SkShader::GradientInfo info; |
| 403 SkColor color; |
| 404 |
| 405 info.fColors = &color; |
| 406 info.fColorOffsets = NULL; |
| 407 info.fColorCount = 1; |
| 408 if (SkShader::kColor_GradientType == shader->asAGradient(&info)) { |
| 409 SkPaint copy(skPaint); |
| 410 copy.setShader(NULL); |
| 411 // modulate the paint alpha by the shader's solid color alpha |
| 412 U8CPU newA = SkMulDiv255Round(SkColorGetA(color), copy.getAlpha()); |
| 413 copy.setColor(SkColorSetA(color, newA)); |
| 414 SkPaint2GrPaintNoShader(dev, copy, false, constantColor, grPaint); |
| 415 } else { |
| 416 SkPaint2GrPaintNoShader(dev, skPaint, false, constantColor, grPaint)
; |
| 417 } |
| 418 } |
| 419 } |
| 420 |
OLD | NEW |