Pass in GrContext instead of SkGpuDevice for dashing and Sk2GrPaint conversion
BUG=skia: R=bsalomon@google.com Author: egdaniel@google.com Review URL: https://codereview.chromium.org/292773002 git-svn-id: http://skia.googlecode.com/svn/trunk@14790 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
584f337832
commit
3595f88aff
@ -77,21 +77,19 @@ void GrUnlockAndUnrefCachedBitmapTexture(GrTexture*);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class SkGpuDevice;
|
||||
|
||||
// Converts a SkPaint to a GrPaint, ignoring the SkPaint's shader.
|
||||
// justAlpha indicates that the 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.
|
||||
void SkPaint2GrPaintNoShader(SkGpuDevice* dev, const SkPaint& skPaint, bool justAlpha,
|
||||
void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, bool justAlpha,
|
||||
bool constantColor, GrPaint* grPaint);
|
||||
|
||||
// This function is similar to skPaint2GrPaintNoShader but also converts
|
||||
// skPaint's shader to a GrTexture/GrEffectStage if possible.
|
||||
// constantColor has the same meaning as in skPaint2GrPaintNoShader.
|
||||
void SkPaint2GrPaintShader(SkGpuDevice* dev, const SkPaint& skPaint,
|
||||
void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint,
|
||||
bool constantColor, GrPaint* grPaint);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -398,7 +398,7 @@ void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
|
||||
CHECK_SHOULD_DRAW(draw, false);
|
||||
|
||||
GrPaint grPaint;
|
||||
SkPaint2GrPaintShader(this, paint, true, &grPaint);
|
||||
SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
|
||||
|
||||
fContext->drawPaint(grPaint);
|
||||
}
|
||||
@ -421,7 +421,7 @@ void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
|
||||
}
|
||||
|
||||
if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mode) {
|
||||
if (GrDashingEffect::DrawDashLine(pts, paint, this)) {
|
||||
if (GrDashingEffect::DrawDashLine(pts, paint, this->context())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -434,7 +434,7 @@ void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
|
||||
}
|
||||
|
||||
GrPaint grPaint;
|
||||
SkPaint2GrPaintShader(this, paint, true, &grPaint);
|
||||
SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
|
||||
|
||||
fContext->drawVertices(grPaint,
|
||||
gPointMode2PrimtiveType[mode],
|
||||
@ -491,7 +491,7 @@ void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect,
|
||||
}
|
||||
|
||||
GrPaint grPaint;
|
||||
SkPaint2GrPaintShader(this, paint, true, &grPaint);
|
||||
SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
|
||||
|
||||
if (!doStroke) {
|
||||
fContext->drawRect(grPaint, rect);
|
||||
@ -509,7 +509,7 @@ void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect,
|
||||
CHECK_SHOULD_DRAW(draw, false);
|
||||
|
||||
GrPaint grPaint;
|
||||
SkPaint2GrPaintShader(this, paint, true, &grPaint);
|
||||
SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
|
||||
|
||||
SkStrokeRec stroke(paint);
|
||||
if (paint.getMaskFilter()) {
|
||||
@ -563,7 +563,7 @@ void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer,
|
||||
CHECK_SHOULD_DRAW(draw, false);
|
||||
|
||||
GrPaint grPaint;
|
||||
SkPaint2GrPaintShader(this, paint, true, &grPaint);
|
||||
SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
|
||||
|
||||
if (NULL == paint.getMaskFilter() && NULL == paint.getPathEffect()) {
|
||||
fContext->drawDRRect(grPaint, outer, inner);
|
||||
@ -601,7 +601,7 @@ void SkGpuDevice::drawOval(const SkDraw& draw, const SkRect& oval,
|
||||
}
|
||||
|
||||
GrPaint grPaint;
|
||||
SkPaint2GrPaintShader(this, paint, true, &grPaint);
|
||||
SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
|
||||
SkStrokeRec stroke(paint);
|
||||
|
||||
fContext->drawOval(grPaint, oval, stroke);
|
||||
@ -752,7 +752,7 @@ void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath,
|
||||
CHECK_SHOULD_DRAW(draw, false);
|
||||
|
||||
GrPaint grPaint;
|
||||
SkPaint2GrPaintShader(this, paint, true, &grPaint);
|
||||
SkPaint2GrPaintShader(this->context(), 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
|
||||
@ -1400,7 +1400,7 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap,
|
||||
GrPaint grPaint;
|
||||
grPaint.addColorEffect(effect);
|
||||
bool alphaOnly = !(SkBitmap::kA8_Config == bitmap.config());
|
||||
SkPaint2GrPaintNoShader(this, paint, alphaOnly, false, &grPaint);
|
||||
SkPaint2GrPaintNoShader(this->context(), paint, alphaOnly, false, &grPaint);
|
||||
|
||||
fContext->drawRectToRect(grPaint, dstRect, paintRect, NULL);
|
||||
}
|
||||
@ -1466,7 +1466,7 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
|
||||
GrPaint grPaint;
|
||||
grPaint.addColorTextureEffect(texture, SkMatrix::I());
|
||||
|
||||
SkPaint2GrPaintNoShader(this, paint, true, false, &grPaint);
|
||||
SkPaint2GrPaintNoShader(this->context(), paint, true, false, &grPaint);
|
||||
|
||||
fContext->drawRectToRect(grPaint,
|
||||
SkRect::MakeXYWH(SkIntToScalar(left),
|
||||
@ -1574,7 +1574,7 @@ void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device,
|
||||
GrPaint grPaint;
|
||||
grPaint.addColorTextureEffect(devTex, SkMatrix::I());
|
||||
|
||||
SkPaint2GrPaintNoShader(this, paint, true, false, &grPaint);
|
||||
SkPaint2GrPaintNoShader(this->context(), paint, true, false, &grPaint);
|
||||
|
||||
SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(x),
|
||||
SkIntToScalar(y),
|
||||
@ -1635,9 +1635,9 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
|
||||
GrPaint grPaint;
|
||||
// we ignore the shader if texs is null.
|
||||
if (NULL == texs) {
|
||||
SkPaint2GrPaintNoShader(this, paint, false, NULL == colors, &grPaint);
|
||||
SkPaint2GrPaintNoShader(this->context(), paint, false, NULL == colors, &grPaint);
|
||||
} else {
|
||||
SkPaint2GrPaintShader(this, paint, NULL == colors, &grPaint);
|
||||
SkPaint2GrPaintShader(this->context(), paint, NULL == colors, &grPaint);
|
||||
}
|
||||
|
||||
if (NULL != xmode && NULL != texs && NULL != colors) {
|
||||
@ -1677,14 +1677,14 @@ void SkGpuDevice::drawText(const SkDraw& draw, const void* text,
|
||||
|
||||
if (fMainTextContext->canDraw(paint)) {
|
||||
GrPaint grPaint;
|
||||
SkPaint2GrPaintShader(this, paint, true, &grPaint);
|
||||
SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
|
||||
|
||||
SkDEBUGCODE(this->validate();)
|
||||
|
||||
fMainTextContext->drawText(grPaint, paint, (const char *)text, byteLength, x, y);
|
||||
} else if (fFallbackTextContext && fFallbackTextContext->canDraw(paint)) {
|
||||
GrPaint grPaint;
|
||||
SkPaint2GrPaintShader(this, paint, true, &grPaint);
|
||||
SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
|
||||
|
||||
SkDEBUGCODE(this->validate();)
|
||||
|
||||
@ -1703,7 +1703,7 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text,
|
||||
|
||||
if (fMainTextContext->canDraw(paint)) {
|
||||
GrPaint grPaint;
|
||||
SkPaint2GrPaintShader(this, paint, true, &grPaint);
|
||||
SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
|
||||
|
||||
SkDEBUGCODE(this->validate();)
|
||||
|
||||
@ -1711,7 +1711,7 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text,
|
||||
constY, scalarsPerPos);
|
||||
} else if (fFallbackTextContext && fFallbackTextContext->canDraw(paint)) {
|
||||
GrPaint grPaint;
|
||||
SkPaint2GrPaintShader(this, paint, true, &grPaint);
|
||||
SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
|
||||
|
||||
SkDEBUGCODE(this->validate();)
|
||||
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include "SkGr.h"
|
||||
#include "SkColorFilter.h"
|
||||
#include "SkConfig8888.h"
|
||||
#include "SkGpuDevice.h"
|
||||
#include "SkMessageBus.h"
|
||||
#include "SkPixelRef.h"
|
||||
#include "GrResourceCache.h"
|
||||
@ -328,7 +327,7 @@ bool GrPixelConfig2ColorType(GrPixelConfig config, SkColorType* ctOut) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void SkPaint2GrPaintNoShader(SkGpuDevice* dev, const SkPaint& skPaint, bool justAlpha,
|
||||
void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, bool justAlpha,
|
||||
bool constantColor, GrPaint* grPaint) {
|
||||
|
||||
grPaint->setDither(skPaint.isDither());
|
||||
@ -371,7 +370,7 @@ void SkPaint2GrPaintNoShader(SkGpuDevice* dev, const SkPaint& skPaint, bool just
|
||||
SkColor filtered = colorFilter->filterColor(skPaint.getColor());
|
||||
grPaint->setColor(SkColor2GrColor(filtered));
|
||||
} else {
|
||||
SkAutoTUnref<GrEffectRef> effect(colorFilter->asNewEffect(dev->context()));
|
||||
SkAutoTUnref<GrEffectRef> effect(colorFilter->asNewEffect(context));
|
||||
if (NULL != effect.get()) {
|
||||
grPaint->addColorEffect(effect);
|
||||
}
|
||||
@ -379,24 +378,24 @@ void SkPaint2GrPaintNoShader(SkGpuDevice* dev, const SkPaint& skPaint, bool just
|
||||
}
|
||||
}
|
||||
|
||||
void SkPaint2GrPaintShader(SkGpuDevice* dev, const SkPaint& skPaint,
|
||||
void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint,
|
||||
bool constantColor, GrPaint* grPaint) {
|
||||
SkShader* shader = skPaint.getShader();
|
||||
if (NULL == shader) {
|
||||
SkPaint2GrPaintNoShader(dev, skPaint, false, constantColor, grPaint);
|
||||
SkPaint2GrPaintNoShader(context, skPaint, false, constantColor, grPaint);
|
||||
return;
|
||||
}
|
||||
|
||||
// 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);
|
||||
GrContext::AutoWideOpenIdentityDraw awo(context, NULL);
|
||||
|
||||
// setup the shader as the first color effect on the paint
|
||||
SkAutoTUnref<GrEffectRef> effect(shader->asNewEffect(dev->context(), skPaint, NULL));
|
||||
SkAutoTUnref<GrEffectRef> effect(shader->asNewEffect(context, skPaint, NULL));
|
||||
if (NULL != effect.get()) {
|
||||
grPaint->addColorEffect(effect);
|
||||
// Now setup the rest of the paint.
|
||||
SkPaint2GrPaintNoShader(dev, skPaint, true, false, grPaint);
|
||||
SkPaint2GrPaintNoShader(context, skPaint, true, false, grPaint);
|
||||
} else {
|
||||
// We still don't have SkColorShader::asNewEffect() implemented.
|
||||
SkShader::GradientInfo info;
|
||||
@ -411,9 +410,9 @@ void SkPaint2GrPaintShader(SkGpuDevice* dev, const SkPaint& skPaint,
|
||||
// modulate the paint alpha by the shader's solid color alpha
|
||||
U8CPU newA = SkMulDiv255Round(SkColorGetA(color), copy.getAlpha());
|
||||
copy.setColor(SkColorSetA(color, newA));
|
||||
SkPaint2GrPaintNoShader(dev, copy, false, constantColor, grPaint);
|
||||
SkPaint2GrPaintNoShader(context, copy, false, constantColor, grPaint);
|
||||
} else {
|
||||
SkPaint2GrPaintNoShader(dev, skPaint, false, constantColor, grPaint);
|
||||
SkPaint2GrPaintNoShader(context, skPaint, false, constantColor, grPaint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include "GrDrawTargetCaps.h"
|
||||
#include "GrEffect.h"
|
||||
#include "GrTBackendEffectFactory.h"
|
||||
#include "SkGpuDevice.h"
|
||||
#include "SkGr.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -87,8 +86,7 @@ static SkScalar calc_end_adjustment(const SkPathEffect::DashInfo& info, const Sk
|
||||
}
|
||||
|
||||
|
||||
bool GrDashingEffect::DrawDashLine(const SkPoint pts[2], const SkPaint& paint, SkGpuDevice* dev) {
|
||||
GrContext* context = dev->context();
|
||||
bool GrDashingEffect::DrawDashLine(const SkPoint pts[2], const SkPaint& paint, GrContext* context) {
|
||||
if (context->getRenderTarget()->isMultisampled()) {
|
||||
return false;
|
||||
}
|
||||
@ -139,7 +137,7 @@ bool GrDashingEffect::DrawDashLine(const SkPoint pts[2], const SkPaint& paint, S
|
||||
}
|
||||
|
||||
GrPaint grPaint;
|
||||
SkPaint2GrPaintShader(dev, paint, true, &grPaint);
|
||||
SkPaint2GrPaintShader(context, paint, true, &grPaint);
|
||||
|
||||
bool useAA = paint.isAntiAlias();
|
||||
|
||||
|
@ -12,13 +12,13 @@
|
||||
#include "GrTypesPriv.h"
|
||||
#include "SkPathEffect.h"
|
||||
|
||||
class SkGpuDevice;
|
||||
class GrContext;
|
||||
|
||||
class GrGLDashingEffect;
|
||||
class SkPath;
|
||||
|
||||
namespace GrDashingEffect {
|
||||
bool DrawDashLine(const SkPoint pnts[2], const SkPaint& paint, SkGpuDevice* dev);
|
||||
bool DrawDashLine(const SkPoint pnts[2], const SkPaint& paint, GrContext* context);
|
||||
|
||||
/**
|
||||
* An effect that renders a dashed line. It is intended to be used as a coverage effect.
|
||||
|
Loading…
Reference in New Issue
Block a user