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 bool 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");) | |
robertphillips
2014/05/13 16:24:11
What's up with this? All caller seem to handle the
egdaniel
2014/05/13 17:35:54
I tried following AsNewEffectOrCoeff to see what f
bsalomon
2014/05/13 20:34:29
I think we should just remove the return false. We
| |
350 #if 0 | |
351 return false; | |
352 #else | |
353 // Fall back to src-over | |
354 sm = SkXfermode::kOne_Coeff; | |
355 dm = SkXfermode::kISA_Coeff; | |
356 #endif | |
357 } | |
358 grPaint->setBlendFunc(sk_blend_to_grblend(sm), sk_blend_to_grblend(dm)); | |
359 | |
360 if (justAlpha) { | |
361 uint8_t alpha = skPaint.getAlpha(); | |
362 grPaint->setColor(GrColorPackRGBA(alpha, alpha, alpha, alpha)); | |
363 // justAlpha is currently set to true only if there is a texture, | |
364 // so constantColor should not also be true. | |
365 SkASSERT(!constantColor); | |
366 } else { | |
367 grPaint->setColor(SkColor2GrColor(skPaint.getColor())); | |
368 } | |
369 | |
370 SkColorFilter* colorFilter = skPaint.getColorFilter(); | |
371 if (NULL != colorFilter) { | |
372 // if the source color is a constant then apply the filter here once rat her than per pixel | |
373 // in a shader. | |
374 if (constantColor) { | |
375 SkColor filtered = colorFilter->filterColor(skPaint.getColor()); | |
376 grPaint->setColor(SkColor2GrColor(filtered)); | |
377 } else { | |
378 SkAutoTUnref<GrEffectRef> effect(colorFilter->asNewEffect(dev->conte xt())); | |
379 if (NULL != effect.get()) { | |
380 grPaint->addColorEffect(effect); | |
381 } | |
382 } | |
383 } | |
384 | |
385 return true; | |
386 } | |
387 | |
388 bool SkPaint2GrPaintShader(SkGpuDevice* dev, const SkPaint& skPaint, | |
389 bool constantColor, GrPaint* grPaint) { | |
390 SkShader* shader = skPaint.getShader(); | |
391 if (NULL == shader) { | |
392 return SkPaint2GrPaintNoShader(dev, skPaint, false, constantColor, grPai nt); | |
393 } | |
394 | |
395 // SkShader::asNewEffect() may do offscreen rendering. Setup default drawing state and require | |
396 // the shader to set a render target . | |
397 GrContext::AutoWideOpenIdentityDraw awo(dev->context(), NULL); | |
398 | |
399 // setup the shader as the first color effect on the paint | |
400 SkAutoTUnref<GrEffectRef> effect(shader->asNewEffect(dev->context(), skPaint , NULL)); | |
401 if (NULL != effect.get()) { | |
402 grPaint->addColorEffect(effect); | |
403 // Now setup the rest of the paint. | |
404 return SkPaint2GrPaintNoShader(dev, skPaint, true, false, grPaint); | |
405 } else { | |
robertphillips
2014/05/13 16:24:11
Do we have a TODO for this? Is it something an int
egdaniel
2014/05/13 17:35:54
Getting this implemented should allow us to remove
bsalomon
2014/05/13 20:34:29
Same argument here. Let's just make the function v
| |
406 // We still don't have SkColorShader::asNewEffect() implemented. | |
407 SkShader::GradientInfo info; | |
408 SkColor color; | |
409 | |
410 info.fColors = &color; | |
411 info.fColorOffsets = NULL; | |
412 info.fColorCount = 1; | |
413 if (SkShader::kColor_GradientType == shader->asAGradient(&info)) { | |
414 SkPaint copy(skPaint); | |
415 copy.setShader(NULL); | |
416 // modulate the paint alpha by the shader's solid color alpha | |
417 U8CPU newA = SkMulDiv255Round(SkColorGetA(color), copy.getAlpha()); | |
418 copy.setColor(SkColorSetA(color, newA)); | |
419 return SkPaint2GrPaintNoShader(dev, copy, false, constantColor, grPa int); | |
420 } else { | |
421 return false; | |
422 } | |
423 } | |
424 } | |
425 | |
OLD | NEW |