Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Unified Diff: src/gpu/SkGpuDevice.cpp

Issue 283803003: Move skPaint2GrPaint to SkGr.h/cpp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add else clause to Sk2GrShader Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/gpu/SkGr.h ('k') | src/gpu/SkGr.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/SkGpuDevice.cpp
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 0aee983f7561eaa852059b04d0d21f88d39b043f..338cb156a57d937b1bddbaf92dff12603f063b8a 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -20,7 +20,6 @@
#include "SkGrTexturePixelRef.h"
#include "SkBounder.h"
-#include "SkColorFilter.h"
#include "SkDeviceImageFilterProxy.h"
#include "SkDrawProcs.h"
#include "SkGlyphCache.h"
@@ -377,119 +376,6 @@ SK_COMPILE_ASSERT(SkShader::kTwoPointConical_BitmapType == 5,
SK_COMPILE_ASSERT(SkShader::kLinear_BitmapType == 6, shader_type_mismatch);
SK_COMPILE_ASSERT(SkShader::kLast_BitmapType == 6, shader_type_mismatch);
-namespace {
-
-// converts a SkPaint to a GrPaint, ignoring the skPaint's shader
-// justAlpha indicates that skPaint's alpha should be used rather than the color
-// Callers may subsequently modify the GrPaint. Setting constantColor indicates
-// that the final paint will draw the same color at every pixel. This allows
-// an optimization where the the color filter can be applied to the skPaint's
-// color once while converting to GrPaint and then ignored.
-inline bool skPaint2GrPaintNoShader(SkGpuDevice* dev,
- const SkPaint& skPaint,
- bool justAlpha,
- bool constantColor,
- GrPaint* grPaint) {
-
- grPaint->setDither(skPaint.isDither());
- grPaint->setAntiAlias(skPaint.isAntiAlias());
-
- SkXfermode::Coeff sm;
- SkXfermode::Coeff dm;
-
- SkXfermode* mode = skPaint.getXfermode();
- GrEffectRef* xferEffect = NULL;
- if (SkXfermode::AsNewEffectOrCoeff(mode, &xferEffect, &sm, &dm)) {
- if (NULL != xferEffect) {
- grPaint->addColorEffect(xferEffect)->unref();
- sm = SkXfermode::kOne_Coeff;
- dm = SkXfermode::kZero_Coeff;
- }
- } else {
- //SkDEBUGCODE(SkDebugf("Unsupported xfer mode.\n");)
-#if 0
- return false;
-#else
- // Fall back to src-over
- sm = SkXfermode::kOne_Coeff;
- dm = SkXfermode::kISA_Coeff;
-#endif
- }
- grPaint->setBlendFunc(sk_blend_to_grblend(sm), sk_blend_to_grblend(dm));
-
- if (justAlpha) {
- uint8_t alpha = skPaint.getAlpha();
- grPaint->setColor(GrColorPackRGBA(alpha, alpha, alpha, alpha));
- // justAlpha is currently set to true only if there is a texture,
- // so constantColor should not also be true.
- SkASSERT(!constantColor);
- } else {
- grPaint->setColor(SkColor2GrColor(skPaint.getColor()));
- }
-
- SkColorFilter* colorFilter = skPaint.getColorFilter();
- if (NULL != colorFilter) {
- // if the source color is a constant then apply the filter here once rather than per pixel
- // in a shader.
- if (constantColor) {
- SkColor filtered = colorFilter->filterColor(skPaint.getColor());
- grPaint->setColor(SkColor2GrColor(filtered));
- } else {
- SkAutoTUnref<GrEffectRef> effect(colorFilter->asNewEffect(dev->context()));
- if (NULL != effect.get()) {
- grPaint->addColorEffect(effect);
- }
- }
- }
-
- return true;
-}
-
-// This function is similar to skPaint2GrPaintNoShader but also converts
-// skPaint's shader to a GrTexture/GrEffectStage if possible. The texture to
-// be used is set on grPaint and returned in param act. constantColor has the
-// same meaning as in skPaint2GrPaintNoShader.
-inline bool skPaint2GrPaintShader(SkGpuDevice* dev,
- const SkPaint& skPaint,
- bool constantColor,
- GrPaint* grPaint) {
- SkShader* shader = skPaint.getShader();
- if (NULL == shader) {
- return skPaint2GrPaintNoShader(dev, skPaint, false, constantColor, grPaint);
- }
-
- // SkShader::asNewEffect() may do offscreen rendering. Setup default drawing state and require
- // the shader to set a render target .
- GrContext::AutoWideOpenIdentityDraw awo(dev->context(), NULL);
-
- // setup the shader as the first color effect on the paint
- SkAutoTUnref<GrEffectRef> effect(shader->asNewEffect(dev->context(), skPaint, NULL));
- if (NULL != effect.get()) {
- grPaint->addColorEffect(effect);
- // Now setup the rest of the paint.
- return skPaint2GrPaintNoShader(dev, skPaint, true, false, grPaint);
- } else {
- // We still don't have SkColorShader::asNewEffect() implemented.
- SkShader::GradientInfo info;
- SkColor color;
-
- info.fColors = &color;
- info.fColorOffsets = NULL;
- info.fColorCount = 1;
- if (SkShader::kColor_GradientType == shader->asAGradient(&info)) {
- SkPaint copy(skPaint);
- copy.setShader(NULL);
- // modulate the paint alpha by the shader's solid color alpha
- U8CPU newA = SkMulDiv255Round(SkColorGetA(color), copy.getAlpha());
- copy.setColor(SkColorSetA(color, newA));
- return skPaint2GrPaintNoShader(dev, copy, false, constantColor, grPaint);
- } else {
- return false;
- }
- }
-}
-}
-
///////////////////////////////////////////////////////////////////////////////
SkBitmap::Config SkGpuDevice::config() const {
@@ -511,9 +397,7 @@ void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
CHECK_SHOULD_DRAW(draw, false);
GrPaint grPaint;
- if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
- return;
- }
+ SkPaint2GrPaintShader(this, paint, true, &grPaint);
fContext->drawPaint(grPaint);
}
@@ -543,9 +427,7 @@ void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
}
GrPaint grPaint;
- if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
- return;
- }
+ SkPaint2GrPaintShader(this, paint, true, &grPaint);
fContext->drawVertices(grPaint,
gPointMode2PrimtiveType[mode],
@@ -602,9 +484,7 @@ void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect,
}
GrPaint grPaint;
- if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
- return;
- }
+ SkPaint2GrPaintShader(this, paint, true, &grPaint);
if (!doStroke) {
fContext->drawRect(grPaint, rect);
@@ -622,9 +502,7 @@ void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect,
CHECK_SHOULD_DRAW(draw, false);
GrPaint grPaint;
- if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
- return;
- }
+ SkPaint2GrPaintShader(this, paint, true, &grPaint);
SkStrokeRec stroke(paint);
if (paint.getMaskFilter()) {
@@ -678,9 +556,7 @@ void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer,
CHECK_SHOULD_DRAW(draw, false);
GrPaint grPaint;
- if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
- return;
- }
+ SkPaint2GrPaintShader(this, paint, true, &grPaint);
if (NULL == paint.getMaskFilter() && NULL == paint.getPathEffect()) {
fContext->drawDRRect(grPaint, outer, inner);
@@ -718,9 +594,7 @@ void SkGpuDevice::drawOval(const SkDraw& draw, const SkRect& oval,
}
GrPaint grPaint;
- if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
- return;
- }
+ SkPaint2GrPaintShader(this, paint, true, &grPaint);
SkStrokeRec stroke(paint);
fContext->drawOval(grPaint, oval, stroke);
@@ -871,9 +745,7 @@ void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath,
CHECK_SHOULD_DRAW(draw, false);
GrPaint grPaint;
- if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
- return;
- }
+ SkPaint2GrPaintShader(this, paint, true, &grPaint);
// If we have a prematrix, apply it to the path, optimizing for the case
// where the original path can in fact be modified in place (even though
@@ -1521,9 +1393,7 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap,
GrPaint grPaint;
grPaint.addColorEffect(effect);
bool alphaOnly = !(SkBitmap::kA8_Config == bitmap.config());
- if (!skPaint2GrPaintNoShader(this, paint, alphaOnly, false, &grPaint)) {
- return;
- }
+ SkPaint2GrPaintNoShader(this, paint, alphaOnly, false, &grPaint);
fContext->drawRectToRect(grPaint, dstRect, paintRect, NULL);
}
@@ -1589,9 +1459,7 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
GrPaint grPaint;
grPaint.addColorTextureEffect(texture, SkMatrix::I());
- if(!skPaint2GrPaintNoShader(this, paint, true, false, &grPaint)) {
- return;
- }
+ SkPaint2GrPaintNoShader(this, paint, true, false, &grPaint);
fContext->drawRectToRect(grPaint,
SkRect::MakeXYWH(SkIntToScalar(left),
@@ -1699,9 +1567,7 @@ void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device,
GrPaint grPaint;
grPaint.addColorTextureEffect(devTex, SkMatrix::I());
- if (!skPaint2GrPaintNoShader(this, paint, true, false, &grPaint)) {
- return;
- }
+ SkPaint2GrPaintNoShader(this, paint, true, false, &grPaint);
SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(x),
SkIntToScalar(y),
@@ -1762,13 +1628,9 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
GrPaint grPaint;
// we ignore the shader if texs is null.
if (NULL == texs) {
- if (!skPaint2GrPaintNoShader(this, paint, false, NULL == colors, &grPaint)) {
- return;
- }
+ SkPaint2GrPaintNoShader(this, paint, false, NULL == colors, &grPaint);
} else {
- if (!skPaint2GrPaintShader(this, paint, NULL == colors, &grPaint)) {
- return;
- }
+ SkPaint2GrPaintShader(this, paint, NULL == colors, &grPaint);
}
if (NULL != xmode && NULL != texs && NULL != colors) {
@@ -1808,18 +1670,14 @@ void SkGpuDevice::drawText(const SkDraw& draw, const void* text,
if (fMainTextContext->canDraw(paint)) {
GrPaint grPaint;
- if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
- return;
- }
+ SkPaint2GrPaintShader(this, paint, true, &grPaint);
SkDEBUGCODE(this->validate();)
fMainTextContext->drawText(grPaint, paint, (const char *)text, byteLength, x, y);
} else if (fFallbackTextContext && fFallbackTextContext->canDraw(paint)) {
GrPaint grPaint;
- if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
- return;
- }
+ SkPaint2GrPaintShader(this, paint, true, &grPaint);
SkDEBUGCODE(this->validate();)
@@ -1838,9 +1696,7 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text,
if (fMainTextContext->canDraw(paint)) {
GrPaint grPaint;
- if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
- return;
- }
+ SkPaint2GrPaintShader(this, paint, true, &grPaint);
SkDEBUGCODE(this->validate();)
@@ -1848,9 +1704,7 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text,
constY, scalarsPerPos);
} else if (fFallbackTextContext && fFallbackTextContext->canDraw(paint)) {
GrPaint grPaint;
- if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
- return;
- }
+ SkPaint2GrPaintShader(this, paint, true, &grPaint);
SkDEBUGCODE(this->validate();)
« no previous file with comments | « include/gpu/SkGr.h ('k') | src/gpu/SkGr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698