Pass Rendertarget into context.

Adding Jim for text context stuff, and Steven for image blur stuff.

BUG=skia:

Review URL: https://codereview.chromium.org/939623005
This commit is contained in:
joshualitt 2015-02-18 12:29:52 -08:00 committed by Commit bot
parent 5a105ff053
commit 25d9c15408
25 changed files with 321 additions and 310 deletions

View File

@ -93,8 +93,6 @@ protected:
GrContext::AutoClip acs(ctx, SkRect::MakeWH(2*S, 2*S));
ctx->setRenderTarget(target);
GrPaint paint;
paint.setPorterDuffXPFactory(SkXfermode::kSrcOver_Mode);
@ -111,7 +109,7 @@ protected:
tm.postIDiv(2*S, 2*S);
paint.addColorTextureProcessor(texture, tm);
ctx->drawRect(paint, vm, SkRect::MakeWH(2*S, 2*S));
ctx->drawRect(target, paint, vm, SkRect::MakeWH(2*S, 2*S));
// now update the lower right of the texture in first pass
// or upper right in second pass
@ -125,7 +123,7 @@ protected:
texture->writePixels(S, (i ? 0 : S), S, S,
texture->config(), gTextureData.get(),
4 * stride);
ctx->drawRect(paint, vm, SkRect::MakeWH(2*S, 2*S));
ctx->drawRect(target, paint, vm, SkRect::MakeWH(2*S, 2*S));
}
} else {
this->drawGpuOnlyMessage(canvas);

View File

@ -17,6 +17,7 @@
class GrContext;
class GrPaint;
class GrRenderTarget;
class SkBitmap;
class SkBlitter;
class SkCachedData;
@ -97,6 +98,7 @@ public:
* true if drawing was successful.
*/
virtual bool directFilterMaskGPU(GrContext* context,
GrRenderTarget* rt,
GrPaint* grp,
const SkMatrix& viewMatrix,
const SkStrokeRec& strokeRec,
@ -106,6 +108,7 @@ public:
* true if drawing was successful.
*/
virtual bool directFilterRRectMaskGPU(GrContext* context,
GrRenderTarget* rt,
GrPaint* grp,
const SkMatrix& viewMatrix,
const SkStrokeRec& strokeRec,

View File

@ -303,24 +303,6 @@ public:
*/
void setMaxTextureSizeOverride(int maxTextureSizeOverride);
///////////////////////////////////////////////////////////////////////////
// Render targets
/**
* Sets the render target.
* @param target the render target to set.
*/
void setRenderTarget(GrRenderTarget* target) {
fRenderTarget.reset(SkSafeRef(target));
}
/**
* Gets the current render target.
* @return the currently bound render target.
*/
const GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); }
GrRenderTarget* getRenderTarget() { return fRenderTarget.get(); }
/**
* Can the provided configuration act as a color render target?
*/
@ -408,7 +390,7 @@ public:
/**
* Draw everywhere (respecting the clip) with the paint.
*/
void drawPaint(const GrPaint&, const SkMatrix& viewMatrix);
void drawPaint(GrRenderTarget*, const GrPaint&, const SkMatrix& viewMatrix);
/**
* Draw the rect using a paint.
@ -422,7 +404,8 @@ public:
* mitered/beveled stroked based on stroke width.
* The rects coords are used to access the paint (through texture matrix)
*/
void drawRect(const GrPaint& paint,
void drawRect(GrRenderTarget*,
const GrPaint& paint,
const SkMatrix& viewMatrix,
const SkRect&,
const GrStrokeInfo* strokeInfo = NULL);
@ -437,7 +420,8 @@ public:
* @param localMatrix an optional matrix to transform the shader coordinates before applying
* to rectToDraw
*/
void drawNonAARectToRect(const GrPaint& paint,
void drawNonAARectToRect(GrRenderTarget*,
const GrPaint& paint,
const SkMatrix& viewMatrix,
const SkRect& rectToDraw,
const SkRect& localRect,
@ -446,11 +430,12 @@ public:
/**
* Draws a non-AA rect with paint and a localMatrix
*/
void drawNonAARectWithLocalMatrix(const GrPaint& paint,
void drawNonAARectWithLocalMatrix(GrRenderTarget* rt,
const GrPaint& paint,
const SkMatrix& viewMatrix,
const SkRect& rect,
const SkMatrix& localMatrix) {
this->drawNonAARectToRect(paint, viewMatrix, rect, rect, &localMatrix);
this->drawNonAARectToRect(rt, paint, viewMatrix, rect, rect, &localMatrix);
}
/**
@ -462,7 +447,10 @@ public:
* @param strokeInfo the stroke information (width, join, cap) and
* the dash information (intervals, count, phase).
*/
void drawRRect(const GrPaint&, const SkMatrix& viewMatrix, const SkRRect& rrect,
void drawRRect(GrRenderTarget*,
const GrPaint&,
const SkMatrix& viewMatrix,
const SkRRect& rrect,
const GrStrokeInfo&);
/**
@ -475,7 +463,10 @@ public:
* @param outer the outer roundrect
* @param inner the inner roundrect
*/
void drawDRRect(const GrPaint&, const SkMatrix& viewMatrix, const SkRRect& outer,
void drawDRRect(GrRenderTarget*,
const GrPaint&,
const SkMatrix& viewMatrix,
const SkRRect& outer,
const SkRRect& inner);
@ -488,7 +479,11 @@ public:
* @param strokeInfo the stroke information (width, join, cap) and
* the dash information (intervals, count, phase).
*/
void drawPath(const GrPaint&, const SkMatrix& viewMatrix, const SkPath&, const GrStrokeInfo&);
void drawPath(GrRenderTarget*,
const GrPaint&,
const SkMatrix& viewMatrix,
const SkPath&,
const GrStrokeInfo&);
/**
* Draws vertices with a paint.
@ -507,7 +502,8 @@ public:
* @param indexCount if indices is non-null then this is the
* number of indices.
*/
void drawVertices(const GrPaint& paint,
void drawVertices(GrRenderTarget*,
const GrPaint& paint,
const SkMatrix& viewMatrix,
GrPrimitiveType primitiveType,
int vertexCount,
@ -526,7 +522,8 @@ public:
* @param strokeInfo the stroke information (width, join, cap) and
* the dash information (intervals, count, phase).
*/
void drawOval(const GrPaint& paint,
void drawOval(GrRenderTarget*,
const GrPaint& paint,
const SkMatrix& viewMatrix,
const SkRect& oval,
const GrStrokeInfo& strokeInfo);
@ -670,30 +667,6 @@ public:
///////////////////////////////////////////////////////////////////////////
// Helpers
class AutoRenderTarget : public ::SkNoncopyable {
public:
AutoRenderTarget(GrContext* context, GrRenderTarget* target) {
fPrevTarget = context->getRenderTarget();
SkSafeRef(fPrevTarget);
context->setRenderTarget(target);
fContext = context;
}
AutoRenderTarget(GrContext* context) {
fPrevTarget = context->getRenderTarget();
SkSafeRef(fPrevTarget);
fContext = context;
}
~AutoRenderTarget() {
if (fContext) {
fContext->setRenderTarget(fPrevTarget);
}
SkSafeUnref(fPrevTarget);
}
private:
GrContext* fContext;
GrRenderTarget* fPrevTarget;
};
class AutoClip : public ::SkNoncopyable {
public:
// This enum exists to require a caller of the constructor to acknowledge that the clip will
@ -736,14 +709,12 @@ public:
class AutoWideOpenIdentityDraw {
public:
AutoWideOpenIdentityDraw(GrContext* ctx, GrRenderTarget* rt)
: fAutoClip(ctx, AutoClip::kWideOpen_InitialClip)
, fAutoRT(ctx, rt) {
AutoWideOpenIdentityDraw(GrContext* ctx)
: fAutoClip(ctx, AutoClip::kWideOpen_InitialClip) {
}
private:
AutoClip fAutoClip;
AutoRenderTarget fAutoRT;
};
///////////////////////////////////////////////////////////////////////////
@ -789,7 +760,6 @@ public:
private:
GrGpu* fGpu;
SkAutoTUnref<GrRenderTarget> fRenderTarget;
const GrClipData* fClip; // TODO: make this ref counted
GrResourceCache* fResourceCache;
@ -833,7 +803,8 @@ private:
class AutoCheckFlush;
// Sets the paint and returns the target to draw into. This function is overloaded to either
// take a GrDrawState, GrPaint, and AutoCheckFlush, or JUST an AutoCheckFlush
GrDrawTarget* prepareToDraw(GrPipelineBuilder*, const GrPaint* paint, const AutoCheckFlush*);
GrDrawTarget* prepareToDraw(GrPipelineBuilder*, GrRenderTarget* rt, const GrPaint* paint,
const AutoCheckFlush*);
void internalDrawPath(GrDrawTarget*,
GrPipelineBuilder*,

View File

@ -80,13 +80,13 @@ GrTexture* GrRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTexture
// 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(GrContext* context, const SkPaint& skPaint, GrColor paintColor,
bool constantColor, GrPaint* grPaint);
void SkPaint2GrPaintNoShader(GrContext* context, GrRenderTarget*, const SkPaint& skPaint,
GrColor paintColor, bool constantColor, GrPaint* grPaint);
// This function is similar to skPaint2GrPaintNoShader but also converts
// skPaint's shader to a GrFragmentProcessor if possible.
// constantColor has the same meaning as in skPaint2GrPaintNoShader.
void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint,
void SkPaint2GrPaintShader(GrContext* context, GrRenderTarget*, const SkPaint& skPaint,
const SkMatrix& viewM, bool constantColor, GrPaint* grPaint);
////////////////////////////////////////////////////////////////////////////////

View File

@ -292,7 +292,6 @@ public:
if (!IsGpuDeviceType(dType)) {
// need to send the raster bits to the (gpu) window
fCurContext->setRenderTarget(fCurRenderTarget);
const SkBitmap& bm = win->getBitmap();
fCurRenderTarget->writePixels(0, 0, bm.width(), bm.height(),
SkImageInfo2GrPixelConfig(bm.colorType(),

View File

@ -256,7 +256,7 @@ bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Cont
if (!dst) {
return false;
}
GrContext::AutoRenderTarget art(context, dst->asRenderTarget());
GrContext::AutoClip acs(context, dstRect);
GrFragmentProcessor* fp;
offset->fX = bounds.left();
@ -268,7 +268,7 @@ bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Cont
SkASSERT(fp);
GrPaint paint;
paint.addColorProcessor(fp)->unref();
context->drawNonAARectToRect(paint, SkMatrix::I(), dstRect, srcRect);
context->drawNonAARectToRect(dst->asRenderTarget(), paint, SkMatrix::I(), dstRect, srcRect);
WrapTexture(dst, bounds.width(), bounds.height(), result);
return true;
@ -382,7 +382,7 @@ bool SkImageFilter::getInputResultGPU(SkImageFilter::Proxy* proxy,
// matrix with no clip and that the matrix, clip, and render target set before this function was
// called are restored before we return to the caller.
GrContext* context = src.getTexture()->getContext();
GrContext::AutoWideOpenIdentityDraw awoid(context, NULL);
GrContext::AutoWideOpenIdentityDraw awoid(context);
if (this->canFilterImageGPU()) {
return this->filterImageGPU(proxy, src, ctx, result, offset);
} else {

View File

@ -316,6 +316,7 @@ bool SkMaskFilter::canFilterMaskGPU(const SkRect& devBounds,
}
bool SkMaskFilter::directFilterMaskGPU(GrContext* context,
GrRenderTarget* rt,
GrPaint* grp,
const SkMatrix& viewMatrix,
const SkStrokeRec& strokeRec,
@ -325,6 +326,7 @@ bool SkMaskFilter::canFilterMaskGPU(const SkRect& devBounds,
bool SkMaskFilter::directFilterRRectMaskGPU(GrContext* context,
GrRenderTarget* rt,
GrPaint* grp,
const SkMatrix& viewMatrix,
const SkStrokeRec& strokeRec,

View File

@ -285,7 +285,6 @@ bool SkAlphaThresholdFilterImpl::asFragmentProcessor(GrFragmentProcessor** fp,
}
{
GrContext::AutoRenderTarget art(context, maskTexture->asRenderTarget());
GrPaint grPaint;
grPaint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
SkRegion::Iterator iter(fRegion);
@ -293,7 +292,7 @@ bool SkAlphaThresholdFilterImpl::asFragmentProcessor(GrFragmentProcessor** fp,
while (!iter.done()) {
SkRect rect = SkRect::Make(iter.rect());
context->drawRect(grPaint, in_matrix, rect);
context->drawRect(maskTexture->asRenderTarget(), grPaint, in_matrix, rect);
iter.next();
}
}

View File

@ -48,11 +48,13 @@ public:
const SkMatrix& ctm,
SkRect* maskRect) const SK_OVERRIDE;
virtual bool directFilterMaskGPU(GrContext* context,
GrRenderTarget* rt,
GrPaint* grp,
const SkMatrix& viewMatrix,
const SkStrokeRec& strokeRec,
const SkPath& path) const SK_OVERRIDE;
virtual bool directFilterRRectMaskGPU(GrContext* context,
GrRenderTarget* rt,
GrPaint* grp,
const SkMatrix& viewMatrix,
const SkStrokeRec& strokeRec,
@ -826,6 +828,7 @@ GrFragmentProcessor* GrRectBlurEffect::TestCreate(SkRandom* random,
bool SkBlurMaskFilterImpl::directFilterMaskGPU(GrContext* context,
GrRenderTarget* rt,
GrPaint* grp,
const SkMatrix& viewMatrix,
const SkStrokeRec& strokeRec,
@ -860,7 +863,7 @@ bool SkBlurMaskFilterImpl::directFilterMaskGPU(GrContext* context,
if (!viewMatrix.invert(&inverse)) {
return false;
}
context->drawNonAARectWithLocalMatrix(*grp, SkMatrix::I(), rect, inverse);
context->drawNonAARectWithLocalMatrix(rt, *grp, SkMatrix::I(), rect, inverse);
return true;
}
@ -1115,6 +1118,7 @@ GrGLFragmentProcessor* GrRRectBlurEffect::createGLInstance() const {
}
bool SkBlurMaskFilterImpl::directFilterRRectMaskGPU(GrContext* context,
GrRenderTarget* rt,
GrPaint* grp,
const SkMatrix& viewMatrix,
const SkStrokeRec& strokeRec,
@ -1144,7 +1148,7 @@ bool SkBlurMaskFilterImpl::directFilterRRectMaskGPU(GrContext* context,
if (!viewMatrix.invert(&inverse)) {
return false;
}
context->drawNonAARectWithLocalMatrix(*grp, SkMatrix::I(), proxy_rect, inverse);
context->drawNonAARectWithLocalMatrix(rt, *grp, SkMatrix::I(), proxy_rect, inverse);
return true;
}
@ -1196,7 +1200,7 @@ bool SkBlurMaskFilterImpl::filterMaskGPU(GrTexture* src,
GrContext* context = src->getContext();
GrContext::AutoWideOpenIdentityDraw awo(context, NULL);
GrContext::AutoWideOpenIdentityDraw awo(context);
SkScalar xformedSigma = this->computeXformedSigma(ctm);
SkASSERT(xformedSigma > 0);
@ -1215,7 +1219,6 @@ bool SkBlurMaskFilterImpl::filterMaskGPU(GrTexture* src,
SkMatrix matrix;
matrix.setIDiv(src->width(), src->height());
// Blend pathTexture over blurTexture.
GrContext::AutoRenderTarget art(context, (*result)->asRenderTarget());
paint.addCoverageProcessor(GrSimpleTextureEffect::Create(src, matrix))->unref();
if (kInner_SkBlurStyle == fBlurStyle) {
// inner: dst = dst * src
@ -1229,7 +1232,7 @@ bool SkBlurMaskFilterImpl::filterMaskGPU(GrTexture* src,
// = 0 * src + (1 - src) * dst
paint.setCoverageSetOpXPFactory(SkRegion::kDifference_Op);
}
context->drawRect(paint, SkMatrix::I(), clipRect);
context->drawRect((*result)->asRenderTarget(), paint, SkMatrix::I(), clipRect);
}
return true;

View File

@ -429,8 +429,6 @@ bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src,
return false;
}
GrContext::AutoRenderTarget art(context, dst->asRenderTarget());
SkVector scale = SkVector::Make(fScale, fScale);
ctx.ctm().mapVectors(&scale, 1);
@ -451,7 +449,7 @@ bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src,
SkMatrix matrix;
matrix.setTranslate(-SkIntToScalar(colorBounds.x()),
-SkIntToScalar(colorBounds.y()));
context->drawRect(paint, matrix, SkRect::Make(colorBounds));
context->drawRect(dst->asRenderTarget(), paint, matrix, SkRect::Make(colorBounds));
offset->fX = bounds.left();
offset->fY = bounds.top();
WrapTexture(dst, bounds.width(), bounds.height(), result);

View File

@ -44,6 +44,7 @@ static float adjust_sigma(float sigma, int maxTextureSize, int *scaleFactor, int
}
static void convolve_gaussian_1d(GrContext* context,
GrRenderTarget* rt,
const SkRect& srcRect,
const SkRect& dstRect,
GrTexture* texture,
@ -56,10 +57,11 @@ static void convolve_gaussian_1d(GrContext* context,
SkAutoTUnref<GrFragmentProcessor> conv(GrConvolutionEffect::CreateGaussian(
texture, direction, radius, sigma, useBounds, bounds));
paint.addColorProcessor(conv);
context->drawNonAARectToRect(paint, SkMatrix::I(), dstRect, srcRect);
context->drawNonAARectToRect(rt, paint, SkMatrix::I(), dstRect, srcRect);
}
static void convolve_gaussian_2d(GrContext* context,
GrRenderTarget* rt,
const SkRect& srcRect,
const SkRect& dstRect,
GrTexture* texture,
@ -77,10 +79,11 @@ static void convolve_gaussian_2d(GrContext* context,
useBounds ? GrTextureDomain::kClamp_Mode : GrTextureDomain::kIgnore_Mode,
true, sigmaX, sigmaY));
paint.addColorProcessor(conv);
context->drawNonAARectToRect(paint, SkMatrix::I(), dstRect, srcRect);
context->drawNonAARectToRect(rt, paint, SkMatrix::I(), dstRect, srcRect);
}
static void convolve_gaussian(GrContext* context,
GrRenderTarget* rt,
const SkRect& srcRect,
const SkRect& dstRect,
GrTexture* texture,
@ -90,7 +93,7 @@ static void convolve_gaussian(GrContext* context,
bool cropToSrcRect) {
float bounds[2] = { 0.0f, 1.0f };
if (!cropToSrcRect) {
convolve_gaussian_1d(context, srcRect, dstRect, texture,
convolve_gaussian_1d(context, rt, srcRect, dstRect, texture,
direction, radius, sigma, false, bounds);
return;
}
@ -122,15 +125,15 @@ static void convolve_gaussian(GrContext* context,
}
if (radius >= size * SK_ScalarHalf) {
// Blur radius covers srcRect; use bounds over entire draw
convolve_gaussian_1d(context, srcRect, dstRect, texture,
convolve_gaussian_1d(context, rt, srcRect, dstRect, texture,
direction, radius, sigma, true, bounds);
} else {
// Draw upper and lower margins with bounds; middle without.
convolve_gaussian_1d(context, lowerSrcRect, lowerDstRect, texture,
convolve_gaussian_1d(context, rt, lowerSrcRect, lowerDstRect, texture,
direction, radius, sigma, true, bounds);
convolve_gaussian_1d(context, upperSrcRect, upperDstRect, texture,
convolve_gaussian_1d(context, rt, upperSrcRect, upperDstRect, texture,
direction, radius, sigma, true, bounds);
convolve_gaussian_1d(context, middleSrcRect, middleDstRect, texture,
convolve_gaussian_1d(context, rt, middleSrcRect, middleDstRect, texture,
direction, radius, sigma, false, bounds);
}
}
@ -144,8 +147,6 @@ GrTexture* GaussianBlur(GrContext* context,
float sigmaY) {
SkASSERT(context);
GrContext::AutoRenderTarget art(context);
SkIRect clearRect;
int scaleFactorX, radiusX;
int scaleFactorY, radiusY;
@ -192,7 +193,6 @@ GrTexture* GaussianBlur(GrContext* context,
GrPaint paint;
SkMatrix matrix;
matrix.setIDiv(srcTexture->width(), srcTexture->height());
context->setRenderTarget(dstTexture->asRenderTarget());
SkRect dstRect(srcRect);
if (cropToRect && i == 1) {
dstRect.offset(-dstRect.fLeft, -dstRect.fTop);
@ -213,7 +213,8 @@ GrTexture* GaussianBlur(GrContext* context,
}
scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f,
i < scaleFactorY ? 0.5f : 1.0f);
context->drawNonAARectToRect(paint, SkMatrix::I(), dstRect, srcRect);
context->drawNonAARectToRect(dstTexture->asRenderTarget(), paint, SkMatrix::I(), dstRect,
srcRect);
srcRect = dstRect;
srcTexture = dstTexture;
SkTSwap(dstTexture, tempTexture);
@ -227,10 +228,9 @@ GrTexture* GaussianBlur(GrContext* context,
(2 * radiusX + 1) * (2 * radiusY + 1) <= MAX_KERNEL_SIZE) {
// We shouldn't be scaling because this is a small size blur
SkASSERT((scaleFactorX == scaleFactorY) == 1);
context->setRenderTarget(dstTexture->asRenderTarget());
SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height());
convolve_gaussian_2d(context, srcRect, dstRect, srcTexture,
radiusX, radiusY, sigmaX, sigmaY, cropToRect, srcIRect);
convolve_gaussian_2d(context, dstTexture->asRenderTarget(), srcRect, dstRect, srcTexture,
radiusX, radiusY, sigmaX, sigmaY, cropToRect, srcIRect);
srcTexture = dstTexture;
srcRect = dstRect;
SkTSwap(dstTexture, tempTexture);
@ -242,11 +242,10 @@ GrTexture* GaussianBlur(GrContext* context,
// X convolution from reading garbage.
clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop,
radiusX, srcIRect.height());
context->clear(&clearRect, 0x0, false, context->getRenderTarget());
context->clear(&clearRect, 0x0, false, srcTexture->asRenderTarget());
}
context->setRenderTarget(dstTexture->asRenderTarget());
SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height());
convolve_gaussian(context, srcRect, dstRect, srcTexture,
convolve_gaussian(context, dstTexture->asRenderTarget(), srcRect, dstRect, srcTexture,
Gr1DKernelEffect::kX_Direction, radiusX, sigmaX, cropToRect);
srcTexture = dstTexture;
srcRect = dstRect;
@ -259,12 +258,11 @@ GrTexture* GaussianBlur(GrContext* context,
// convolution from reading garbage.
clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom,
srcIRect.width(), radiusY);
context->clear(&clearRect, 0x0, false, context->getRenderTarget());
context->clear(&clearRect, 0x0, false, srcTexture->asRenderTarget());
}
context->setRenderTarget(dstTexture->asRenderTarget());
SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height());
convolve_gaussian(context, srcRect, dstRect, srcTexture,
convolve_gaussian(context, dstTexture->asRenderTarget(), srcRect, dstRect, srcTexture,
Gr1DKernelEffect::kY_Direction, radiusY, sigmaY, cropToRect);
srcTexture = dstTexture;
srcRect = dstRect;
@ -277,13 +275,12 @@ GrTexture* GaussianBlur(GrContext* context,
// upsampling.
clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom,
srcIRect.width() + 1, 1);
context->clear(&clearRect, 0x0, false, context->getRenderTarget());
context->clear(&clearRect, 0x0, false, srcTexture->asRenderTarget());
clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop,
1, srcIRect.height());
context->clear(&clearRect, 0x0, false, context->getRenderTarget());
context->clear(&clearRect, 0x0, false, srcTexture->asRenderTarget());
SkMatrix matrix;
matrix.setIDiv(srcTexture->width(), srcTexture->height());
context->setRenderTarget(dstTexture->asRenderTarget());
GrPaint paint;
// FIXME: this should be mitchell, not bilinear.
@ -292,7 +289,8 @@ GrTexture* GaussianBlur(GrContext* context,
SkRect dstRect(srcRect);
scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY);
context->drawNonAARectToRect(paint, SkMatrix::I(), dstRect, srcRect);
context->drawNonAARectToRect(dstTexture->asRenderTarget(), paint, SkMatrix::I(), dstRect,
srcRect);
srcRect = dstRect;
srcTexture = dstTexture;
SkTSwap(dstTexture, tempTexture);

View File

@ -562,6 +562,7 @@ namespace {
void apply_morphology_rect(GrContext* context,
GrRenderTarget* rt,
GrTexture* texture,
const SkIRect& srcRect,
const SkIRect& dstRect,
@ -575,27 +576,29 @@ void apply_morphology_rect(GrContext* context,
radius,
morphType,
bounds))->unref();
context->drawNonAARectToRect(paint, SkMatrix::I(), SkRect::Make(dstRect),
SkRect::Make(srcRect));
context->drawNonAARectToRect(rt, paint, SkMatrix::I(), SkRect::Make(dstRect),
SkRect::Make(srcRect));
}
void apply_morphology_rect_no_bounds(GrContext* context,
GrTexture* texture,
const SkIRect& srcRect,
const SkIRect& dstRect,
int radius,
GrMorphologyEffect::MorphologyType morphType,
Gr1DKernelEffect::Direction direction) {
GrRenderTarget* rt,
GrTexture* texture,
const SkIRect& srcRect,
const SkIRect& dstRect,
int radius,
GrMorphologyEffect::MorphologyType morphType,
Gr1DKernelEffect::Direction direction) {
GrPaint paint;
paint.addColorProcessor(GrMorphologyEffect::Create(texture,
direction,
radius,
morphType))->unref();
context->drawNonAARectToRect(paint, SkMatrix::I(), SkRect::Make(dstRect),
SkRect::Make(srcRect));
context->drawNonAARectToRect(rt, paint, SkMatrix::I(), SkRect::Make(dstRect),
SkRect::Make(srcRect));
}
void apply_morphology_pass(GrContext* context,
GrRenderTarget* rt,
GrTexture* texture,
const SkIRect& srcRect,
const SkIRect& dstRect,
@ -627,15 +630,15 @@ void apply_morphology_pass(GrContext* context,
}
if (middleSrcRect.fLeft - middleSrcRect.fRight >= 0) {
// radius covers srcRect; use bounds over entire draw
apply_morphology_rect(context, texture, srcRect, dstRect, radius,
apply_morphology_rect(context, rt, texture, srcRect, dstRect, radius,
morphType, bounds, direction);
} else {
// Draw upper and lower margins with bounds; middle without.
apply_morphology_rect(context, texture, lowerSrcRect, lowerDstRect, radius,
apply_morphology_rect(context, rt,texture, lowerSrcRect, lowerDstRect, radius,
morphType, bounds, direction);
apply_morphology_rect(context, texture, upperSrcRect, upperDstRect, radius,
apply_morphology_rect(context, rt, texture, upperSrcRect, upperDstRect, radius,
morphType, bounds, direction);
apply_morphology_rect_no_bounds(context, texture, middleSrcRect, middleDstRect, radius,
apply_morphology_rect_no_bounds(context, rt, texture, middleSrcRect, middleDstRect, radius,
morphType, direction);
}
}
@ -665,9 +668,8 @@ bool apply_morphology(const SkBitmap& input,
if (NULL == texture) {
return false;
}
GrContext::AutoRenderTarget art(context, texture->asRenderTarget());
apply_morphology_pass(context, srcTexture, srcRect, dstRect, radius.fWidth,
morphType, Gr1DKernelEffect::kX_Direction);
apply_morphology_pass(context, texture->asRenderTarget(), srcTexture, srcRect, dstRect,
radius.fWidth, morphType, Gr1DKernelEffect::kX_Direction);
SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom,
dstRect.width(), radius.fHeight);
GrColor clearColor = GrMorphologyEffect::kErode_MorphologyType == morphType ?
@ -682,9 +684,8 @@ bool apply_morphology(const SkBitmap& input,
if (NULL == texture) {
return false;
}
GrContext::AutoRenderTarget art(context, texture->asRenderTarget());
apply_morphology_pass(context, srcTexture, srcRect, dstRect, radius.fHeight,
morphType, Gr1DKernelEffect::kY_Direction);
apply_morphology_pass(context, texture->asRenderTarget(), srcTexture, srcRect, dstRect,
radius.fHeight, morphType, Gr1DKernelEffect::kY_Direction);
srcTexture.reset(texture);
}
SkImageFilter::WrapTexture(srcTexture, rect.width(), rect.height(), dst);

View File

@ -154,7 +154,6 @@ bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy,
if (!dst) {
return false;
}
GrContext::AutoRenderTarget art(context, dst->asRenderTarget());
if (!fMode || !fMode->asFragmentProcessor(&xferProcessor, backgroundTex)) {
// canFilterImageGPU() should've taken care of this
@ -173,7 +172,7 @@ bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy,
GrPaint paint;
paint.addColorTextureProcessor(foregroundTex, foregroundMatrix);
paint.addColorProcessor(xferProcessor)->unref();
context->drawRect(paint, SkMatrix::I(), srcRect);
context->drawRect(dst->asRenderTarget(), paint, SkMatrix::I(), srcRect);
offset->fX = backgroundOffset.fX;
offset->fY = backgroundOffset.fY;

View File

@ -70,8 +70,9 @@ bool GrBitmapTextContext::canDraw(const SkPaint& paint, const SkMatrix& viewMatr
return !SkDraw::ShouldDrawTextAsPaths(paint, viewMatrix);
}
inline void GrBitmapTextContext::init(const GrPaint& paint, const SkPaint& skPaint) {
GrTextContext::init(paint, skPaint);
inline void GrBitmapTextContext::init(GrRenderTarget* rt, const GrPaint& paint,
const SkPaint& skPaint) {
GrTextContext::init(rt, paint, skPaint);
fStrike = NULL;
@ -83,7 +84,8 @@ inline void GrBitmapTextContext::init(const GrPaint& paint, const SkPaint& skPai
fTotalVertexCount = 0;
}
void GrBitmapTextContext::onDrawText(const GrPaint& paint, const SkPaint& skPaint,
void GrBitmapTextContext::onDrawText(GrRenderTarget* rt, const GrPaint& paint,
const SkPaint& skPaint,
const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
SkScalar x, SkScalar y) {
@ -94,7 +96,7 @@ void GrBitmapTextContext::onDrawText(const GrPaint& paint, const SkPaint& skPain
return;
}
this->init(paint, skPaint);
this->init(rt, paint, skPaint);
SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
@ -182,7 +184,8 @@ void GrBitmapTextContext::onDrawText(const GrPaint& paint, const SkPaint& skPain
this->finish();
}
void GrBitmapTextContext::onDrawPosText(const GrPaint& paint, const SkPaint& skPaint,
void GrBitmapTextContext::onDrawPosText(GrRenderTarget* rt, const GrPaint& paint,
const SkPaint& skPaint,
const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
@ -195,7 +198,7 @@ void GrBitmapTextContext::onDrawPosText(const GrPaint& paint, const SkPaint& skP
return;
}
this->init(paint, skPaint);
this->init(rt, paint, skPaint);
SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
@ -452,7 +455,7 @@ void GrBitmapTextContext::appendGlyph(GrGlyph::PackedID packed,
SkPath tmpPath(*glyph->fPath);
tmpPath.transform(translate);
GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle);
fContext->drawPath(fPaint, SkMatrix::I(), tmpPath, strokeInfo);
fContext->drawPath(fRenderTarget, fPaint, SkMatrix::I(), tmpPath, strokeInfo);
// remove this glyph from the vertices we need to allocate
fTotalVertexCount -= kVerticesPerGlyph;
@ -550,7 +553,7 @@ void GrBitmapTextContext::flush() {
if (fCurrVertex > 0) {
GrPipelineBuilder pipelineBuilder;
pipelineBuilder.setFromPaint(fPaint, fContext->getRenderTarget());
pipelineBuilder.setFromPaint(fPaint, fRenderTarget);
// setup our sampler state for our text texture/atlas
SkASSERT(SkIsAlign4(fCurrVertex));

View File

@ -40,15 +40,16 @@ private:
bool canDraw(const SkPaint& paint, const SkMatrix& viewMatrix) SK_OVERRIDE;
virtual void onDrawText(const GrPaint&, const SkPaint&, const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
virtual void onDrawText(GrRenderTarget*, const GrPaint&, const SkPaint&,
const SkMatrix& viewMatrix, const char text[], size_t byteLength,
SkScalar x, SkScalar y) SK_OVERRIDE;
virtual void onDrawPosText(const GrPaint&, const SkPaint&, const SkMatrix& viewMatrix,
virtual void onDrawPosText(GrRenderTarget*, const GrPaint&, const SkPaint&,
const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset) SK_OVERRIDE;
void init(const GrPaint&, const SkPaint&);
void init(GrRenderTarget*, const GrPaint&, const SkPaint&);
void appendGlyph(GrGlyph::PackedID, SkFixed left, SkFixed top, GrFontScaler*);
bool uploadGlyph(GrGlyph*, GrFontScaler*);
void flush(); // automatically called by destructor

View File

@ -383,20 +383,22 @@ void GrContext::clear(const SkIRect* rect,
AutoCheckFlush acf(this);
GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::clear", this);
GrDrawTarget* target = this->prepareToDraw(NULL, NULL, &acf);
GrDrawTarget* target = this->prepareToDraw(NULL, renderTarget, NULL, &acf);
if (NULL == target) {
return;
}
target->clear(rect, color, canIgnoreRect, renderTarget);
}
void GrContext::drawPaint(const GrPaint& origPaint, const SkMatrix& viewMatrix) {
void GrContext::drawPaint(GrRenderTarget* rt,
const GrPaint& origPaint,
const SkMatrix& viewMatrix) {
// set rect to be big enough to fill the space, but not super-huge, so we
// don't overflow fixed-point implementations
SkRect r;
r.setLTRB(0, 0,
SkIntToScalar(getRenderTarget()->width()),
SkIntToScalar(getRenderTarget()->height()));
SkIntToScalar(rt->width()),
SkIntToScalar(rt->height()));
SkTCopyOnFirstWrite<GrPaint> paint(origPaint);
// by definition this fills the entire clip, no need for AA
@ -416,7 +418,7 @@ void GrContext::drawPaint(const GrPaint& origPaint, const SkMatrix& viewMatrix)
return;
}
inverse.mapRect(&r);
this->drawRect(*paint, viewMatrix, r);
this->drawRect(rt, *paint, viewMatrix, r);
} else {
SkMatrix localMatrix;
if (!viewMatrix.invert(&localMatrix)) {
@ -426,7 +428,7 @@ void GrContext::drawPaint(const GrPaint& origPaint, const SkMatrix& viewMatrix)
AutoCheckFlush acf(this);
GrPipelineBuilder pipelineBuilder;
GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, paint, &acf);
GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, paint, &acf);
if (NULL == target) {
return;
}
@ -522,20 +524,21 @@ static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po
point.fY >= rect.fTop && point.fY <= rect.fBottom;
}
void GrContext::drawRect(const GrPaint& paint,
void GrContext::drawRect(GrRenderTarget* rt,
const GrPaint& paint,
const SkMatrix& viewMatrix,
const SkRect& rect,
const GrStrokeInfo* strokeInfo) {
if (strokeInfo && strokeInfo->isDashed()) {
SkPath path;
path.addRect(rect);
this->drawPath(paint, viewMatrix, path, *strokeInfo);
this->drawPath(rt, paint, viewMatrix, path, *strokeInfo);
return;
}
AutoCheckFlush acf(this);
GrPipelineBuilder pipelineBuilder;
GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, &paint, &acf);
GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &acf);
if (NULL == target) {
return;
}
@ -571,7 +574,7 @@ void GrContext::drawRect(const GrPaint& paint,
// Will it blend?
GrColor clearColor;
if (paint.isOpaqueAndConstantColor(&clearColor)) {
target->clear(NULL, clearColor, true, fRenderTarget);
target->clear(NULL, clearColor, true, rt);
return;
}
}
@ -654,14 +657,15 @@ void GrContext::drawRect(const GrPaint& paint,
}
}
void GrContext::drawNonAARectToRect(const GrPaint& paint,
void GrContext::drawNonAARectToRect(GrRenderTarget* rt,
const GrPaint& paint,
const SkMatrix& viewMatrix,
const SkRect& rectToDraw,
const SkRect& localRect,
const SkMatrix* localMatrix) {
AutoCheckFlush acf(this);
GrPipelineBuilder pipelineBuilder;
GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, &paint, &acf);
GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &acf);
if (NULL == target) {
return;
}
@ -696,7 +700,8 @@ static const GrGeometryProcessor* set_vertex_attributes(const SkPoint* texCoords
return GrDefaultGeoProcFactory::Create(flags, color, viewMatrix, SkMatrix::I());
}
void GrContext::drawVertices(const GrPaint& paint,
void GrContext::drawVertices(GrRenderTarget* rt,
const GrPaint& paint,
const SkMatrix& viewMatrix,
GrPrimitiveType primitiveType,
int vertexCount,
@ -709,7 +714,7 @@ void GrContext::drawVertices(const GrPaint& paint,
GrPipelineBuilder pipelineBuilder;
GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scope
GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, &paint, &acf);
GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &acf);
if (NULL == target) {
return;
}
@ -757,7 +762,8 @@ void GrContext::drawVertices(const GrPaint& paint,
///////////////////////////////////////////////////////////////////////////////
void GrContext::drawRRect(const GrPaint& paint,
void GrContext::drawRRect(GrRenderTarget*rt,
const GrPaint& paint,
const SkMatrix& viewMatrix,
const SkRRect& rrect,
const GrStrokeInfo& strokeInfo) {
@ -768,13 +774,13 @@ void GrContext::drawRRect(const GrPaint& paint,
if (strokeInfo.isDashed()) {
SkPath path;
path.addRRect(rrect);
this->drawPath(paint, viewMatrix, path, strokeInfo);
this->drawPath(rt, paint, viewMatrix, path, strokeInfo);
return;
}
AutoCheckFlush acf(this);
GrPipelineBuilder pipelineBuilder;
GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, &paint, &acf);
GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &acf);
if (NULL == target) {
return;
}
@ -795,7 +801,8 @@ void GrContext::drawRRect(const GrPaint& paint,
///////////////////////////////////////////////////////////////////////////////
void GrContext::drawDRRect(const GrPaint& paint,
void GrContext::drawDRRect(GrRenderTarget* rt,
const GrPaint& paint,
const SkMatrix& viewMatrix,
const SkRRect& outer,
const SkRRect& inner) {
@ -805,7 +812,7 @@ void GrContext::drawDRRect(const GrPaint& paint,
AutoCheckFlush acf(this);
GrPipelineBuilder pipelineBuilder;
GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, &paint, &acf);
GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &acf);
GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target);
@ -825,7 +832,8 @@ void GrContext::drawDRRect(const GrPaint& paint,
///////////////////////////////////////////////////////////////////////////////
void GrContext::drawOval(const GrPaint& paint,
void GrContext::drawOval(GrRenderTarget*rt,
const GrPaint& paint,
const SkMatrix& viewMatrix,
const SkRect& oval,
const GrStrokeInfo& strokeInfo) {
@ -836,13 +844,13 @@ void GrContext::drawOval(const GrPaint& paint,
if (strokeInfo.isDashed()) {
SkPath path;
path.addOval(oval);
this->drawPath(paint, viewMatrix, path, strokeInfo);
this->drawPath(rt, paint, viewMatrix, path, strokeInfo);
return;
}
AutoCheckFlush acf(this);
GrPipelineBuilder pipelineBuilder;
GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, &paint, &acf);
GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &acf);
if (NULL == target) {
return;
}
@ -919,14 +927,15 @@ static bool is_nested_rects(GrDrawTarget* target,
return allEq || allGoE1;
}
void GrContext::drawPath(const GrPaint& paint,
void GrContext::drawPath(GrRenderTarget* rt,
const GrPaint& paint,
const SkMatrix& viewMatrix,
const SkPath& path,
const GrStrokeInfo& strokeInfo) {
if (path.isEmpty()) {
if (path.isInverseFillType()) {
this->drawPaint(paint, viewMatrix);
this->drawPaint(rt, paint, viewMatrix);
}
return;
}
@ -937,7 +946,7 @@ void GrContext::drawPath(const GrPaint& paint,
if (path.isLine(pts)) {
AutoCheckFlush acf(this);
GrPipelineBuilder pipelineBuilder;
GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, &paint, &acf);
GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &acf);
if (NULL == target) {
return;
}
@ -954,11 +963,11 @@ void GrContext::drawPath(const GrPaint& paint,
GrStrokeInfo newStrokeInfo(strokeInfo, false);
SkStrokeRec* stroke = newStrokeInfo.getStrokeRecPtr();
if (SkDashPath::FilterDashPath(effectPath.init(), path, stroke, NULL, info)) {
this->drawPath(paint, viewMatrix, *effectPath.get(), newStrokeInfo);
this->drawPath(rt, paint, viewMatrix, *effectPath.get(), newStrokeInfo);
return;
}
this->drawPath(paint, viewMatrix, path, newStrokeInfo);
this->drawPath(rt, paint, viewMatrix, path, newStrokeInfo);
return;
}
@ -969,7 +978,7 @@ void GrContext::drawPath(const GrPaint& paint,
// OK.
AutoCheckFlush acf(this);
GrPipelineBuilder pipelineBuilder;
GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, &paint, &acf);
GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &acf);
if (NULL == target) {
return;
}
@ -1194,7 +1203,7 @@ bool GrContext::writeSurfacePixels(GrSurface* surface,
// drawing a rect to the render target.
// The bracket ensures we pop the stack if we wind up flushing below.
{
GrDrawTarget* drawTarget = this->prepareToDraw(NULL, NULL, NULL);
GrDrawTarget* drawTarget = this->prepareToDraw(NULL, NULL, NULL, NULL);
GrDrawTarget::AutoGeometryPush agp(drawTarget);
GrPipelineBuilder pipelineBuilder;
@ -1376,7 +1385,7 @@ void GrContext::discardRenderTarget(GrRenderTarget* renderTarget) {
SkASSERT(renderTarget);
ASSERT_OWNED_RESOURCE(renderTarget);
AutoCheckFlush acf(this);
GrDrawTarget* target = this->prepareToDraw(NULL, NULL, &acf);
GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL, NULL);
if (NULL == target) {
return;
}
@ -1394,7 +1403,7 @@ void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe
// Since we're going to the draw target and not GPU, no need to check kNoFlush
// here.
GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL);
GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL, NULL);
if (NULL == target) {
return;
}
@ -1412,16 +1421,17 @@ void GrContext::flushSurfaceWrites(GrSurface* surface) {
}
GrDrawTarget* GrContext::prepareToDraw(GrPipelineBuilder* pipelineBuilder,
GrRenderTarget* rt,
const GrPaint* paint,
const AutoCheckFlush* acf) {
if (NULL == fGpu) {
return NULL;
}
ASSERT_OWNED_RESOURCE(fRenderTarget.get());
if (pipelineBuilder) {
SkASSERT(paint && acf);
pipelineBuilder->setFromPaint(*paint, fRenderTarget.get());
ASSERT_OWNED_RESOURCE(rt);
SkASSERT(rt && paint && acf);
pipelineBuilder->setFromPaint(*paint, rt);
pipelineBuilder->setState(GrPipelineBuilder::kClip_StateBit,
fClip && !fClip->fClipStack->isWideOpen());
}
@ -1508,7 +1518,7 @@ void GrContext::setupDrawBuffer() {
}
GrDrawTarget* GrContext::getTextTarget() {
return this->prepareToDraw(NULL, NULL, NULL);
return this->prepareToDraw(NULL, NULL, NULL, NULL);
}
const GrIndexBuffer* GrContext::getQuadIndexBuffer() const {

View File

@ -112,8 +112,9 @@ bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint, const SkMatrix& v
return true;
}
inline void GrDistanceFieldTextContext::init(const GrPaint& paint, const SkPaint& skPaint) {
GrTextContext::init(paint, skPaint);
inline void GrDistanceFieldTextContext::init(GrRenderTarget* rt, const GrPaint& paint,
const SkPaint& skPaint) {
GrTextContext::init(rt, paint, skPaint);
fStrike = NULL;
@ -206,8 +207,8 @@ static void setup_gamma_texture(GrContext* context, const SkGlyphCache* cache,
}
}
void GrDistanceFieldTextContext::onDrawText(const GrPaint& paint, const SkPaint& skPaint,
const SkMatrix& viewMatrix,
void GrDistanceFieldTextContext::onDrawText(GrRenderTarget* rt, const GrPaint& paint,
const SkPaint& skPaint, const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
SkScalar x, SkScalar y) {
SkASSERT(byteLength == 0 || text != NULL);
@ -267,11 +268,12 @@ void GrDistanceFieldTextContext::onDrawText(const GrPaint& paint, const SkPaint&
y -= alignY;
SkPoint offset = SkPoint::Make(x, y);
this->drawPosText(paint, skPaint, viewMatrix, text, byteLength, positions.begin(), 2, offset);
this->drawPosText(rt, paint, skPaint, viewMatrix, text, byteLength, positions.begin(), 2,
offset);
}
void GrDistanceFieldTextContext::onDrawPosText(const GrPaint& paint, const SkPaint& skPaint,
const SkMatrix& viewMatrix,
void GrDistanceFieldTextContext::onDrawPosText(GrRenderTarget* rt, const GrPaint& paint,
const SkPaint& skPaint, const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset) {
@ -285,7 +287,7 @@ void GrDistanceFieldTextContext::onDrawPosText(const GrPaint& paint, const SkPai
}
fViewMatrix = viewMatrix;
this->init(paint, skPaint);
this->init(rt, paint, skPaint);
SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
@ -360,7 +362,7 @@ void GrDistanceFieldTextContext::onDrawPosText(const GrPaint& paint, const SkPai
this->finish();
if (fallbackTxt.count() > 0) {
fFallbackTextContext->drawPosText(paint, skPaint, viewMatrix, fallbackTxt.begin(),
fFallbackTextContext->drawPosText(rt, paint, skPaint, viewMatrix, fallbackTxt.begin(),
fallbackTxt.count(), fallbackPos.begin(),
scalarsPerPosition, offset);
}
@ -569,7 +571,7 @@ bool GrDistanceFieldTextContext::appendGlyph(GrGlyph::PackedID packed,
tmpPath.transform(ctm);
GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle);
fContext->drawPath(fPaint, fViewMatrix, tmpPath, strokeInfo);
fContext->drawPath(fRenderTarget, fPaint, fViewMatrix, tmpPath, strokeInfo);
// remove this glyph from the vertices we need to allocate
fTotalVertexCount -= kVerticesPerGlyph;
@ -666,7 +668,7 @@ void GrDistanceFieldTextContext::flush() {
if (fCurrVertex > 0) {
GrPipelineBuilder pipelineBuilder;
pipelineBuilder.setFromPaint(fPaint, fContext->getRenderTarget());
pipelineBuilder.setFromPaint(fPaint, fRenderTarget);
// setup our sampler state for our text texture/atlas
SkASSERT(SkIsAlign4(fCurrVertex));

View File

@ -52,15 +52,17 @@ private:
bool canDraw(const SkPaint& paint, const SkMatrix& viewMatrix) SK_OVERRIDE;
virtual void onDrawText(const GrPaint&, const SkPaint&, const SkMatrix& viewMatrix,
virtual void onDrawText(GrRenderTarget*, const GrPaint&, const SkPaint&,
const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
SkScalar x, SkScalar y) SK_OVERRIDE;
virtual void onDrawPosText(const GrPaint&, const SkPaint&, const SkMatrix& viewMatrix,
virtual void onDrawPosText(GrRenderTarget*, const GrPaint&, const SkPaint&,
const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset) SK_OVERRIDE;
void init(const GrPaint&, const SkPaint&);
void init(GrRenderTarget*, const GrPaint&, const SkPaint&);
bool appendGlyph(GrGlyph::PackedID, SkScalar left, SkScalar top, GrFontScaler*);
bool uploadGlyph(GrGlyph*, GrFontScaler*);
void setupCoverageEffect(const SkColor& filteredColor);

View File

@ -64,7 +64,8 @@ bool GrStencilAndCoverTextContext::canDraw(const SkPaint& paint, const SkMatrix&
return rec.getFormat() != SkMask::kARGB32_Format;
}
void GrStencilAndCoverTextContext::onDrawText(const GrPaint& paint,
void GrStencilAndCoverTextContext::onDrawText(GrRenderTarget* rt,
const GrPaint& paint,
const SkPaint& skPaint,
const SkMatrix& viewMatrix,
const char text[],
@ -91,7 +92,7 @@ void GrStencilAndCoverTextContext::onDrawText(const GrPaint& paint,
// will turn off the use of device-space glyphs when perspective transforms
// are in use.
this->init(paint, skPaint, byteLength, kMaxAccuracy_RenderMode, viewMatrix);
this->init(rt, paint, skPaint, byteLength, kMaxAccuracy_RenderMode, viewMatrix);
// Transform our starting point.
if (fUsingDeviceSpaceGlyphs) {
@ -153,7 +154,8 @@ void GrStencilAndCoverTextContext::onDrawText(const GrPaint& paint,
this->finish();
}
void GrStencilAndCoverTextContext::onDrawPosText(const GrPaint& paint,
void GrStencilAndCoverTextContext::onDrawPosText(GrRenderTarget* rt,
const GrPaint& paint,
const SkPaint& skPaint,
const SkMatrix& viewMatrix,
const char text[],
@ -177,7 +179,7 @@ void GrStencilAndCoverTextContext::onDrawPosText(const GrPaint& paint,
// transform is not part of SkPaint::measureText API, and thus we use the
// same glyphs as what were measured.
this->init(paint, skPaint, byteLength, kMaxPerformance_RenderMode, viewMatrix);
this->init(rt, paint, skPaint, byteLength, kMaxPerformance_RenderMode, viewMatrix);
SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
@ -229,12 +231,13 @@ static GrPathRange* get_gr_glyphs(GrContext* ctx,
return glyphs.detach();
}
void GrStencilAndCoverTextContext::init(const GrPaint& paint,
void GrStencilAndCoverTextContext::init(GrRenderTarget* rt,
const GrPaint& paint,
const SkPaint& skPaint,
size_t textByteLength,
RenderMode renderMode,
const SkMatrix& viewMatrix) {
GrTextContext::init(paint, skPaint);
GrTextContext::init(rt, paint, skPaint);
fContextInitialMatrix = viewMatrix;
fViewMatrix = viewMatrix;
@ -351,7 +354,7 @@ void GrStencilAndCoverTextContext::init(const GrPaint& paint,
fStateRestore.set(&fPipelineBuilder);
fPipelineBuilder.setFromPaint(fPaint, fContext->getRenderTarget());
fPipelineBuilder.setFromPaint(fPaint, fRenderTarget);
GR_STATIC_CONST_SAME_STENCIL(kStencilPass,
kZero_StencilOp,
@ -439,8 +442,8 @@ void GrStencilAndCoverTextContext::flush() {
inverse.mapPoints(&fGlyphPositions[fFallbackGlyphsIdx], fallbackGlyphCount);
}
fFallbackTextContext->drawPosText(paintFallback, skPaintFallback, fViewMatrix,
(char*)&fGlyphIndices[fFallbackGlyphsIdx],
fFallbackTextContext->drawPosText(fRenderTarget, paintFallback, skPaintFallback,
fViewMatrix, (char*)&fGlyphIndices[fFallbackGlyphsIdx],
2 * fallbackGlyphCount,
get_xy_scalar_array(&fGlyphPositions[fFallbackGlyphsIdx]),
2, SkPoint::Make(0, 0));

View File

@ -71,15 +71,17 @@ private:
bool canDraw(const SkPaint& paint, const SkMatrix& viewMatrix) SK_OVERRIDE;
virtual void onDrawText(const GrPaint&, const SkPaint&, const SkMatrix& viewMatrix,
virtual void onDrawText(GrRenderTarget*, const GrPaint&, const SkPaint&,
const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
SkScalar x, SkScalar y) SK_OVERRIDE;
virtual void onDrawPosText(const GrPaint&, const SkPaint&, const SkMatrix& viewMatrix,
virtual void onDrawPosText(GrRenderTarget*, const GrPaint&, const SkPaint&,
const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset) SK_OVERRIDE;
void init(const GrPaint&, const SkPaint&, size_t textByteLength, RenderMode,
void init(GrRenderTarget*, const GrPaint&, const SkPaint&, size_t textByteLength, RenderMode,
const SkMatrix& viewMatrix);
bool mapToFallbackContext(SkMatrix* inverse);
void appendGlyph(const SkGlyph&, const SkPoint&);

View File

@ -21,12 +21,12 @@ GrTextContext::~GrTextContext() {
SkDELETE(fFallbackTextContext);
}
void GrTextContext::init(const GrPaint& grPaint, const SkPaint& skPaint) {
void GrTextContext::init(GrRenderTarget* rt, const GrPaint& grPaint, const SkPaint& skPaint) {
const GrClipData* clipData = fContext->getClip();
clipData->getConservativeBounds(fContext->getRenderTarget()->width(),
fContext->getRenderTarget()->height(),
&fClipRect);
fRenderTarget.reset(SkRef(rt));
clipData->getConservativeBounds(fRenderTarget->width(), fRenderTarget->height(), &fClipRect);
fDrawTarget = fContext->getTextTarget();
@ -34,7 +34,7 @@ void GrTextContext::init(const GrPaint& grPaint, const SkPaint& skPaint) {
fSkPaint = skPaint;
}
bool GrTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint,
bool GrTextContext::drawText(GrRenderTarget* rt, const GrPaint& paint, const SkPaint& skPaint,
const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
SkScalar x, SkScalar y) {
@ -42,7 +42,7 @@ bool GrTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint,
GrTextContext* textContext = this;
do {
if (textContext->canDraw(skPaint, viewMatrix)) {
textContext->onDrawText(paint, skPaint, viewMatrix, text, byteLength, x, y);
textContext->onDrawText(rt, paint, skPaint, viewMatrix, text, byteLength, x, y);
return true;
}
textContext = textContext->fFallbackTextContext;
@ -51,7 +51,7 @@ bool GrTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint,
return false;
}
bool GrTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPaint,
bool GrTextContext::drawPosText(GrRenderTarget* rt, const GrPaint& paint, const SkPaint& skPaint,
const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
@ -60,7 +60,7 @@ bool GrTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPaint,
GrTextContext* textContext = this;
do {
if (textContext->canDraw(skPaint, viewMatrix)) {
textContext->onDrawPosText(paint, skPaint, viewMatrix, text, byteLength, pos,
textContext->onDrawPosText(rt, paint, skPaint, viewMatrix, text, byteLength, pos,
scalarsPerPosition, offset);
return true;
}

View File

@ -25,35 +25,38 @@ class GrTextContext {
public:
virtual ~GrTextContext();
bool drawText(const GrPaint&, const SkPaint&, const SkMatrix& viewMatrix, const char text[],
size_t byteLength, SkScalar x, SkScalar y);
bool drawPosText(const GrPaint&, const SkPaint&, const SkMatrix& viewMatrix,
bool drawText(GrRenderTarget* rt, const GrPaint&, const SkPaint&, const SkMatrix& viewMatrix,
const char text[], size_t byteLength, SkScalar x, SkScalar y);
bool drawPosText(GrRenderTarget* rt, const GrPaint&, const SkPaint&, const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset);
protected:
GrTextContext* fFallbackTextContext;
GrContext* fContext;
SkDeviceProperties fDeviceProperties;
GrTextContext* fFallbackTextContext;
GrContext* fContext;
SkDeviceProperties fDeviceProperties;
GrDrawTarget* fDrawTarget;
SkIRect fClipRect;
GrPaint fPaint;
SkPaint fSkPaint;
SkAutoTUnref<GrRenderTarget> fRenderTarget;
GrDrawTarget* fDrawTarget;
SkIRect fClipRect;
GrPaint fPaint;
SkPaint fSkPaint;
GrTextContext(GrContext*, const SkDeviceProperties&);
virtual bool canDraw(const SkPaint& paint, const SkMatrix& viewMatrix) = 0;
virtual void onDrawText(const GrPaint&, const SkPaint&, const SkMatrix& viewMatrix,
const char text[], size_t byteLength, SkScalar x, SkScalar y) = 0;
virtual void onDrawPosText(const GrPaint&, const SkPaint&, const SkMatrix& viewMatrix,
virtual void onDrawText(GrRenderTarget*, const GrPaint&, const SkPaint&,
const SkMatrix& viewMatrix, const char text[], size_t byteLength,
SkScalar x, SkScalar y) = 0;
virtual void onDrawPosText(GrRenderTarget*, const GrPaint&, const SkPaint&,
const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset) = 0;
void init(const GrPaint&, const SkPaint&);
void init(GrRenderTarget*, const GrPaint&, const SkPaint&);
void finish() { fDrawTarget = NULL; }
static GrFontScaler* GetGrFontScaler(SkGlyphCache* cache);

View File

@ -211,12 +211,6 @@ SkGpuDevice::~SkGpuDevice() {
delete fTextContext;
// The GrContext takes a ref on the target. We don't want to cause the render
// target to be unnecessarily kept alive.
if (fContext->getRenderTarget() == fRenderTarget) {
fContext->setRenderTarget(NULL);
}
if (fContext->getClip() == &fClipData) {
fContext->setClip(NULL);
}
@ -286,8 +280,6 @@ void SkGpuDevice::onDetachFromCanvas() {
void SkGpuDevice::prepareDraw(const SkDraw& draw) {
SkASSERT(fClipData.fClipStack);
fContext->setRenderTarget(fRenderTarget);
SkASSERT(draw.fClipStack && draw.fClipStack == fClipData.fClipStack);
fClipData.fOrigin = this->getOrigin();
@ -330,9 +322,9 @@ void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPaint", fContext);
GrPaint grPaint;
SkPaint2GrPaintShader(this->context(), paint, *draw.fMatrix, true, &grPaint);
SkPaint2GrPaintShader(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint);
fContext->drawPaint(grPaint, *draw.fMatrix);
fContext->drawPaint(fRenderTarget, grPaint, *draw.fMatrix);
}
// must be in SkCanvas::PointMode order
@ -355,12 +347,12 @@ void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mode) {
GrStrokeInfo strokeInfo(paint, SkPaint::kStroke_Style);
GrPaint grPaint;
SkPaint2GrPaintShader(this->context(), paint, *draw.fMatrix, true, &grPaint);
SkPaint2GrPaintShader(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint);
SkPath path;
path.setIsVolatile(true);
path.moveTo(pts[0]);
path.lineTo(pts[1]);
fContext->drawPath(grPaint, *draw.fMatrix, path, strokeInfo);
fContext->drawPath(fRenderTarget, grPaint, *draw.fMatrix, path, strokeInfo);
return;
}
@ -372,9 +364,10 @@ void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
}
GrPaint grPaint;
SkPaint2GrPaintShader(this->context(), paint, *draw.fMatrix, true, &grPaint);
SkPaint2GrPaintShader(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint);
fContext->drawVertices(grPaint,
fContext->drawVertices(fRenderTarget,
grPaint,
*draw.fMatrix,
gPointMode2PrimtiveType[mode],
SkToS32(count),
@ -442,9 +435,9 @@ void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect,
}
GrPaint grPaint;
SkPaint2GrPaintShader(this->context(), paint, *draw.fMatrix, true, &grPaint);
SkPaint2GrPaintShader(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint);
fContext->drawRect(grPaint, *draw.fMatrix, rect, &strokeInfo);
fContext->drawRect(fRenderTarget, grPaint, *draw.fMatrix, rect, &strokeInfo);
}
///////////////////////////////////////////////////////////////////////////////
@ -456,7 +449,7 @@ void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect,
CHECK_SHOULD_DRAW(draw);
GrPaint grPaint;
SkPaint2GrPaintShader(this->context(), paint, *draw.fMatrix, true, &grPaint);
SkPaint2GrPaintShader(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint);
GrStrokeInfo strokeInfo(paint);
if (paint.getMaskFilter()) {
@ -476,7 +469,9 @@ void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect,
// clipped out
return;
}
if (paint.getMaskFilter()->directFilterRRectMaskGPU(fContext, &grPaint,
if (paint.getMaskFilter()->directFilterRRectMaskGPU(fContext,
fRenderTarget,
&grPaint,
*draw.fMatrix,
strokeInfo.getStrokeRec(),
devRRect)) {
@ -509,7 +504,7 @@ void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect,
return;
}
fContext->drawRRect(grPaint, *draw.fMatrix, rect, strokeInfo);
fContext->drawRRect(fRenderTarget, grPaint, *draw.fMatrix, rect, strokeInfo);
}
void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer,
@ -521,10 +516,10 @@ void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer,
CHECK_SHOULD_DRAW(draw);
GrPaint grPaint;
SkPaint2GrPaintShader(this->context(), paint, *draw.fMatrix, true, &grPaint);
SkPaint2GrPaintShader(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint);
if (NULL == paint.getMaskFilter() && NULL == paint.getPathEffect()) {
fContext->drawDRRect(grPaint, *draw.fMatrix, outer, inner);
fContext->drawDRRect(fRenderTarget, grPaint, *draw.fMatrix, outer, inner);
return;
}
}
@ -569,9 +564,9 @@ void SkGpuDevice::drawOval(const SkDraw& draw, const SkRect& oval,
}
GrPaint grPaint;
SkPaint2GrPaintShader(this->context(), paint, *draw.fMatrix, true, &grPaint);
SkPaint2GrPaintShader(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint);
fContext->drawOval(grPaint, *draw.fMatrix, oval, strokeInfo);
fContext->drawOval(fRenderTarget, grPaint, *draw.fMatrix, oval, strokeInfo);
}
#include "SkMaskFilter.h"
@ -584,8 +579,12 @@ namespace {
// Draw a mask using the supplied paint. Since the coverage/geometry
// is already burnt into the mask this boils down to a rect draw.
// Return true if the mask was successfully drawn.
bool draw_mask(GrContext* context, const SkMatrix& viewMatrix, const SkRect& maskRect,
GrPaint* grp, GrTexture* mask) {
bool draw_mask(GrContext* context,
GrRenderTarget* rt,
const SkMatrix& viewMatrix,
const SkRect& maskRect,
GrPaint* grp,
GrTexture* mask) {
SkMatrix matrix;
matrix.setTranslate(-maskRect.fLeft, -maskRect.fTop);
matrix.postIDiv(mask->width(), mask->height());
@ -597,13 +596,18 @@ bool draw_mask(GrContext* context, const SkMatrix& viewMatrix, const SkRect& mas
if (!viewMatrix.invert(&inverse)) {
return false;
}
context->drawNonAARectWithLocalMatrix(*grp, SkMatrix::I(), maskRect, inverse);
context->drawNonAARectWithLocalMatrix(rt, *grp, SkMatrix::I(), maskRect, inverse);
return true;
}
bool draw_with_mask_filter(GrContext* context, const SkMatrix& viewMatrix, const SkPath& devPath,
SkMaskFilter* filter, const SkRegion& clip,
GrPaint* grp, SkPaint::Style style) {
bool draw_with_mask_filter(GrContext* context,
GrRenderTarget* rt,
const SkMatrix& viewMatrix,
const SkPath& devPath,
SkMaskFilter* filter,
const SkRegion& clip,
GrPaint* grp,
SkPaint::Style style) {
SkMask srcM, dstM;
if (!SkDraw::DrawToMask(devPath, &clip.getBounds(), filter, &viewMatrix, &srcM,
@ -639,11 +643,12 @@ bool draw_with_mask_filter(GrContext* context, const SkMatrix& viewMatrix, const
SkRect maskRect = SkRect::Make(dstM.fBounds);
return draw_mask(context, viewMatrix, maskRect, grp, texture);
return draw_mask(context, rt, viewMatrix, maskRect, grp, texture);
}
// Create a mask of 'devPath' and place the result in 'mask'.
GrTexture* create_mask_GPU(GrContext* context,
GrRenderTarget* rt,
const SkRect& maskRect,
const SkPath& devPath,
const GrStrokeInfo& strokeInfo,
@ -670,7 +675,6 @@ GrTexture* create_mask_GPU(GrContext* context,
SkRect clipRect = SkRect::MakeWH(maskRect.width(), maskRect.height());
GrContext::AutoRenderTarget art(context, mask->asRenderTarget());
GrContext::AutoClip ac(context, clipRect);
context->clear(NULL, 0x0, true, mask->asRenderTarget());
@ -682,7 +686,7 @@ GrTexture* create_mask_GPU(GrContext* context,
// Draw the mask into maskTexture with the path's top-left at the origin using tempPaint.
SkMatrix translate;
translate.setTranslate(-maskRect.fLeft, -maskRect.fTop);
context->drawPath(tempPaint, translate, devPath, strokeInfo);
context->drawPath(mask->asRenderTarget(), tempPaint, translate, devPath, strokeInfo);
return mask;
}
@ -741,7 +745,7 @@ void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath,
SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;)
GrPaint grPaint;
SkPaint2GrPaintShader(this->context(), paint, viewMatrix, true, &grPaint);
SkPaint2GrPaintShader(this->context(), fRenderTarget, paint, viewMatrix, true, &grPaint);
const SkRect* cullRect = NULL; // TODO: what is our bounds?
SkStrokeRec* strokePtr = strokeInfo.getStrokeRecPtr();
@ -784,16 +788,24 @@ void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath,
return;
}
if (paint.getMaskFilter()->directFilterMaskGPU(fContext, &grPaint, viewMatrix,
stroke, *devPathPtr)) {
if (paint.getMaskFilter()->directFilterMaskGPU(fContext,
fRenderTarget,
&grPaint,
viewMatrix,
stroke,
*devPathPtr)) {
// the mask filter was able to draw itself directly, so there's nothing
// left to do.
return;
}
SkAutoTUnref<GrTexture> mask(create_mask_GPU(fContext, maskRect, *devPathPtr,
strokeInfo, grPaint.isAntiAlias(),
SkAutoTUnref<GrTexture> mask(create_mask_GPU(fContext,
fRenderTarget,
maskRect,
*devPathPtr,
strokeInfo,
grPaint.isAntiAlias(),
fRenderTarget->numSamples()));
if (mask) {
GrTexture* filtered;
@ -801,7 +813,8 @@ void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath,
if (paint.getMaskFilter()->filterMaskGPU(mask, viewMatrix, maskRect, &filtered, true)) {
// filterMaskGPU gives us ownership of a ref to the result
SkAutoTUnref<GrTexture> atu(filtered);
if (draw_mask(fContext, viewMatrix, maskRect, &grPaint, filtered)) {
if (draw_mask(fContext, fRenderTarget, viewMatrix, maskRect, &grPaint,
filtered)) {
// This path is completely drawn
return;
}
@ -813,12 +826,12 @@ void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath,
// GPU path fails
SkPaint::Style style = stroke.isHairlineStyle() ? SkPaint::kStroke_Style :
SkPaint::kFill_Style;
draw_with_mask_filter(fContext, viewMatrix, *devPathPtr, paint.getMaskFilter(),
*draw.fClip, &grPaint, style);
draw_with_mask_filter(fContext, fRenderTarget, viewMatrix, *devPathPtr,
paint.getMaskFilter(), *draw.fClip, &grPaint, style);
return;
}
fContext->drawPath(grPaint, viewMatrix, *pathPtr, strokeInfo);
fContext->drawPath(fRenderTarget, grPaint, viewMatrix, *pathPtr, strokeInfo);
}
static const int kBmpSmallTileSize = 1 << 10;
@ -850,12 +863,13 @@ static int determine_tile_size(const SkBitmap& bitmap, const SkIRect& src, int m
// Given a bitmap, an optional src rect, and a context with a clip and matrix determine what
// pixels from the bitmap are necessary.
static void determine_clipped_src_rect(const GrContext* context,
const GrRenderTarget* rt,
const SkMatrix& viewMatrix,
const SkBitmap& bitmap,
const SkRect* srcRectPtr,
SkIRect* clippedSrcIRect) {
const GrClipData* clip = context->getClip();
clip->getConservativeBounds(context->getRenderTarget(), clippedSrcIRect, NULL);
clip->getConservativeBounds(rt, clippedSrcIRect, NULL);
SkMatrix inv;
if (!viewMatrix.invert(&inv)) {
clippedSrcIRect->setEmpty();
@ -892,7 +906,8 @@ bool SkGpuDevice::shouldTileBitmap(const SkBitmap& bitmap,
// if it's larger than the max tile size, then we have no choice but tiling.
if (bitmap.width() > maxTileSize || bitmap.height() > maxTileSize) {
determine_clipped_src_rect(fContext, viewMatrix, bitmap, srcRectPtr, clippedSrcRect);
determine_clipped_src_rect(fContext, fRenderTarget, viewMatrix, bitmap, srcRectPtr,
clippedSrcRect);
*tileSize = determine_tile_size(bitmap, *clippedSrcRect, maxTileSize);
return true;
}
@ -921,7 +936,8 @@ bool SkGpuDevice::shouldTileBitmap(const SkBitmap& bitmap,
}
// Figure out how much of the src we will need based on the src rect and clipping.
determine_clipped_src_rect(fContext, viewMatrix, bitmap, srcRectPtr, clippedSrcRect);
determine_clipped_src_rect(fContext, fRenderTarget, viewMatrix, bitmap, srcRectPtr,
clippedSrcRect);
*tileSize = kBmpSmallTileSize; // already know whole bitmap fits in one max sized tile.
size_t usedTileBytes = get_tile_count(*clippedSrcRect, kBmpSmallTileSize) *
kBmpSmallTileSize * kBmpSmallTileSize;
@ -1392,9 +1408,9 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap,
bool alphaOnly = !(kAlpha_8_SkColorType == bitmap.colorType());
GrColor paintColor = (alphaOnly) ? SkColor2GrColorJustAlpha(paint.getColor()) :
SkColor2GrColor(paint.getColor());
SkPaint2GrPaintNoShader(this->context(), paint, paintColor, false, &grPaint);
SkPaint2GrPaintNoShader(this->context(), fRenderTarget, paint, paintColor, false, &grPaint);
fContext->drawNonAARectToRect(grPaint, viewMatrix, dstRect, paintRect);
fContext->drawNonAARectToRect(fRenderTarget, grPaint, viewMatrix, dstRect, paintRect);
}
bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture,
@ -1408,9 +1424,8 @@ bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture,
SkDeviceImageFilterProxy proxy(this, SkSurfaceProps(0, getLeakyProperties().pixelGeometry()));
if (filter->canFilterImageGPU()) {
// Save the render target and set it to NULL, so we don't accidentally draw to it in the
// filter. Also set the clip wide open and the matrix to identity.
GrContext::AutoWideOpenIdentityDraw awo(context, NULL);
// Set the clip wide open and the matrix to identity.
GrContext::AutoWideOpenIdentityDraw awo(context);
return filter->filterImageGPU(&proxy, wrap_texture(texture), ctx, result, offset);
} else {
return false;
@ -1462,10 +1477,11 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
GrPaint grPaint;
grPaint.addColorTextureProcessor(texture, SkMatrix::I());
SkPaint2GrPaintNoShader(this->context(), paint, SkColor2GrColorJustAlpha(paint.getColor()),
false, &grPaint);
SkPaint2GrPaintNoShader(this->context(), fRenderTarget, paint,
SkColor2GrColorJustAlpha(paint.getColor()), false, &grPaint);
fContext->drawNonAARectToRect(grPaint,
fContext->drawNonAARectToRect(fRenderTarget,
grPaint,
SkMatrix::I(),
SkRect::MakeXYWH(SkIntToScalar(left),
SkIntToScalar(top),
@ -1574,8 +1590,8 @@ void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device,
GrPaint grPaint;
grPaint.addColorTextureProcessor(devTex, SkMatrix::I());
SkPaint2GrPaintNoShader(this->context(), paint, SkColor2GrColorJustAlpha(paint.getColor()),
false, &grPaint);
SkPaint2GrPaintNoShader(this->context(), fRenderTarget, paint,
SkColor2GrColorJustAlpha(paint.getColor()), false, &grPaint);
SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(x),
SkIntToScalar(y),
@ -1587,7 +1603,7 @@ void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device,
SkRect srcRect = SkRect::MakeWH(SK_Scalar1 * w / devTex->width(),
SK_Scalar1 * h / devTex->height());
fContext->drawNonAARectToRect(grPaint, SkMatrix::I(), dstRect, srcRect);
fContext->drawNonAARectToRect(fRenderTarget, grPaint, SkMatrix::I(), dstRect, srcRect);
}
bool SkGpuDevice::canHandleImageFilter(const SkImageFilter* filter) {
@ -1648,8 +1664,8 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
copy.setStrokeWidth(0);
// we ignore the shader if texs is null.
SkPaint2GrPaintNoShader(this->context(), copy, SkColor2GrColor(copy.getColor()),
NULL == colors, &grPaint);
SkPaint2GrPaintNoShader(this->context(), fRenderTarget, copy,
SkColor2GrColor(copy.getColor()), NULL == colors, &grPaint);
primType = kLines_GrPrimitiveType;
int triangleCount = 0;
@ -1688,10 +1704,12 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
primType = gVertexMode2PrimitiveType[vmode];
if (NULL == texs || NULL == paint.getShader()) {
SkPaint2GrPaintNoShader(this->context(), paint, SkColor2GrColor(paint.getColor()),
SkPaint2GrPaintNoShader(this->context(), fRenderTarget, paint,
SkColor2GrColor(paint.getColor()),
NULL == colors, &grPaint);
} else {
SkPaint2GrPaintShader(this->context(), paint, *draw.fMatrix, NULL == colors, &grPaint);
SkPaint2GrPaintShader(this->context(), fRenderTarget, paint, *draw.fMatrix,
NULL == colors, &grPaint);
}
}
@ -1718,7 +1736,8 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
}
colors = convertedColors.get();
}
fContext->drawVertices(grPaint,
fContext->drawVertices(fRenderTarget,
grPaint,
*draw.fMatrix,
primType,
vertexCount,
@ -1738,12 +1757,12 @@ void SkGpuDevice::drawText(const SkDraw& draw, const void* text,
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext);
GrPaint grPaint;
SkPaint2GrPaintShader(this->context(), paint, *draw.fMatrix, true, &grPaint);
SkPaint2GrPaintShader(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint);
SkDEBUGCODE(this->validate();)
if (!fTextContext->drawText(grPaint, paint, *draw.fMatrix, (const char *)text, byteLength, x,
y)) {
if (!fTextContext->drawText(fRenderTarget, grPaint, paint, *draw.fMatrix, (const char *)text,
byteLength, x, y)) {
// this will just call our drawPath()
draw.drawText_asPaths((const char*)text, byteLength, x, y, paint);
}
@ -1756,12 +1775,12 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteL
CHECK_SHOULD_DRAW(draw);
GrPaint grPaint;
SkPaint2GrPaintShader(this->context(), paint, *draw.fMatrix, true, &grPaint);
SkPaint2GrPaintShader(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint);
SkDEBUGCODE(this->validate();)
if (!fTextContext->drawPosText(grPaint, paint, *draw.fMatrix, (const char *)text, byteLength,
pos, scalarsPerPos, offset)) {
if (!fTextContext->drawPosText(fRenderTarget, grPaint, paint, *draw.fMatrix, (const char *)text,
byteLength, pos, scalarsPerPos, offset)) {
// this will just call our drawPath()
draw.drawPosText_asPaths((const char*)text, byteLength, pos, scalarsPerPos, offset, paint);
}

View File

@ -245,9 +245,9 @@ GrTexture* stretch_texture_to_next_pot(GrTexture* inputTexture, Stretch stretch,
SkRect rect = SkRect::MakeWH(SkIntToScalar(rtDesc.fWidth), SkIntToScalar(rtDesc.fHeight));
SkRect localRect = SkRect::MakeWH(1.f, 1.f);
GrContext::AutoRenderTarget autoRT(context, stretched->asRenderTarget());
GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialClip);
context->drawNonAARectToRect(paint, SkMatrix::I(), rect, localRect);
context->drawNonAARectToRect(stretched->asRenderTarget(), paint, SkMatrix::I(), rect,
localRect);
return stretched;
}
@ -396,9 +396,8 @@ static GrTexture* load_yuv_texture(GrContext* ctx, const GrContentKey& optionalK
paint.addColorProcessor(yuvToRgbProcessor);
SkRect r = SkRect::MakeWH(SkIntToScalar(yuvInfo.fSize[0].fWidth),
SkIntToScalar(yuvInfo.fSize[0].fHeight));
GrContext::AutoRenderTarget autoRT(ctx, renderTarget);
GrContext::AutoClip ac(ctx, GrContext::AutoClip::kWideOpen_InitialClip);
ctx->drawRect(paint, SkMatrix::I(), r);
ctx->drawRect(renderTarget, paint, SkMatrix::I(), r);
return result;
}
@ -640,8 +639,8 @@ bool GrPixelConfig2ColorAndProfileType(GrPixelConfig config, SkColorType* ctOut,
///////////////////////////////////////////////////////////////////////////////
void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor paintColor,
bool constantColor, GrPaint* grPaint) {
void SkPaint2GrPaintNoShader(GrContext* context, GrRenderTarget* rt, const SkPaint& skPaint,
GrColor paintColor, bool constantColor, GrPaint* grPaint) {
grPaint->setDither(skPaint.isDither());
grPaint->setAntiAlias(skPaint.isAntiAlias());
@ -678,13 +677,12 @@ void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor
// supports it. If not, then install a dither effect.
if (skPaint.isDither() && grPaint->numColorStages() > 0) {
// What are we rendering into?
const GrRenderTarget *target = context->getRenderTarget();
SkASSERT(target);
SkASSERT(rt);
// Suspect the dithering flag has no effect on these configs, otherwise
// fall back on setting the appropriate state.
if (target->config() == kRGBA_8888_GrPixelConfig ||
target->config() == kBGRA_8888_GrPixelConfig) {
if (GrPixelConfigIs8888(rt->config()) ||
GrPixelConfigIs8888(rt->config())) {
// The dither flag is set and the target is likely
// not going to be dithered by the GPU.
SkAutoTUnref<GrFragmentProcessor> fp(GrDitherEffect::Create());
@ -697,11 +695,11 @@ void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor
#endif
}
void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint, const SkMatrix& viewM,
bool constantColor, GrPaint* grPaint) {
void SkPaint2GrPaintShader(GrContext* context, GrRenderTarget* rt, const SkPaint& skPaint,
const SkMatrix& viewM, bool constantColor, GrPaint* grPaint) {
SkShader* shader = skPaint.getShader();
if (NULL == shader) {
SkPaint2GrPaintNoShader(context, skPaint, SkColor2GrColor(skPaint.getColor()),
SkPaint2GrPaintNoShader(context, rt, skPaint, SkColor2GrColor(skPaint.getColor()),
constantColor, grPaint);
return;
}
@ -712,9 +710,6 @@ void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint, const SkM
// asFragmentProcessor(). Since these calls get passed back to the client, we don't really
// want them messing around with the context.
{
// SkShader::asFragmentProcessor() may do offscreen rendering. Save off the current RT,
// and clip
GrContext::AutoRenderTarget art(context, NULL);
GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialClip);
// Allow the shader to modify paintColor and also create an effect to be installed as
@ -728,5 +723,5 @@ void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint, const SkM
// The grcolor is automatically set when calling asFragmentProcessor.
// If the shader can be seen as an effect it returns true and adds its effect to the grpaint.
SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint);
SkPaint2GrPaintNoShader(context, rt, skPaint, paintColor, constantColor, grPaint);
}

View File

@ -206,7 +206,7 @@ void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context
{kDivByAlpha_RoundUp_PMConversion, kMulByAlpha_RoundDown_PMConversion},
};
GrContext::AutoWideOpenIdentityDraw awoid(context, NULL);
GrContext::AutoWideOpenIdentityDraw awoid(context);
bool failed = true;
@ -230,22 +230,22 @@ void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context
SkNEW_ARGS(GrConfigConversionEffect,
(tempTex, false, *pmToUPMRule, SkMatrix::I())));
context->setRenderTarget(readTex->asRenderTarget());
GrPaint paint1;
paint1.addColorProcessor(pmToUPM1);
context->drawNonAARectToRect(paint1, SkMatrix::I(), kDstRect, kSrcRect);
context->drawNonAARectToRect(readTex->asRenderTarget(), paint1, SkMatrix::I(), kDstRect,
kSrcRect);
readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, firstRead);
context->setRenderTarget(tempTex->asRenderTarget());
GrPaint paint2;
paint2.addColorProcessor(upmToPM);
context->drawNonAARectToRect(paint2, SkMatrix::I(), kDstRect, kSrcRect);
context->setRenderTarget(readTex->asRenderTarget());
context->drawNonAARectToRect(tempTex->asRenderTarget(), paint2, SkMatrix::I(), kDstRect,
kSrcRect);
GrPaint paint3;
paint3.addColorProcessor(pmToUPM2);
context->drawNonAARectToRect(paint3, SkMatrix::I(), kDstRect, kSrcRect);
context->drawNonAARectToRect(readTex->asRenderTarget(), paint3, SkMatrix::I(), kDstRect,
kSrcRect);
readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, secondRead);