}
SkAutoTUnref<GrTexture> au(texture);
- // setup new clip
- GrClip clip(SkRect::MakeWH(2*S, 2*S));
+ GrContext::AutoClip acs(ctx, SkRect::MakeWH(2*S, 2*S));
GrPaint paint;
paint.setPorterDuffXPFactory(SkXfermode::kSrcOver_Mode);
tm.postIDiv(2*S, 2*S);
paint.addColorTextureProcessor(texture, tm);
- ctx->drawRect(target, clip, 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
texture->writePixels(S, (i ? 0 : S), S, S,
texture->config(), gTextureData.get(),
4 * stride);
- ctx->drawRect(target, clip, paint, vm, SkRect::MakeWH(2*S, 2*S));
+ ctx->drawRect(target, paint, vm, SkRect::MakeWH(2*S, 2*S));
}
} else {
this->drawGpuOnlyMessage(canvas);
#include "SkMask.h"
#include "SkPaint.h"
-class GrClip;
class GrContext;
class GrPaint;
class GrRenderTarget;
virtual bool directFilterMaskGPU(GrContext* context,
GrRenderTarget* rt,
GrPaint* grp,
- const GrClip&,
const SkMatrix& viewMatrix,
const SkStrokeRec& strokeRec,
const SkPath& path) const;
virtual bool directFilterRRectMaskGPU(GrContext* context,
GrRenderTarget* rt,
GrPaint* grp,
- const GrClip&,
const SkMatrix& viewMatrix,
const SkStrokeRec& strokeRec,
const SkRRect& rrect) const;
}
/**
- * Returns true if the specified rectangle r is inside or equal to this rectangle.
- */
- bool contains(const SkIRect& r) const {
- // todo: can we eliminate the this->isEmpty check?
- return !r.isEmpty() && !this->isEmpty() &&
- fLeft <= SkIntToScalar(r.fLeft) && fTop <= SkIntToScalar(r.fTop) &&
- fRight >= SkIntToScalar(r.fRight) && fBottom >= SkIntToScalar(r.fBottom);
- }
-
- /**
* Set the dst rectangle by rounding this rectangle's coordinates to their
* nearest integer values using SkScalarRoundToInt.
*/
/**
* GrClip encapsulates the information required to construct the clip
- * masks. 'A GrClip is either wide open, just an IRect, just a Rect, or a full clipstack.
+ * masks. 'A GrClip is either wide open, just an IRect, just a Rect(TODO), or a full clipstack.
* If the clip is a clipstack than the origin is used to translate the stack with
* respect to device coordinates. This allows us to use a clip stack that is
* specified for a root device with a layer device that is restricted to a subset
GrClip() : fClipType(kWideOpen_ClipType) {
fOrigin.setZero();
}
-
GrClip(const SkIRect& rect) : fClipType(kIRect_ClipType) {
fOrigin.setZero();
fClip.fIRect = rect;
}
-
- GrClip(const SkRect& rect) : fClipType(kRect_ClipType) {
- fOrigin.setZero();
- fClip.fRect = rect;
- }
-
~GrClip() { this->reset(); }
const GrClip& operator=(const GrClip& other) {
this->reset();
fClipType = other.fClipType;
switch (other.fClipType) {
+ default:
+ SkFAIL("Incomplete Switch\n");
case kWideOpen_ClipType:
fOrigin.setZero();
break;
fClip.fIRect = other.irect();
fOrigin.setZero();
break;
- case kRect_ClipType:
- fClip.fRect = other.rect();
- fOrigin.setZero();
- break;
}
return *this;
}
}
switch (fClipType) {
+ default:
+ SkFAIL("Incomplete Switch\n");
+ return false;
case kWideOpen_ClipType:
return true;
case kClipStack_ClipType:
case kIRect_ClipType:
return this->irect() == other.irect();
break;
- case kRect_ClipType:
- return this->rect() == other.rect();
- break;
}
}
return fClip.fIRect;
}
- const SkRect& rect() const {
- SkASSERT(kRect_ClipType == fClipType);
- return fClip.fRect;
- }
-
void reset() {
if (kClipStack_ClipType == fClipType) {
fClip.fStack->unref();
bool isWideOpen(const SkRect& rect) const {
return (kWideOpen_ClipType == fClipType) ||
(kClipStack_ClipType == fClipType && this->clipStack()->isWideOpen()) ||
- (kIRect_ClipType == fClipType && this->irect().contains(rect)) ||
- (kRect_ClipType == fClipType && this->rect().contains(rect));
+ (kIRect_ClipType == fClipType && this->irect().contains(rect));
}
bool isWideOpen(const SkIRect& rect) const {
return (kWideOpen_ClipType == fClipType) ||
(kClipStack_ClipType == fClipType && this->clipStack()->isWideOpen()) ||
- (kIRect_ClipType == fClipType && this->irect().contains(rect)) ||
- (kRect_ClipType == fClipType && this->rect().contains(rect));
+ (kIRect_ClipType == fClipType && this->irect().contains(rect));
}
bool isWideOpen() const {
(kClipStack_ClipType == fClipType && this->clipStack()->isWideOpen());
}
- bool quickContains(const SkRect& rect) const {
- return (kWideOpen_ClipType == fClipType) ||
- (kClipStack_ClipType == fClipType && this->clipStack()->quickContains(rect)) ||
- (kIRect_ClipType == fClipType && this->irect().contains(rect)) ||
- (kRect_ClipType == fClipType && this->rect().contains(rect));
- }
-
void getConservativeBounds(const GrSurface* surface,
SkIRect* devResult,
bool* isIntersectionOfRects = NULL) const {
kClipStack_ClipType,
kWideOpen_ClipType,
kIRect_ClipType,
- kRect_ClipType,
};
ClipType clipType() const { return fClipType; }
private:
union Clip {
const SkClipStack* fStack;
- SkRect fRect;
SkIRect fIRect;
} fClip;
GrRenderTarget* wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc);
///////////////////////////////////////////////////////////////////////////
+ // Clip state
+ /**
+ * Gets the current clip.
+ * @return the current clip.
+ */
+ const GrClip* getClip() const { return fClip; }
+
+ /**
+ * Sets the clip.
+ * @param clipData the clip to set.
+ */
+ void setClip(const GrClip* clipData) { fClip = clipData; }
+
+ ///////////////////////////////////////////////////////////////////////////
// Draws
/**
/**
* Draw everywhere (respecting the clip) with the paint.
*/
- void drawPaint(GrRenderTarget*, const GrClip&, const GrPaint&, const SkMatrix& viewMatrix);
+ void drawPaint(GrRenderTarget*, const GrPaint&, const SkMatrix& viewMatrix);
/**
* Draw the rect using a paint.
* The rects coords are used to access the paint (through texture matrix)
*/
void drawRect(GrRenderTarget*,
- const GrClip&,
const GrPaint& paint,
const SkMatrix& viewMatrix,
const SkRect&,
* to rectToDraw
*/
void drawNonAARectToRect(GrRenderTarget*,
- const GrClip&,
const GrPaint& paint,
const SkMatrix& viewMatrix,
const SkRect& rectToDraw,
* Draws a non-AA rect with paint and a localMatrix
*/
void drawNonAARectWithLocalMatrix(GrRenderTarget* rt,
- const GrClip& clip,
const GrPaint& paint,
const SkMatrix& viewMatrix,
const SkRect& rect,
const SkMatrix& localMatrix) {
- this->drawNonAARectToRect(rt, clip, paint, viewMatrix, rect, rect, &localMatrix);
+ this->drawNonAARectToRect(rt, paint, viewMatrix, rect, rect, &localMatrix);
}
/**
* the dash information (intervals, count, phase).
*/
void drawRRect(GrRenderTarget*,
- const GrClip&,
const GrPaint&,
const SkMatrix& viewMatrix,
const SkRRect& rrect,
* @param inner the inner roundrect
*/
void drawDRRect(GrRenderTarget*,
- const GrClip&,
const GrPaint&,
const SkMatrix& viewMatrix,
const SkRRect& outer,
* the dash information (intervals, count, phase).
*/
void drawPath(GrRenderTarget*,
- const GrClip&,
const GrPaint&,
const SkMatrix& viewMatrix,
const SkPath&,
* number of indices.
*/
void drawVertices(GrRenderTarget*,
- const GrClip&,
const GrPaint& paint,
const SkMatrix& viewMatrix,
GrPrimitiveType primitiveType,
* the dash information (intervals, count, phase).
*/
void drawOval(GrRenderTarget*,
- const GrClip&,
const GrPaint& paint,
const SkMatrix& viewMatrix,
const SkRect& oval,
#endif
///////////////////////////////////////////////////////////////////////////
+ // Helpers
+
+ class AutoClip : public ::SkNoncopyable {
+ public:
+ // This enum exists to require a caller of the constructor to acknowledge that the clip will
+ // initially be wide open. It also could be extended if there are other desirable initial
+ // clip states.
+ enum InitialClip {
+ kWideOpen_InitialClip,
+ };
+
+ AutoClip(GrContext* context, InitialClip SkDEBUGCODE(initialState))
+ : fContext(context) {
+ SkASSERT(kWideOpen_InitialClip == initialState);
+ fNewClipData.setClipStack(&fNewClipStack);
+
+ fOldClip = context->getClip();
+ context->setClip(&fNewClipData);
+ }
+
+ AutoClip(GrContext* context, const SkRect& newClipRect)
+ : fContext(context)
+ , fNewClipStack(newClipRect) {
+ fNewClipData.setClipStack(&fNewClipStack);
+
+ fOldClip = fContext->getClip();
+ fContext->setClip(&fNewClipData);
+ }
+
+ ~AutoClip() {
+ if (fContext) {
+ fContext->setClip(fOldClip);
+ }
+ }
+ private:
+ GrContext* fContext;
+ const GrClip* fOldClip;
+
+ SkClipStack fNewClipStack;
+ GrClip fNewClipData;
+ };
+
+ class AutoWideOpenIdentityDraw {
+ public:
+ AutoWideOpenIdentityDraw(GrContext* ctx)
+ : fAutoClip(ctx, AutoClip::kWideOpen_InitialClip) {
+ }
+
+ private:
+ AutoClip fAutoClip;
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
// Functions intended for internal use only.
GrGpu* getGpu() { return fGpu; }
const GrGpu* getGpu() const { return fGpu; }
private:
GrGpu* fGpu;
+ const GrClip* fClip;
GrResourceCache* fResourceCache;
GrFontCache* fFontCache;
void setupDrawBuffer();
class AutoCheckFlush;
- // Sets the paint and returns the target to draw into.
- GrDrawTarget* prepareToDraw(GrPipelineBuilder*,
- GrRenderTarget* rt,
- const GrClip&,
- const GrPaint* paint,
+ // 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*, GrRenderTarget* rt, const GrPaint* paint,
const AutoCheckFlush*);
- // A simpler version of the above which just returns the draw target. Clip is *NOT* set
- GrDrawTarget* prepareToDraw();
-
void internalDrawPath(GrDrawTarget*,
GrPipelineBuilder*,
const SkMatrix& viewMatrix,
return false;
}
- // setup new clip
- GrClip clip(dstRect);
-
+ GrContext::AutoClip acs(context, dstRect);
GrFragmentProcessor* fp;
offset->fX = bounds.left();
offset->fY = bounds.top();
SkASSERT(fp);
GrPaint paint;
paint.addColorProcessor(fp)->unref();
- context->drawNonAARectToRect(dst->asRenderTarget(), clip, paint, SkMatrix::I(), dstRect,
- srcRect);
+ context->drawNonAARectToRect(dst->asRenderTarget(), paint, SkMatrix::I(), dstRect, srcRect);
WrapTexture(dst, bounds.width(), bounds.height(), result);
return true;
// 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);
if (this->canFilterImageGPU()) {
return this->filterImageGPU(proxy, src, ctx, result, offset);
} else {
bool SkMaskFilter::directFilterMaskGPU(GrContext* context,
GrRenderTarget* rt,
GrPaint* grp,
- const GrClip&,
const SkMatrix& viewMatrix,
const SkStrokeRec& strokeRec,
const SkPath& path) const {
bool SkMaskFilter::directFilterRRectMaskGPU(GrContext* context,
GrRenderTarget* rt,
GrPaint* grp,
- const GrClip&,
const SkMatrix& viewMatrix,
const SkStrokeRec& strokeRec,
const SkRRect& rrect) const {
while (!iter.done()) {
SkRect rect = SkRect::Make(iter.rect());
- context->drawRect(maskTexture->asRenderTarget(), GrClip::WideOpen(), grPaint,
- in_matrix, rect);
+ context->drawRect(maskTexture->asRenderTarget(), grPaint, in_matrix, rect);
iter.next();
}
}
virtual bool directFilterMaskGPU(GrContext* context,
GrRenderTarget* rt,
GrPaint* grp,
- const GrClip&,
const SkMatrix& viewMatrix,
const SkStrokeRec& strokeRec,
const SkPath& path) const SK_OVERRIDE;
virtual bool directFilterRRectMaskGPU(GrContext* context,
GrRenderTarget* rt,
GrPaint* grp,
- const GrClip&,
const SkMatrix& viewMatrix,
const SkStrokeRec& strokeRec,
const SkRRect& rrect) const SK_OVERRIDE;
bool SkBlurMaskFilterImpl::directFilterMaskGPU(GrContext* context,
GrRenderTarget* rt,
GrPaint* grp,
- const GrClip& clip,
const SkMatrix& viewMatrix,
const SkStrokeRec& strokeRec,
const SkPath& path) const {
if (!viewMatrix.invert(&inverse)) {
return false;
}
- context->drawNonAARectWithLocalMatrix(rt, clip, *grp, SkMatrix::I(), rect, inverse);
+ context->drawNonAARectWithLocalMatrix(rt, *grp, SkMatrix::I(), rect, inverse);
return true;
}
bool SkBlurMaskFilterImpl::directFilterRRectMaskGPU(GrContext* context,
GrRenderTarget* rt,
GrPaint* grp,
- const GrClip& clip,
const SkMatrix& viewMatrix,
const SkStrokeRec& strokeRec,
const SkRRect& rrect) const {
if (!viewMatrix.invert(&inverse)) {
return false;
}
- context->drawNonAARectWithLocalMatrix(rt, clip, *grp, SkMatrix::I(), proxy_rect, inverse);
+ context->drawNonAARectWithLocalMatrix(rt, *grp, SkMatrix::I(), proxy_rect, inverse);
return true;
}
GrContext* context = src->getContext();
+ GrContext::AutoWideOpenIdentityDraw awo(context);
+
SkScalar xformedSigma = this->computeXformedSigma(ctm);
SkASSERT(xformedSigma > 0);
// = 0 * src + (1 - src) * dst
paint.setCoverageSetOpXPFactory(SkRegion::kDifference_Op);
}
- context->drawRect((*result)->asRenderTarget(), GrClip::WideOpen(), paint, SkMatrix::I(),
- clipRect);
+ context->drawRect((*result)->asRenderTarget(), paint, SkMatrix::I(), clipRect);
}
return true;
SkMatrix matrix;
matrix.setTranslate(-SkIntToScalar(colorBounds.x()),
-SkIntToScalar(colorBounds.y()));
- context->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), 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);
static void convolve_gaussian_1d(GrContext* context,
GrRenderTarget* rt,
- const GrClip& clip,
const SkRect& srcRect,
const SkRect& dstRect,
GrTexture* texture,
SkAutoTUnref<GrFragmentProcessor> conv(GrConvolutionEffect::CreateGaussian(
texture, direction, radius, sigma, useBounds, bounds));
paint.addColorProcessor(conv);
- context->drawNonAARectToRect(rt, clip, paint, SkMatrix::I(), dstRect, srcRect);
+ context->drawNonAARectToRect(rt, paint, SkMatrix::I(), dstRect, srcRect);
}
static void convolve_gaussian_2d(GrContext* context,
GrRenderTarget* rt,
- const GrClip& clip,
const SkRect& srcRect,
const SkRect& dstRect,
GrTexture* texture,
useBounds ? GrTextureDomain::kClamp_Mode : GrTextureDomain::kIgnore_Mode,
true, sigmaX, sigmaY));
paint.addColorProcessor(conv);
- context->drawNonAARectToRect(rt, clip, paint, SkMatrix::I(), dstRect, srcRect);
+ context->drawNonAARectToRect(rt, paint, SkMatrix::I(), dstRect, srcRect);
}
static void convolve_gaussian(GrContext* context,
GrRenderTarget* rt,
- const GrClip& clip,
const SkRect& srcRect,
const SkRect& dstRect,
GrTexture* texture,
bool cropToSrcRect) {
float bounds[2] = { 0.0f, 1.0f };
if (!cropToSrcRect) {
- convolve_gaussian_1d(context, rt, clip, srcRect, dstRect, texture,
+ convolve_gaussian_1d(context, rt, srcRect, dstRect, texture,
direction, radius, sigma, false, bounds);
return;
}
}
if (radius >= size * SK_ScalarHalf) {
// Blur radius covers srcRect; use bounds over entire draw
- convolve_gaussian_1d(context, rt, clip, 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, rt, clip, lowerSrcRect, lowerDstRect, texture,
+ convolve_gaussian_1d(context, rt, lowerSrcRect, lowerDstRect, texture,
direction, radius, sigma, true, bounds);
- convolve_gaussian_1d(context, rt, clip, upperSrcRect, upperDstRect, texture,
+ convolve_gaussian_1d(context, rt, upperSrcRect, upperDstRect, texture,
direction, radius, sigma, true, bounds);
- convolve_gaussian_1d(context, rt, clip, middleSrcRect, middleDstRect, texture,
+ convolve_gaussian_1d(context, rt, middleSrcRect, middleDstRect, texture,
direction, radius, sigma, false, bounds);
}
}
scale_rect(&srcRect, static_cast<float>(scaleFactorX),
static_cast<float>(scaleFactorY));
- // setup new clip
- GrClip clip(SkRect::MakeWH(srcRect.width(), srcRect.height()));
+ GrContext::AutoClip acs(context, SkRect::MakeWH(srcRect.width(), srcRect.height()));
SkASSERT(kBGRA_8888_GrPixelConfig == srcTexture->config() ||
kRGBA_8888_GrPixelConfig == srcTexture->config() ||
}
scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f,
i < scaleFactorY ? 0.5f : 1.0f);
- context->drawNonAARectToRect(dstTexture->asRenderTarget(), clip, paint, SkMatrix::I(),
- dstRect, srcRect);
+ context->drawNonAARectToRect(dstTexture->asRenderTarget(), paint, SkMatrix::I(), dstRect,
+ srcRect);
srcRect = dstRect;
srcTexture = dstTexture;
SkTSwap(dstTexture, tempTexture);
// We shouldn't be scaling because this is a small size blur
SkASSERT((scaleFactorX == scaleFactorY) == 1);
SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height());
- convolve_gaussian_2d(context, dstTexture->asRenderTarget(), clip, 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);
context->clear(&clearRect, 0x0, false, srcTexture->asRenderTarget());
}
SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height());
- convolve_gaussian(context, dstTexture->asRenderTarget(), clip, srcRect, dstRect,
- srcTexture, Gr1DKernelEffect::kX_Direction, radiusX, sigmaX,
- cropToRect);
+ convolve_gaussian(context, dstTexture->asRenderTarget(), srcRect, dstRect, srcTexture,
+ Gr1DKernelEffect::kX_Direction, radiusX, sigmaX, cropToRect);
srcTexture = dstTexture;
srcRect = dstRect;
SkTSwap(dstTexture, tempTexture);
}
SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height());
- convolve_gaussian(context, dstTexture->asRenderTarget(), clip, srcRect,
- dstRect, srcTexture, Gr1DKernelEffect::kY_Direction, radiusY, sigmaY,
- cropToRect);
+ convolve_gaussian(context, dstTexture->asRenderTarget(), srcRect, dstRect, srcTexture,
+ Gr1DKernelEffect::kY_Direction, radiusY, sigmaY, cropToRect);
srcTexture = dstTexture;
srcRect = dstRect;
SkTSwap(dstTexture, tempTexture);
SkRect dstRect(srcRect);
scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY);
- context->drawNonAARectToRect(dstTexture->asRenderTarget(), clip, paint,
- SkMatrix::I(), dstRect, srcRect);
+ context->drawNonAARectToRect(dstTexture->asRenderTarget(), paint, SkMatrix::I(), dstRect,
+ srcRect);
srcRect = dstRect;
srcTexture = dstTexture;
SkTSwap(dstTexture, tempTexture);
void apply_morphology_rect(GrContext* context,
GrRenderTarget* rt,
- const GrClip& clip,
GrTexture* texture,
const SkIRect& srcRect,
const SkIRect& dstRect,
radius,
morphType,
bounds))->unref();
- context->drawNonAARectToRect(rt, clip, paint, SkMatrix::I(), SkRect::Make(dstRect),
+ context->drawNonAARectToRect(rt, paint, SkMatrix::I(), SkRect::Make(dstRect),
SkRect::Make(srcRect));
}
void apply_morphology_rect_no_bounds(GrContext* context,
GrRenderTarget* rt,
- const GrClip& clip,
GrTexture* texture,
const SkIRect& srcRect,
const SkIRect& dstRect,
direction,
radius,
morphType))->unref();
- context->drawNonAARectToRect(rt, clip, paint, SkMatrix::I(), SkRect::Make(dstRect),
+ context->drawNonAARectToRect(rt, paint, SkMatrix::I(), SkRect::Make(dstRect),
SkRect::Make(srcRect));
}
void apply_morphology_pass(GrContext* context,
GrRenderTarget* rt,
- const GrClip& clip,
GrTexture* texture,
const SkIRect& srcRect,
const SkIRect& dstRect,
}
if (middleSrcRect.fLeft - middleSrcRect.fRight >= 0) {
// radius covers srcRect; use bounds over entire draw
- apply_morphology_rect(context, rt, clip, 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, rt, clip, texture, lowerSrcRect, lowerDstRect, radius,
+ apply_morphology_rect(context, rt,texture, lowerSrcRect, lowerDstRect, radius,
morphType, bounds, direction);
- apply_morphology_rect(context, rt, clip, texture, upperSrcRect, upperDstRect, radius,
+ apply_morphology_rect(context, rt, texture, upperSrcRect, upperDstRect, radius,
morphType, bounds, direction);
- apply_morphology_rect_no_bounds(context, rt, clip, texture, middleSrcRect, middleDstRect,
- radius, morphType, direction);
+ apply_morphology_rect_no_bounds(context, rt, texture, middleSrcRect, middleDstRect, radius,
+ morphType, direction);
}
}
SkASSERT(srcTexture);
GrContext* context = srcTexture->getContext();
- // setup new clip
- GrClip clip(SkRect::MakeWH(SkIntToScalar(srcTexture->width()),
- SkIntToScalar(srcTexture->height())));
+ GrContext::AutoClip acs(context, SkRect::MakeWH(SkIntToScalar(srcTexture->width()),
+ SkIntToScalar(srcTexture->height())));
SkIRect dstRect = SkIRect::MakeWH(rect.width(), rect.height());
GrSurfaceDesc desc;
if (NULL == texture) {
return false;
}
- apply_morphology_pass(context, texture->asRenderTarget(), clip, 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 ?
if (NULL == texture) {
return false;
}
- apply_morphology_pass(context, texture->asRenderTarget(), clip, 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);
GrPaint paint;
paint.addColorTextureProcessor(foregroundTex, foregroundMatrix);
paint.addColorProcessor(xferProcessor)->unref();
- context->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, SkMatrix::I(), srcRect);
+ context->drawRect(dst->asRenderTarget(), paint, SkMatrix::I(), srcRect);
offset->fX = backgroundOffset.fX;
offset->fY = backgroundOffset.fY;
return !SkDraw::ShouldDrawTextAsPaths(paint, viewMatrix);
}
-inline void GrBitmapTextContext::init(GrRenderTarget* rt, const GrClip& clip,
- const GrPaint& paint, const SkPaint& skPaint) {
- GrTextContext::init(rt, clip, paint, skPaint);
+inline void GrBitmapTextContext::init(GrRenderTarget* rt, const GrPaint& paint,
+ const SkPaint& skPaint) {
+ GrTextContext::init(rt, paint, skPaint);
fStrike = NULL;
fTotalVertexCount = 0;
}
-void GrBitmapTextContext::onDrawText(GrRenderTarget* rt, const GrClip& clip,
- 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) {
return;
}
- this->init(rt, clip, paint, skPaint);
+ this->init(rt, paint, skPaint);
SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
this->finish();
}
-void GrBitmapTextContext::onDrawPosText(GrRenderTarget* rt, const GrClip& clip,
- 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,
return;
}
- this->init(rt, clip, paint, skPaint);
+ this->init(rt, paint, skPaint);
SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
SkPath tmpPath(*glyph->fPath);
tmpPath.transform(translate);
GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle);
- fContext->drawPath(fRenderTarget, fClip, 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;
bool canDraw(const SkPaint& paint, const SkMatrix& viewMatrix) SK_OVERRIDE;
- virtual void onDrawText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
+ 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(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
+ 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(GrRenderTarget*, const GrClip&, 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
void GrClip::getConservativeBounds(int width, int height, SkIRect* devResult,
bool* isIntersectionOfRects) const {
switch (fClipType) {
+ default:
+ SkFAIL("incomplete switch\n");
case kWideOpen_ClipType: {
devResult->setLTRB(0, 0, width, height);
if (isIntersectionOfRects) {
*isIntersectionOfRects = true;
}
} break;
- case kRect_ClipType: {
- devResult->setLTRB(SkScalarCeilToInt(this->rect().fLeft),
- SkScalarCeilToInt(this->rect().fTop),
- SkScalarCeilToInt(this->rect().fRight),
- SkScalarCeilToInt(this->rect().fBottom));
- if (isIntersectionOfRects) {
- *isIntersectionOfRects = true;
- }
- } break;
case kClipStack_ClipType: {
SkRect devBounds;
this->clipStack()->getConservativeBounds(-this->origin().fX,
bool ignoreClip = clip.isWideOpen(clipSpaceRTIBounds);
if (!ignoreClip) {
// The clip mask manager always draws with a single IRect so we special case that logic here
- // Image filters just use a rect, so we also special case that logic
- switch (clip.clipType()) {
- case GrClip::kWideOpen_ClipType:
- // we should have handled this case above
- SkASSERT(false);
- case GrClip::kIRect_ClipType: {
- initialState = GrReducedClip::kAllIn_InitialState;
- clipSpaceIBounds = clip.irect();
- SkNEW_INSERT_AT_LLIST_HEAD(&elements,
- Element,
- (SkRect::Make(clipSpaceIBounds),
- SkRegion::kIntersect_Op, false));
- } break;
- case GrClip::kRect_ClipType: {
- initialState = GrReducedClip::kAllIn_InitialState;
- clipSpaceIBounds.setLTRB(SkScalarCeilToInt(clip.rect().fLeft),
- SkScalarCeilToInt(clip.rect().fTop),
- SkScalarCeilToInt(clip.rect().fRight),
- SkScalarCeilToInt(clip.rect().fBottom));
- SkNEW_INSERT_AT_LLIST_HEAD(&elements,
- Element,
- (SkRect::Make(clipSpaceIBounds),
- SkRegion::kIntersect_Op, false));
- } break;
- case GrClip::kClipStack_ClipType: {
- clipSpaceRTIBounds.offset(clip.origin());
- GrReducedClip::ReduceClipStack(*clip.clipStack(),
- clipSpaceRTIBounds,
- &elements,
- &genID,
- &initialState,
- &clipSpaceIBounds,
- &requiresAA);
- if (elements.isEmpty()) {
- if (GrReducedClip::kAllIn_InitialState == initialState) {
- ignoreClip = clipSpaceIBounds == clipSpaceRTIBounds;
- } else {
- return false;
- }
+ if (GrClip::kIRect_ClipType == clip.clipType()) {
+ initialState = GrReducedClip::kAllIn_InitialState;
+ clipSpaceIBounds = clip.irect();
+ SkNEW_INSERT_AT_LLIST_HEAD(&elements,
+ Element,
+ (SkRect::Make(clipSpaceIBounds),
+ SkRegion::kIntersect_Op, false));
+ } else {
+ clipSpaceRTIBounds.offset(clip.origin());
+ GrReducedClip::ReduceClipStack(*clip.clipStack(),
+ clipSpaceRTIBounds,
+ &elements,
+ &genID,
+ &initialState,
+ &clipSpaceIBounds,
+ &requiresAA);
+ if (elements.isEmpty()) {
+ if (GrReducedClip::kAllIn_InitialState == initialState) {
+ ignoreClip = clipSpaceIBounds == clipSpaceRTIBounds;
+ } else {
+ return false;
}
- } break;
+ }
}
}
GrContext::GrContext(const Options& opts) : fOptions(opts) {
fGpu = NULL;
+ fClip = NULL;
fPathRendererChain = NULL;
fSoftwarePathRenderer = NULL;
fResourceCache = NULL;
AutoCheckFlush acf(this);
GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::clear", this);
- GrDrawTarget* target = this->prepareToDraw();
+ GrDrawTarget* target = this->prepareToDraw(NULL, renderTarget, NULL, &acf);
if (NULL == target) {
return;
}
}
void GrContext::drawPaint(GrRenderTarget* rt,
- const GrClip& clip,
const GrPaint& origPaint,
const SkMatrix& viewMatrix) {
// set rect to be big enough to fill the space, but not super-huge, so we
return;
}
inverse.mapRect(&r);
- this->drawRect(rt, clip, *paint, viewMatrix, r);
+ this->drawRect(rt, *paint, viewMatrix, r);
} else {
SkMatrix localMatrix;
if (!viewMatrix.invert(&localMatrix)) {
AutoCheckFlush acf(this);
GrPipelineBuilder pipelineBuilder;
- GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, paint, &acf);
+ GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, paint, &acf);
if (NULL == target) {
return;
}
}
void GrContext::drawRect(GrRenderTarget* rt,
- const GrClip& clip,
const GrPaint& paint,
const SkMatrix& viewMatrix,
const SkRect& rect,
if (strokeInfo && strokeInfo->isDashed()) {
SkPath path;
path.addRect(rect);
- this->drawPath(rt, clip, paint, viewMatrix, path, *strokeInfo);
+ this->drawPath(rt, paint, viewMatrix, path, *strokeInfo);
return;
}
AutoCheckFlush acf(this);
GrPipelineBuilder pipelineBuilder;
- GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &paint, &acf);
+ GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &acf);
if (NULL == target) {
return;
}
SkRect rtRect;
pipelineBuilder.getRenderTarget()->getBoundsRect(&rtRect);
SkRect clipSpaceRTRect = rtRect;
- bool checkClip = GrClip::kWideOpen_ClipType != clip.clipType();
+ bool checkClip = fClip && GrClip::kWideOpen_ClipType != fClip->clipType();
if (checkClip) {
- clipSpaceRTRect.offset(SkIntToScalar(clip.origin().fX),
- SkIntToScalar(clip.origin().fY));
+ clipSpaceRTRect.offset(SkIntToScalar(this->getClip()->origin().fX),
+ SkIntToScalar(this->getClip()->origin().fY));
}
// Does the clip contain the entire RT?
- if (!checkClip || clip.quickContains(clipSpaceRTRect)) {
+ if (!checkClip || fClip->clipStack()->quickContains(clipSpaceRTRect)) {
SkMatrix invM;
if (!viewMatrix.invert(&invM)) {
return;
}
void GrContext::drawNonAARectToRect(GrRenderTarget* rt,
- const GrClip& clip,
const GrPaint& paint,
const SkMatrix& viewMatrix,
const SkRect& rectToDraw,
const SkMatrix* localMatrix) {
AutoCheckFlush acf(this);
GrPipelineBuilder pipelineBuilder;
- GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &paint, &acf);
+ GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &acf);
if (NULL == target) {
return;
}
}
void GrContext::drawVertices(GrRenderTarget* rt,
- const GrClip& clip,
const GrPaint& paint,
const SkMatrix& viewMatrix,
GrPrimitiveType primitiveType,
GrPipelineBuilder pipelineBuilder;
GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scope
- GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &paint, &acf);
+ GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &acf);
if (NULL == target) {
return;
}
///////////////////////////////////////////////////////////////////////////////
void GrContext::drawRRect(GrRenderTarget*rt,
- const GrClip& clip,
const GrPaint& paint,
const SkMatrix& viewMatrix,
const SkRRect& rrect,
if (strokeInfo.isDashed()) {
SkPath path;
path.addRRect(rrect);
- this->drawPath(rt, clip, paint, viewMatrix, path, strokeInfo);
+ this->drawPath(rt, paint, viewMatrix, path, strokeInfo);
return;
}
AutoCheckFlush acf(this);
GrPipelineBuilder pipelineBuilder;
- GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &paint, &acf);
+ GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &acf);
if (NULL == target) {
return;
}
///////////////////////////////////////////////////////////////////////////////
void GrContext::drawDRRect(GrRenderTarget* rt,
- const GrClip& clip,
const GrPaint& paint,
const SkMatrix& viewMatrix,
const SkRRect& outer,
AutoCheckFlush acf(this);
GrPipelineBuilder pipelineBuilder;
- GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &paint, &acf);
+ GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &acf);
GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target);
///////////////////////////////////////////////////////////////////////////////
-void GrContext::drawOval(GrRenderTarget* rt,
- const GrClip& clip,
+void GrContext::drawOval(GrRenderTarget*rt,
const GrPaint& paint,
const SkMatrix& viewMatrix,
const SkRect& oval,
if (strokeInfo.isDashed()) {
SkPath path;
path.addOval(oval);
- this->drawPath(rt, clip, paint, viewMatrix, path, strokeInfo);
+ this->drawPath(rt, paint, viewMatrix, path, strokeInfo);
return;
}
AutoCheckFlush acf(this);
GrPipelineBuilder pipelineBuilder;
- GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &paint, &acf);
+ GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &acf);
if (NULL == target) {
return;
}
}
void GrContext::drawPath(GrRenderTarget* rt,
- const GrClip& clip,
const GrPaint& paint,
const SkMatrix& viewMatrix,
const SkPath& path,
if (path.isEmpty()) {
if (path.isInverseFillType()) {
- this->drawPaint(rt, clip, paint, viewMatrix);
+ this->drawPaint(rt, paint, viewMatrix);
}
return;
}
if (path.isLine(pts)) {
AutoCheckFlush acf(this);
GrPipelineBuilder pipelineBuilder;
- GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &paint, &acf);
+ GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &acf);
if (NULL == target) {
return;
}
GrStrokeInfo newStrokeInfo(strokeInfo, false);
SkStrokeRec* stroke = newStrokeInfo.getStrokeRecPtr();
if (SkDashPath::FilterDashPath(effectPath.init(), path, stroke, NULL, info)) {
- this->drawPath(rt, clip, paint, viewMatrix, *effectPath.get(), newStrokeInfo);
+ this->drawPath(rt, paint, viewMatrix, *effectPath.get(), newStrokeInfo);
return;
}
- this->drawPath(rt, clip, paint, viewMatrix, path, newStrokeInfo);
+ this->drawPath(rt, paint, viewMatrix, path, newStrokeInfo);
return;
}
// OK.
AutoCheckFlush acf(this);
GrPipelineBuilder pipelineBuilder;
- GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &paint, &acf);
+ GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &acf);
if (NULL == target) {
return;
}
// drawing a rect to the render target.
// The bracket ensures we pop the stack if we wind up flushing below.
{
- GrDrawTarget* drawTarget = this->prepareToDraw();
- if (!drawTarget) {
- return false;
- }
+ GrDrawTarget* drawTarget = this->prepareToDraw(NULL, NULL, NULL, NULL);
GrDrawTarget::AutoGeometryPush agp(drawTarget);
GrPipelineBuilder pipelineBuilder;
SkASSERT(renderTarget);
ASSERT_OWNED_RESOURCE(renderTarget);
AutoCheckFlush acf(this);
- GrDrawTarget* target = this->prepareToDraw();
+ GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL, NULL);
if (NULL == target) {
return;
}
// Since we're going to the draw target and not GPU, no need to check kNoFlush
// here.
- GrDrawTarget* target = this->prepareToDraw();
+ GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL, NULL);
if (NULL == target) {
return;
}
GrDrawTarget* GrContext::prepareToDraw(GrPipelineBuilder* pipelineBuilder,
GrRenderTarget* rt,
- const GrClip& clip,
const GrPaint* paint,
const AutoCheckFlush* acf) {
if (NULL == fGpu) {
return NULL;
}
- ASSERT_OWNED_RESOURCE(rt);
- SkASSERT(rt && paint && acf);
- pipelineBuilder->setFromPaint(*paint, rt, clip);
- return fDrawBuffer;
-}
-
-GrDrawTarget* GrContext::prepareToDraw() {
- if (NULL == fGpu) {
- return NULL;
+ if (pipelineBuilder) {
+ ASSERT_OWNED_RESOURCE(rt);
+ SkASSERT(rt && paint && acf);
+ pipelineBuilder->setFromPaint(*paint, rt, fClip);
}
return fDrawBuffer;
}
}
GrDrawTarget* GrContext::getTextTarget() {
- return this->prepareToDraw();
+ return this->prepareToDraw(NULL, NULL, NULL, NULL);
}
const GrIndexBuffer* GrContext::getQuadIndexBuffer() const {
return true;
}
-inline void GrDistanceFieldTextContext::init(GrRenderTarget* rt, const GrClip& clip,
- const GrPaint& paint, const SkPaint& skPaint) {
- GrTextContext::init(rt, clip, paint, skPaint);
+inline void GrDistanceFieldTextContext::init(GrRenderTarget* rt, const GrPaint& paint,
+ const SkPaint& skPaint) {
+ GrTextContext::init(rt, paint, skPaint);
fStrike = NULL;
}
}
-void GrDistanceFieldTextContext::onDrawText(GrRenderTarget* rt, const GrClip& clip,
- const GrPaint& paint,
+void GrDistanceFieldTextContext::onDrawText(GrRenderTarget* rt, const GrPaint& paint,
const SkPaint& skPaint, const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
SkScalar x, SkScalar y) {
y -= alignY;
SkPoint offset = SkPoint::Make(x, y);
- this->drawPosText(rt, clip, paint, skPaint, viewMatrix, text, byteLength, positions.begin(), 2,
+ this->drawPosText(rt, paint, skPaint, viewMatrix, text, byteLength, positions.begin(), 2,
offset);
}
-void GrDistanceFieldTextContext::onDrawPosText(GrRenderTarget* rt, const GrClip& clip,
- const GrPaint& paint,
+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,
}
fViewMatrix = viewMatrix;
- this->init(rt, clip, paint, skPaint);
+ this->init(rt, paint, skPaint);
SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
this->finish();
if (fallbackTxt.count() > 0) {
- fFallbackTextContext->drawPosText(rt, clip, paint, skPaint, viewMatrix, fallbackTxt.begin(),
+ fFallbackTextContext->drawPosText(rt, paint, skPaint, viewMatrix, fallbackTxt.begin(),
fallbackTxt.count(), fallbackPos.begin(),
scalarsPerPosition, offset);
}
tmpPath.transform(ctm);
GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle);
- fContext->drawPath(fRenderTarget, fClip, fPaint, fViewMatrix, tmpPath, strokeInfo);
+ fContext->drawPath(fRenderTarget, fPaint, fViewMatrix, tmpPath, strokeInfo);
// remove this glyph from the vertices we need to allocate
fTotalVertexCount -= kVerticesPerGlyph;
bool canDraw(const SkPaint& paint, const SkMatrix& viewMatrix) SK_OVERRIDE;
- virtual void onDrawText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
+ 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(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
+ 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(GrRenderTarget*, const GrClip&, 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);
return *this;
}
-void GrPipelineBuilder::setFromPaint(const GrPaint& paint, GrRenderTarget* rt, const GrClip& clip) {
+void GrPipelineBuilder::setFromPaint(const GrPaint& paint, GrRenderTarget* rt, const GrClip* clip) {
SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages());
fColorStages.reset();
fStencilSettings.setDisabled();
fFlagBits = 0;
- fClip = clip;
+ if (clip) {
+ fClip = *clip;
+ }
this->setState(GrPipelineBuilder::kDither_StateBit, paint.isDither());
this->setState(GrPipelineBuilder::kHWAntialias_StateBit, paint.isAntiAlias());
* no GrPaint equivalents are set to default values with the exception of vertex attribute state
* which is unmodified by this function and clipping which will be enabled.
*/
- void setFromPaint(const GrPaint&, GrRenderTarget*, const GrClip&);
+ void setFromPaint(const GrPaint&, GrRenderTarget*, const GrClip*);
/// @}
}
void GrStencilAndCoverTextContext::onDrawText(GrRenderTarget* rt,
- const GrClip& clip,
const GrPaint& paint,
const SkPaint& skPaint,
const SkMatrix& viewMatrix,
// will turn off the use of device-space glyphs when perspective transforms
// are in use.
- this->init(rt, clip, paint, skPaint, byteLength, kMaxAccuracy_RenderMode, viewMatrix);
+ this->init(rt, paint, skPaint, byteLength, kMaxAccuracy_RenderMode, viewMatrix);
// Transform our starting point.
if (fUsingDeviceSpaceGlyphs) {
}
void GrStencilAndCoverTextContext::onDrawPosText(GrRenderTarget* rt,
- const GrClip& clip,
const GrPaint& paint,
const SkPaint& skPaint,
const SkMatrix& viewMatrix,
// transform is not part of SkPaint::measureText API, and thus we use the
// same glyphs as what were measured.
- this->init(rt, clip, paint, skPaint, byteLength, kMaxPerformance_RenderMode, viewMatrix);
+ this->init(rt, paint, skPaint, byteLength, kMaxPerformance_RenderMode, viewMatrix);
SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
}
void GrStencilAndCoverTextContext::init(GrRenderTarget* rt,
- const GrClip& clip,
const GrPaint& paint,
const SkPaint& skPaint,
size_t textByteLength,
RenderMode renderMode,
const SkMatrix& viewMatrix) {
- GrTextContext::init(rt, clip, paint, skPaint);
+ GrTextContext::init(rt, paint, skPaint);
fContextInitialMatrix = viewMatrix;
fViewMatrix = viewMatrix;
inverse.mapPoints(&fGlyphPositions[fFallbackGlyphsIdx], fallbackGlyphCount);
}
- fFallbackTextContext->drawPosText(fRenderTarget, fClip, paintFallback, skPaintFallback,
+ fFallbackTextContext->drawPosText(fRenderTarget, paintFallback, skPaintFallback,
fViewMatrix, (char*)&fGlyphIndices[fFallbackGlyphsIdx],
2 * fallbackGlyphCount,
get_xy_scalar_array(&fGlyphPositions[fFallbackGlyphsIdx]),
bool canDraw(const SkPaint& paint, const SkMatrix& viewMatrix) SK_OVERRIDE;
- virtual void onDrawText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
+ 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(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
+ 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(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
- size_t textByteLength, RenderMode, const SkMatrix& viewMatrix);
+ void init(GrRenderTarget*, const GrPaint&, const SkPaint&, size_t textByteLength, RenderMode,
+ const SkMatrix& viewMatrix);
bool mapToFallbackContext(SkMatrix* inverse);
void appendGlyph(const SkGlyph&, const SkPoint&);
void flush();
#include "GrTextContext.h"
#include "GrContext.h"
-#include "GrDrawTarget.h"
-#include "GrFontScaler.h"
#include "SkAutoKern.h"
#include "SkGlyphCache.h"
+#include "GrFontScaler.h"
GrTextContext::GrTextContext(GrContext* context, const SkDeviceProperties& properties) :
fFallbackTextContext(NULL),
SkDELETE(fFallbackTextContext);
}
-void GrTextContext::init(GrRenderTarget* rt, const GrClip& clip, const GrPaint& grPaint,
- const SkPaint& skPaint) {
- fClip = clip;
+void GrTextContext::init(GrRenderTarget* rt, const GrPaint& grPaint, const SkPaint& skPaint) {
+ fClip = fContext->getClip();
fRenderTarget.reset(SkRef(rt));
- fClip.getConservativeBounds(fRenderTarget->width(), fRenderTarget->height(), &fClipRect);
+ fClip->getConservativeBounds(fRenderTarget->width(), fRenderTarget->height(), &fClipRect);
fDrawTarget = fContext->getTextTarget();
fSkPaint = skPaint;
}
-bool GrTextContext::drawText(GrRenderTarget* rt, const GrClip& clip, const GrPaint& paint,
- const SkPaint& skPaint, const SkMatrix& viewMatrix,
+bool GrTextContext::drawText(GrRenderTarget* rt, const GrPaint& paint, const SkPaint& skPaint,
+ const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
SkScalar x, SkScalar y) {
GrTextContext* textContext = this;
do {
if (textContext->canDraw(skPaint, viewMatrix)) {
- textContext->onDrawText(rt, clip, paint, skPaint, viewMatrix, text, byteLength, x, y);
+ textContext->onDrawText(rt, paint, skPaint, viewMatrix, text, byteLength, x, y);
return true;
}
textContext = textContext->fFallbackTextContext;
return false;
}
-bool GrTextContext::drawPosText(GrRenderTarget* rt, const GrClip& clip, const GrPaint& paint,
- const SkPaint& skPaint, const SkMatrix& viewMatrix,
+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,
const SkPoint& offset) {
GrTextContext* textContext = this;
do {
if (textContext->canDraw(skPaint, viewMatrix)) {
- textContext->onDrawPosText(rt, clip, paint, skPaint, viewMatrix, text, byteLength, pos,
+ textContext->onDrawPosText(rt, paint, skPaint, viewMatrix, text, byteLength, pos,
scalarsPerPosition, offset);
return true;
}
#include "SkPostConfig.h"
-class GrClip;
class GrContext;
class GrDrawTarget;
class GrFontScaler;
public:
virtual ~GrTextContext();
- bool drawText(GrRenderTarget* rt, const GrClip&, const GrPaint&, const SkPaint&,
- const SkMatrix& viewMatrix, const char text[], size_t byteLength, SkScalar x,
- SkScalar y);
- bool drawPosText(GrRenderTarget* rt, const GrClip&, 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);
SkDeviceProperties fDeviceProperties;
SkAutoTUnref<GrRenderTarget> fRenderTarget;
- GrClip fClip;
+ const GrClip* fClip;
GrDrawTarget* fDrawTarget;
SkIRect fClipRect;
GrPaint fPaint;
virtual bool canDraw(const SkPaint& paint, const SkMatrix& viewMatrix) = 0;
- virtual void onDrawText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
+ 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 GrClip&, const GrPaint&, const SkPaint&,
+ 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(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&);
+ void init(GrRenderTarget*, const GrPaint&, const SkPaint&);
void finish() { fDrawTarget = NULL; }
static GrFontScaler* GetGrFontScaler(SkGlyphCache* cache);
delete fTextContext;
+ if (fContext->getClip() == &fClipData) {
+ fContext->setClip(NULL);
+ }
+
fRenderTarget->unref();
fContext->unref();
}
void SkGpuDevice::onDetachFromCanvas() {
INHERITED::onDetachFromCanvas();
- fClip.reset();
+ fClipData.reset();
fClipStack.reset(NULL);
}
SkASSERT(draw.fClipStack && draw.fClipStack == fClipStack);
- fClip.setClipStack(fClipStack, &this->getOrigin());
+ fClipData.setClipStack(fClipStack, &this->getOrigin());
+
+ fContext->setClip(&fClipData);
DO_DEFERRED_CLEAR();
}
GrPaint grPaint;
SkPaint2GrPaintShader(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint);
- fContext->drawPaint(fRenderTarget, fClip, grPaint, *draw.fMatrix);
+ fContext->drawPaint(fRenderTarget, grPaint, *draw.fMatrix);
}
// must be in SkCanvas::PointMode order
path.setIsVolatile(true);
path.moveTo(pts[0]);
path.lineTo(pts[1]);
- fContext->drawPath(fRenderTarget, fClip, grPaint, *draw.fMatrix, path, strokeInfo);
+ fContext->drawPath(fRenderTarget, grPaint, *draw.fMatrix, path, strokeInfo);
return;
}
SkPaint2GrPaintShader(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint);
fContext->drawVertices(fRenderTarget,
- fClip,
grPaint,
*draw.fMatrix,
gPointMode2PrimtiveType[mode],
GrPaint grPaint;
SkPaint2GrPaintShader(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint);
- fContext->drawRect(fRenderTarget, fClip, grPaint, *draw.fMatrix, rect, &strokeInfo);
+ fContext->drawRect(fRenderTarget, grPaint, *draw.fMatrix, rect, &strokeInfo);
}
///////////////////////////////////////////////////////////////////////////////
if (paint.getMaskFilter()->directFilterRRectMaskGPU(fContext,
fRenderTarget,
&grPaint,
- fClip,
*draw.fMatrix,
strokeInfo.getStrokeRec(),
devRRect)) {
return;
}
- fContext->drawRRect(fRenderTarget, fClip, grPaint, *draw.fMatrix, rect, strokeInfo);
+ fContext->drawRRect(fRenderTarget, grPaint, *draw.fMatrix, rect, strokeInfo);
}
void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer,
SkPaint2GrPaintShader(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint);
if (NULL == paint.getMaskFilter() && NULL == paint.getPathEffect()) {
- fContext->drawDRRect(fRenderTarget, fClip, grPaint, *draw.fMatrix, outer, inner);
+ fContext->drawDRRect(fRenderTarget, grPaint, *draw.fMatrix, outer, inner);
return;
}
}
GrPaint grPaint;
SkPaint2GrPaintShader(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint);
- fContext->drawOval(fRenderTarget, fClip, grPaint, *draw.fMatrix, oval, strokeInfo);
+ fContext->drawOval(fRenderTarget, grPaint, *draw.fMatrix, oval, strokeInfo);
}
#include "SkMaskFilter.h"
// Return true if the mask was successfully drawn.
bool draw_mask(GrContext* context,
GrRenderTarget* rt,
- const GrClip& clip,
const SkMatrix& viewMatrix,
const SkRect& maskRect,
GrPaint* grp,
if (!viewMatrix.invert(&inverse)) {
return false;
}
- context->drawNonAARectWithLocalMatrix(rt, clip, *grp, SkMatrix::I(), maskRect, inverse);
+ context->drawNonAARectWithLocalMatrix(rt, *grp, SkMatrix::I(), maskRect, inverse);
return true;
}
bool draw_with_mask_filter(GrContext* context,
GrRenderTarget* rt,
- const GrClip& clipData,
const SkMatrix& viewMatrix,
const SkPath& devPath,
SkMaskFilter* filter,
SkRect maskRect = SkRect::Make(dstM.fBounds);
- return draw_mask(context, rt, clipData, viewMatrix, maskRect, grp, texture);
+ return draw_mask(context, rt, viewMatrix, maskRect, grp, texture);
}
// Create a mask of 'devPath' and place the result in 'mask'.
SkRect clipRect = SkRect::MakeWH(maskRect.width(), maskRect.height());
+ GrContext::AutoClip ac(context, clipRect);
+
context->clear(NULL, 0x0, true, mask->asRenderTarget());
GrPaint tempPaint;
tempPaint.setAntiAlias(doAA);
tempPaint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op);
- // setup new clip
- GrClip clip(clipRect);
-
// 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(mask->asRenderTarget(), clip, tempPaint, translate, devPath, strokeInfo);
+ context->drawPath(mask->asRenderTarget(), tempPaint, translate, devPath, strokeInfo);
return mask;
}
if (paint.getMaskFilter()->directFilterMaskGPU(fContext,
fRenderTarget,
&grPaint,
- fClip,
viewMatrix,
stroke,
*devPathPtr)) {
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,
- fRenderTarget,
- fClip,
- viewMatrix,
- maskRect,
- &grPaint,
+ if (draw_mask(fContext, fRenderTarget, viewMatrix, maskRect, &grPaint,
filtered)) {
// This path is completely drawn
return;
// GPU path fails
SkPaint::Style style = stroke.isHairlineStyle() ? SkPaint::kStroke_Style :
SkPaint::kFill_Style;
- draw_with_mask_filter(fContext, fRenderTarget, fClip, viewMatrix, *devPathPtr,
+ draw_with_mask_filter(fContext, fRenderTarget, viewMatrix, *devPathPtr,
paint.getMaskFilter(), *draw.fClip, &grPaint, style);
return;
}
- fContext->drawPath(fRenderTarget, fClip, grPaint, viewMatrix, *pathPtr, strokeInfo);
+ fContext->drawPath(fRenderTarget, grPaint, viewMatrix, *pathPtr, strokeInfo);
}
static const int kBmpSmallTileSize = 1 << 10;
// pixels from the bitmap are necessary.
static void determine_clipped_src_rect(const GrContext* context,
const GrRenderTarget* rt,
- const GrClip& clip,
const SkMatrix& viewMatrix,
const SkBitmap& bitmap,
const SkRect* srcRectPtr,
SkIRect* clippedSrcIRect) {
- clip.getConservativeBounds(rt, clippedSrcIRect, NULL);
+ const GrClip* clip = context->getClip();
+ clip->getConservativeBounds(rt, clippedSrcIRect, NULL);
SkMatrix inv;
if (!viewMatrix.invert(&inv)) {
clippedSrcIRect->setEmpty();
// 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, fRenderTarget, fClip, viewMatrix, bitmap,
- srcRectPtr, clippedSrcRect);
+ determine_clipped_src_rect(fContext, fRenderTarget, viewMatrix, bitmap, srcRectPtr,
+ clippedSrcRect);
*tileSize = determine_tile_size(bitmap, *clippedSrcRect, maxTileSize);
return true;
}
}
// Figure out how much of the src we will need based on the src rect and clipping.
- determine_clipped_src_rect(fContext, fRenderTarget, fClip, viewMatrix, bitmap, srcRectPtr,
+ 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) *
SkColor2GrColor(paint.getColor());
SkPaint2GrPaintNoShader(this->context(), fRenderTarget, paint, paintColor, false, &grPaint);
- fContext->drawNonAARectToRect(fRenderTarget, fClip, grPaint, viewMatrix, dstRect,
- paintRect);
+ fContext->drawNonAARectToRect(fRenderTarget, grPaint, viewMatrix, dstRect, paintRect);
}
bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture,
SkDeviceImageFilterProxy proxy(this, SkSurfaceProps(0, getLeakyProperties().pixelGeometry()));
if (filter->canFilterImageGPU()) {
+ // 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;
SkColor2GrColorJustAlpha(paint.getColor()), false, &grPaint);
fContext->drawNonAARectToRect(fRenderTarget,
- fClip,
grPaint,
SkMatrix::I(),
SkRect::MakeXYWH(SkIntToScalar(left),
SkRect srcRect = SkRect::MakeWH(SK_Scalar1 * w / devTex->width(),
SK_Scalar1 * h / devTex->height());
- fContext->drawNonAARectToRect(fRenderTarget, fClip, grPaint, SkMatrix::I(), dstRect,
- srcRect);
+ fContext->drawNonAARectToRect(fRenderTarget, grPaint, SkMatrix::I(), dstRect, srcRect);
}
bool SkGpuDevice::canHandleImageFilter(const SkImageFilter* filter) {
colors = convertedColors.get();
}
fContext->drawVertices(fRenderTarget,
- fClip,
grPaint,
*draw.fMatrix,
primType,
SkDEBUGCODE(this->validate();)
- if (!fTextContext->drawText(fRenderTarget, fClip, 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);
}
SkDEBUGCODE(this->validate();)
- if (!fTextContext->drawPosText(fRenderTarget, fClip, 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);
}
GrSkDrawProcs* fDrawProcs;
SkAutoTUnref<const SkClipStack> fClipStack;
SkIPoint fClipOrigin;
- GrClip fClip;
+ GrClip fClipData;
GrTextContext* fTextContext;
SkSurfaceProps fSurfaceProps;
GrRenderTarget* fRenderTarget;
SkRect rect = SkRect::MakeWH(SkIntToScalar(rtDesc.fWidth), SkIntToScalar(rtDesc.fHeight));
SkRect localRect = SkRect::MakeWH(1.f, 1.f);
- context->drawNonAARectToRect(stretched->asRenderTarget(), GrClip::WideOpen(), paint,
- SkMatrix::I(), rect, localRect);
+ GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialClip);
+ context->drawNonAARectToRect(stretched->asRenderTarget(), paint, SkMatrix::I(), rect,
+ localRect);
return stretched;
}
paint.addColorProcessor(yuvToRgbProcessor);
SkRect r = SkRect::MakeWH(SkIntToScalar(yuvInfo.fSize[0].fWidth),
SkIntToScalar(yuvInfo.fSize[0].fHeight));
-
- ctx->drawRect(renderTarget, GrClip::WideOpen(), paint, SkMatrix::I(), r);
+ GrContext::AutoClip ac(ctx, GrContext::AutoClip::kWideOpen_InitialClip);
+ ctx->drawRect(renderTarget, paint, SkMatrix::I(), r);
return result;
}
// asFragmentProcessor(). Since these calls get passed back to the client, we don't really
// want them messing around with the context.
{
+ GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialClip);
+
// Allow the shader to modify paintColor and also create an effect to be installed as
// the first color effect on the GrPaint.
GrFragmentProcessor* fp = NULL;
{kDivByAlpha_RoundUp_PMConversion, kMulByAlpha_RoundDown_PMConversion},
};
+ GrContext::AutoWideOpenIdentityDraw awoid(context);
+
bool failed = true;
for (size_t i = 0; i < SK_ARRAY_COUNT(kConversionRules) && failed; ++i) {
GrPaint paint1;
paint1.addColorProcessor(pmToUPM1);
- context->drawNonAARectToRect(readTex->asRenderTarget(),
- GrClip::WideOpen(),
- paint1,
- SkMatrix::I(),
- kDstRect,
+ context->drawNonAARectToRect(readTex->asRenderTarget(), paint1, SkMatrix::I(), kDstRect,
kSrcRect);
readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, firstRead);
GrPaint paint2;
paint2.addColorProcessor(upmToPM);
- context->drawNonAARectToRect(tempTex->asRenderTarget(),
- GrClip::WideOpen(),
- paint2,
- SkMatrix::I(),
- kDstRect,
+ context->drawNonAARectToRect(tempTex->asRenderTarget(), paint2, SkMatrix::I(), kDstRect,
kSrcRect);
GrPaint paint3;
paint3.addColorProcessor(pmToUPM2);
- context->drawNonAARectToRect(readTex->asRenderTarget(),
- GrClip::WideOpen(),
- paint3,
- SkMatrix::I(),
- kDstRect,
+ context->drawNonAARectToRect(readTex->asRenderTarget(), paint3, SkMatrix::I(), kDstRect,
kSrcRect);
readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, secondRead);
REPORTER_ASSERT(reporter, screen == devStackBounds);
REPORTER_ASSERT(reporter, isIntersectionOfRects);
- // wrap the SkClipStack in a GrClip
+ // wrap the SkClipStack in a GrClipData
GrClip clipData;
clipData.setClipStack(&stack);
- SkIRect devGrClipBound;
+ SkIRect devGrClipDataBound;
clipData.getConservativeBounds(texture,
- &devGrClipBound,
+ &devGrClipDataBound,
&isIntersectionOfRects);
- // make sure that GrClip is behaving itself
- REPORTER_ASSERT(reporter, intScreen == devGrClipBound);
+ // make sure that GrClipData is behaving itself
+ REPORTER_ASSERT(reporter, intScreen == devGrClipDataBound);
REPORTER_ASSERT(reporter, isIntersectionOfRects);
}
SkClipStack stack;
stack.clipDevRect(screen, SkRegion::kReplace_Op, false);
- // wrap the SkClipStack in a GrClip
+ // wrap the SkClipStack in a GrClipData
GrClip clip;
clip.setClipStack(&stack);