/**
* getBounds places the current finite bound in its first parameter. In its
* second, it indicates which kind of bound is being returned. If
- * 'finiteBound' is a normal bounding box then it encloses all writeable
- * pixels. If 'finiteBound' is an inside out bounding box then it
+ * 'canvFiniteBound' is a normal bounding box then it encloses all writeable
+ * pixels. If 'canvFiniteBound' is an inside out bounding box then it
* encloses all the un-writeable pixels and the true/normal bound is the
* infinite plane. isIntersectionOfRects is an optional parameter
- * that is true if 'finiteBound' resulted from an intersection of rects.
+ * that is true if 'canvFiniteBound' resulted from an intersection of rects.
*/
- void getBounds(SkRect* finiteBound,
+ void getBounds(SkRect* canvFiniteBound,
BoundsType* boundType,
bool* isIntersectionOfRects = NULL) const;
int offsetY,
int maxWidth,
int maxHeight,
- SkRect* bounds,
+ SkRect* devBounds,
bool* isIntersectionOfRects = NULL) const;
private:
}
void getConservativeBounds(const GrSurface* surface,
- GrIRect* result,
+ GrIRect* devResult,
bool* isIntersectionOfRects = NULL) const;
};
}
}
-void SkClipStack::getBounds(SkRect* finiteBound,
+void SkClipStack::getBounds(SkRect* canvFiniteBound,
BoundsType* boundType,
bool* isIntersectionOfRects) const {
- SkASSERT(NULL != finiteBound && NULL != boundType);
+ SkASSERT(NULL != canvFiniteBound && NULL != boundType);
Rec* rec = (Rec*)fDeque.back();
if (NULL == rec) {
// the clip is wide open - the infinite plane w/ no pixels un-writeable
- finiteBound->setEmpty();
+ canvFiniteBound->setEmpty();
*boundType = kInsideOut_BoundsType;
if (NULL != isIntersectionOfRects) {
*isIntersectionOfRects = false;
return;
}
- *finiteBound = rec->fFiniteBound;
+ *canvFiniteBound = rec->fFiniteBound;
*boundType = rec->fFiniteBoundType;
if (NULL != isIntersectionOfRects) {
*isIntersectionOfRects = rec->fIsIntersectionOfRects;
int offsetY,
int maxWidth,
int maxHeight,
- SkRect* bounds,
+ SkRect* devBounds,
bool* isIntersectionOfRects) const {
- SkASSERT(NULL != bounds);
+ SkASSERT(NULL != devBounds);
- bounds->setLTRB(0, 0,
- SkIntToScalar(maxWidth), SkIntToScalar(maxHeight));
+ devBounds->setLTRB(0, 0,
+ SkIntToScalar(maxWidth), SkIntToScalar(maxHeight));
SkRect temp;
SkClipStack::BoundsType boundType;
+ // temp starts off in canvas space here
this->getBounds(&temp, &boundType, isIntersectionOfRects);
if (SkClipStack::kInsideOut_BoundsType == boundType) {
return;
}
+ // but is converted to device space here
temp.offset(SkIntToScalar(offsetX), SkIntToScalar(offsetY));
- if (!bounds->intersect(temp)) {
- bounds->setEmpty();
+ if (!devBounds->intersect(temp)) {
+ devBounds->setEmpty();
}
}
int generate_lines_and_quads(const SkPath& path,
const SkMatrix& m,
const SkVector& translate,
- GrIRect clip,
+ const GrIRect& devClipBounds,
PtArray* lines,
PtArray* quads,
IntArray* quadSubdivCnts) {
bounds.setBounds(devPts, 2);
bounds.outset(SK_Scalar1, SK_Scalar1);
bounds.roundOut(&ibounds);
- if (SkIRect::Intersects(clip, ibounds)) {
+ if (SkIRect::Intersects(devClipBounds, ibounds)) {
SkPoint* pts = lines->push_back_n(2);
pts[0] = devPts[0];
pts[1] = devPts[1];
bounds.setBounds(devPts, 3);
bounds.outset(SK_Scalar1, SK_Scalar1);
bounds.roundOut(&ibounds);
- if (SkIRect::Intersects(clip, ibounds)) {
+ if (SkIRect::Intersects(devClipBounds, ibounds)) {
int subdiv = num_quad_subdivs(devPts);
GrAssert(subdiv >= -1);
if (-1 == subdiv) {
bounds.setBounds(devPts, 4);
bounds.outset(SK_Scalar1, SK_Scalar1);
bounds.roundOut(&ibounds);
- if (SkIRect::Intersects(clip, ibounds)) {
+ if (SkIRect::Intersects(devClipBounds, ibounds)) {
PREALLOC_PTARRAY(32) q;
// we don't need a direction if we aren't constraining the subdivision
static const SkPath::Direction kDummyDir = SkPath::kCCW_Direction;
}
bounds.outset(SK_Scalar1, SK_Scalar1);
bounds.roundOut(&ibounds);
- if (SkIRect::Intersects(clip, ibounds)) {
+ if (SkIRect::Intersects(devClipBounds, ibounds)) {
int subdiv = num_quad_subdivs(qInDevSpace);
GrAssert(subdiv >= -1);
if (-1 == subdiv) {
const GrDrawState& drawState = target->getDrawState();
int rtHeight = drawState.getRenderTarget()->height();
- GrIRect clip;
- target->getClip()->getConservativeBounds(drawState.getRenderTarget(), &clip);
+ GrIRect devClipBounds;
+ target->getClip()->getConservativeBounds(drawState.getRenderTarget(),
+ &devClipBounds);
GrVertexLayout layout = GrDrawTarget::kEdge_VertexLayoutBit;
GrMatrix viewM = drawState.getViewMatrix();
if (NULL == translate) {
translate = &gZeroVec;
}
- *quadCnt = generate_lines_and_quads(path, viewM, *translate, clip,
+ *quadCnt = generate_lines_and_quads(path, viewM, *translate, devClipBounds,
&lines, &quads, &qSubdivs);
*lineCnt = lines.count() / 2;
* isIntersectionOfRects will be set to true.
*/
void GrClipData::getConservativeBounds(const GrSurface* surface,
- GrIRect* result,
+ GrIRect* devResult,
bool* isIntersectionOfRects) const {
// Until we switch to using the SkClipStack directly we need to take
SkIntToScalar(surface->width()),
SkIntToScalar(surface->height()));
+ // convervativeBounds starts off in canvas coordinates here
GrRect conservativeBounds = fClipStack->getConservativeBounds();
+ // but is translated into device coordinates here
conservativeBounds.offset(SkIntToScalar(-fOrigin.fX),
SkIntToScalar(-fOrigin.fY));
conservativeBounds.setEmpty();
}
- conservativeBounds.roundOut(result);
+ conservativeBounds.roundOut(devResult);
if (NULL != isIntersectionOfRects) {
*isIntersectionOfRects = fClipStack->isRect();
// sampler matrix this also alters the vertex layout
void setup_drawstate_aaclip(GrGpu* gpu,
GrTexture* result,
- const GrIRect &bound) {
+ const GrIRect &devBound) {
GrDrawState* drawState = gpu->drawState();
GrAssert(drawState);
GrMatrix mat;
mat.setIDiv(result->width(), result->height());
- mat.preTranslate(SkIntToScalar(-bound.fLeft), SkIntToScalar(-bound.fTop));
+ mat.preTranslate(SkIntToScalar(-devBound.fLeft),
+ SkIntToScalar(-devBound.fTop));
mat.preConcat(drawState->getViewMatrix());
drawState->sampler(maskStage)->reset(mat);
// GrDrawTarget should have filtered this for us
GrAssert(NULL != rt);
- GrIRect bounds;
+ GrIRect devClipBounds;
bool isIntersectionOfRects = false;
- clipDataIn->getConservativeBounds(rt, &bounds, &isIntersectionOfRects);
- if (bounds.isEmpty()) {
+ clipDataIn->getConservativeBounds(rt, &devClipBounds,
+ &isIntersectionOfRects);
+ if (devClipBounds.isEmpty()) {
return false;
}
// The clip geometry is complex enough that it will be more
// efficient to create it entirely in software
GrTexture* result = NULL;
- GrIRect bound;
- if (this->createSoftwareClipMask(*clipDataIn, &result, &bound)) {
- setup_drawstate_aaclip(fGpu, result, bound);
+ GrIRect devBound;
+ if (this->createSoftwareClipMask(*clipDataIn, &result, &devBound)) {
+ setup_drawstate_aaclip(fGpu, result, devBound);
fGpu->disableScissor();
this->setGpuStencil();
return true;
// render target) we aren't going to use scissoring like the stencil
// path does (see scissorSettings below)
GrTexture* result = NULL;
- GrIRect bound;
- if (this->createAlphaClipMask(*clipDataIn, &result, &bound)) {
- setup_drawstate_aaclip(fGpu, result, bound);
+ GrIRect devBound;
+ if (this->createAlphaClipMask(*clipDataIn, &result, &devBound)) {
+ setup_drawstate_aaclip(fGpu, result, devBound);
fGpu->disableScissor();
this->setGpuStencil();
return true;
// If the clip is a rectangle then just set the scissor. Otherwise, create
// a stencil mask.
if (isIntersectionOfRects) {
- fGpu->enableScissor(bounds);
+ fGpu->enableScissor(devClipBounds);
this->setGpuStencil();
return true;
}
// use the stencil clip if we can't represent the clip as a rectangle.
- bool useStencil = !clipDataIn->fClipStack->isWideOpen() && !bounds.isEmpty();
+ bool useStencil = !clipDataIn->fClipStack->isWideOpen() &&
+ !devClipBounds.isEmpty();
if (useStencil) {
- this->createStencilClipMask(*clipDataIn, bounds);
+ this->createStencilClipMask(*clipDataIn, devClipBounds);
}
// This must occur after createStencilClipMask. That function may change
// the scissor. Also, it only guarantees that the stencil mask is correct
// within the bounds it was passed, so we must use both stencil and scissor
// test to the bounds for the final draw.
- fGpu->enableScissor(bounds);
+ fGpu->enableScissor(devClipBounds);
this->setGpuStencil();
return true;
}
namespace {
/**
- * Does "container" contain "containee"? If either is empty then
- * no containment is possible. "container" is in canvas coordinates while
- * "containee" is in device coordiates. "origin" provides the mapping between
+ * Does "canvContainer" contain "devContainee"? If either is empty then
+ * no containment is possible. "canvContainer" is in canvas coordinates while
+ * "devContainee" is in device coordiates. "origin" provides the mapping between
* the two.
*/
-bool contains(const SkRect& container,
- const SkIRect& containee,
+bool contains(const SkRect& canvContainer,
+ const SkIRect& devContainee,
const SkIPoint& origin) {
- return !containee.isEmpty() && !container.isEmpty() &&
- container.fLeft <= SkIntToScalar(containee.fLeft+origin.fX) &&
- container.fTop <= SkIntToScalar(containee.fTop+origin.fY) &&
- container.fRight >= SkIntToScalar(containee.fRight+origin.fX) &&
- container.fBottom >= SkIntToScalar(containee.fBottom+origin.fY);
+ return !devContainee.isEmpty() && !canvContainer.isEmpty() &&
+ canvContainer.fLeft <= SkIntToScalar(devContainee.fLeft+origin.fX) &&
+ canvContainer.fTop <= SkIntToScalar(devContainee.fTop+origin.fY) &&
+ canvContainer.fRight >= SkIntToScalar(devContainee.fRight+origin.fX) &&
+ canvContainer.fBottom >= SkIntToScalar(devContainee.fBottom+origin.fY);
}
////////////////////////////////////////////////////////////////////////////////
// and what op should be used to draw the first element that isn't skipped.
const GrClip::Iter::Clip* process_initial_clip_elements(
GrClip::Iter* iter,
- const GrIRect& bounds,
+ const GrIRect& devBounds,
bool* clearToInside,
SkRegion::Op* firstOp,
const GrClipData& clipData) {
// if this element contains the entire bounds then we
// can skip it.
if (NULL != clip->fRect &&
- contains(*clip->fRect, bounds, clipData.fOrigin)) {
+ contains(*clip->fRect, devBounds, clipData.fOrigin)) {
break;
}
// if everything is initially clearToInside then intersect is
return true;
}
+// 'rect' enters in device coordinates and leaves in canvas coordinates
+void device_to_canvas(SkRect* rect, const SkIPoint& origin) {
+ GrAssert(NULL != rect);
+
+ rect->fLeft += SkIntToScalar(origin.fX);
+ rect->fTop += SkIntToScalar(origin.fY);
+ rect->fRight += SkIntToScalar(origin.fX);
+ rect->fBottom += SkIntToScalar(origin.fY);
+}
+
}
////////////////////////////////////////////////////////////////////////////////
// Returns true if there is no more work to be done (i.e., we got a cache hit)
bool GrClipMaskManager::clipMaskPreamble(const GrClipData& clipDataIn,
GrTexture** result,
- GrIRect* resultBounds) {
+ GrIRect* devResultBounds) {
GrDrawState* origDrawState = fGpu->drawState();
GrAssert(origDrawState->isClipState());
// unlike the stencil path the alpha path is not bound to the size of the
// render target - determine the minimum size required for the mask
// Note: intBounds is in device (as opposed to canvas) coordinates
- GrIRect intBounds;
- clipDataIn.getConservativeBounds(rt, &intBounds);
+ GrIRect devClipBounds;
+ clipDataIn.getConservativeBounds(rt, &devClipBounds);
// need to outset a pixel since the standard bounding box computation
// path doesn't leave any room for antialiasing (esp. w.r.t. rects)
- intBounds.outset(1, 1);
+ devClipBounds.outset(1, 1);
// TODO: make sure we don't outset if bounds are still 0,0 @ min
if (fAACache.canReuse(*clipDataIn.fClipStack,
- intBounds.width(),
- intBounds.height())) {
+ devClipBounds.width(),
+ devClipBounds.height())) {
*result = fAACache.getLastMask();
- fAACache.getLastBound(resultBounds);
+ fAACache.getLastBound(devResultBounds);
return true;
}
- this->setupCache(*clipDataIn.fClipStack, intBounds);
+ this->setupCache(*clipDataIn.fClipStack, devClipBounds);
- *resultBounds = intBounds;
+ *devResultBounds = devClipBounds;
return false;
}
// Create a 8-bit clip mask in alpha
bool GrClipMaskManager::createAlphaClipMask(const GrClipData& clipDataIn,
GrTexture** result,
- GrIRect *resultBounds) {
- GrAssert(NULL != resultBounds);
+ GrIRect *devResultBounds) {
+ GrAssert(NULL != devResultBounds);
GrAssert(kNone_ClipMaskType == fCurrClipMaskType);
- if (this->clipMaskPreamble(clipDataIn, result, resultBounds)) {
+ if (this->clipMaskPreamble(clipDataIn, result, devResultBounds)) {
fCurrClipMaskType = kAlpha_ClipMaskType;
return true;
}
GrDrawTarget::AutoGeometryPush agp(fGpu);
- if (0 != resultBounds->fTop || 0 != resultBounds->fLeft ||
+ if (0 != devResultBounds->fTop || 0 != devResultBounds->fLeft ||
0 != clipDataIn.fOrigin.fX || 0 != clipDataIn.fOrigin.fY) {
// if we were able to trim down the size of the mask we need to
// offset the paths & rects that will be used to compute it
drawState->viewMatrix()->setTranslate(
- SkIntToScalar(-resultBounds->fLeft-clipDataIn.fOrigin.fX),
- SkIntToScalar(-resultBounds->fTop-clipDataIn.fOrigin.fY));
+ SkIntToScalar(-devResultBounds->fLeft-clipDataIn.fOrigin.fX),
+ SkIntToScalar(-devResultBounds->fTop-clipDataIn.fOrigin.fY));
}
bool clearToInside;
GrClip::Iter iter(*clipDataIn.fClipStack,
GrClip::Iter::kBottom_IterStart);
const GrClip::Iter::Clip* clip = process_initial_clip_elements(&iter,
- *resultBounds,
+ *devResultBounds,
&clearToInside,
&firstOp,
clipDataIn);
fGpu->clear(NULL, 0x00000000, accum->asRenderTarget());
setup_boolean_blendcoeffs(drawState, op);
- this->drawClipShape(accum, clip, *resultBounds);
+ this->drawClipShape(accum, clip, *devResultBounds);
} else if (SkRegion::kReverseDifference_Op == op ||
SkRegion::kIntersect_Op == op) {
// there is no point in intersecting a screen filling rectangle.
if (SkRegion::kIntersect_Op == op && NULL != clip->fRect &&
- contains(*clip->fRect, *resultBounds, clipDataIn.fOrigin)) {
+ contains(*clip->fRect, *devResultBounds, clipDataIn.fOrigin)) {
continue;
}
- getTemp(*resultBounds, &temp);
+ getTemp(*devResultBounds, &temp);
if (NULL == temp.texture()) {
fAACache.reset();
return false;
fGpu->clear(NULL, 0x00000000, temp.texture()->asRenderTarget());
setup_boolean_blendcoeffs(drawState, SkRegion::kReplace_Op);
- this->drawClipShape(temp.texture(), clip, *resultBounds);
+ this->drawClipShape(temp.texture(), clip, *devResultBounds);
// TODO: rather than adding these two translations here
// compute the bounding box needed to render the texture
// into temp
- if (0 != resultBounds->fTop || 0 != resultBounds->fLeft ||
+ if (0 != devResultBounds->fTop || 0 != devResultBounds->fLeft ||
0 != clipDataIn.fOrigin.fX || 0 != clipDataIn.fOrigin.fY) {
// In order for the merge of the temp clip into the accumulator
// to work we need to disable the translation
setup_boolean_blendcoeffs(drawState, op);
this->drawTexture(accum, temp.texture());
- if (0 != resultBounds->fTop || 0 != resultBounds->fLeft ||
+ if (0 != devResultBounds->fTop || 0 != devResultBounds->fLeft ||
0 != clipDataIn.fOrigin.fX || 0 != clipDataIn.fOrigin.fY) {
drawState->viewMatrix()->setTranslate(
- SkIntToScalar(-resultBounds->fLeft-clipDataIn.fOrigin.fX),
- SkIntToScalar(-resultBounds->fTop-clipDataIn.fOrigin.fY));
+ SkIntToScalar(-devResultBounds->fLeft-clipDataIn.fOrigin.fX),
+ SkIntToScalar(-devResultBounds->fTop-clipDataIn.fOrigin.fY));
}
} else {
// all the remaining ops can just be directly draw into
// the accumulation buffer
setup_boolean_blendcoeffs(drawState, op);
- this->drawClipShape(accum, clip, *resultBounds);
+ this->drawClipShape(accum, clip, *devResultBounds);
}
}
}
////////////////////////////////////////////////////////////////////////////////
-// Create a 1-bit clip mask in the stencil buffer. 'bounds' are in device
+// Create a 1-bit clip mask in the stencil buffer. 'devClipBounds' are in device
// (as opposed to canvas) coordinates
bool GrClipMaskManager::createStencilClipMask(const GrClipData& clipDataIn,
- const GrIRect& bounds) {
+ const GrIRect& devClipBounds) {
GrAssert(kNone_ClipMaskType == fCurrClipMaskType);
// we finish drawing it into the stencil.
const GrClipData* oldClipData = fGpu->getClip();
- GrClip newClipStack(bounds);
+ // The origin of 'newClipData' is (0, 0) so it is okay to place
+ // a device-coordinate bound in 'newClipStack'
+ GrClip newClipStack(devClipBounds);
GrClipData newClipData;
newClipData.fClipStack = &newClipStack;
if (0 != clipDataIn.fOrigin.fX || 0 != clipDataIn.fOrigin.fY) {
// Add the saveLayer's offset to the view matrix rather than
// offset each individual draw
- GrMatrix m;
-
- m.setTranslate(SkIntToScalar(-clipDataIn.fOrigin.fX),
+ drawState->viewMatrix()->setTranslate(
+ SkIntToScalar(-clipDataIn.fOrigin.fX),
SkIntToScalar(-clipDataIn.fOrigin.fY));
-
- drawState->setViewMatrix(m);
}
#if !VISUALIZE_COMPLEX_CLIP
"Ganesh only handles 16b or smaller stencil buffers");
clipBit = (1 << (clipBit-1));
- GrIRect rtRect = GrIRect::MakeWH(rt->width(), rt->height());
+ GrIRect devRTRect = GrIRect::MakeWH(rt->width(), rt->height());
bool clearToInside;
SkRegion::Op firstOp = SkRegion::kReplace_Op; // suppress warning
GrClip::Iter iter(*oldClipData->fClipStack,
GrClip::Iter::kBottom_IterStart);
const GrClip::Iter::Clip* clip = process_initial_clip_elements(&iter,
- rtRect,
+ devRTRect,
&clearToInside,
&firstOp,
clipDataIn);
- fGpu->clearStencilClip(bounds, clearToInside);
+ fGpu->clearStencilClip(devClipBounds, clearToInside);
bool first = true;
// walk through each clip element and perform its set op
// there is no point in intersecting a screen filling
// rectangle.
if (SkRegion::kIntersect_Op == op &&
- contains(*clip->fRect, rtRect, oldClipData->fOrigin)) {
+ contains(*clip->fRect, devRTRect, oldClipData->fOrigin)) {
continue;
}
} else if (NULL != clip->fPath) {
}
} else {
SET_RANDOM_COLOR
- // 'bounds' is already in device coordinates so the
+ // 'devClipBounds' is already in device coordinates so the
// translation in the view matrix is inappropriate.
- // Apply the inverse translation so the drawn rect will
+ // Convert it to canvas space so the drawn rect will
// be in the correct location
- GrRect rect = GrRect::MakeLTRB(
- SkIntToScalar(bounds.fLeft+clipDataIn.fOrigin.fX),
- SkIntToScalar(bounds.fTop+clipDataIn.fOrigin.fY),
- SkIntToScalar(bounds.fRight+clipDataIn.fOrigin.fX),
- SkIntToScalar(bounds.fBottom+clipDataIn.fOrigin.fY));
- fGpu->drawSimpleRect(rect, NULL);
+ GrRect canvClipBounds;
+ canvClipBounds.set(devClipBounds);
+ device_to_canvas(&canvClipBounds, clipDataIn.fOrigin);
+ fGpu->drawSimpleRect(canvClipBounds, NULL);
}
}
}
bool GrClipMaskManager::createSoftwareClipMask(const GrClipData& clipDataIn,
GrTexture** result,
- GrIRect* resultBounds) {
+ GrIRect* devResultBounds) {
GrAssert(kNone_ClipMaskType == fCurrClipMaskType);
- if (this->clipMaskPreamble(clipDataIn, result, resultBounds)) {
+ if (this->clipMaskPreamble(clipDataIn, result, devResultBounds)) {
return true;
}
GrMatrix matrix;
matrix.setTranslate(SkIntToScalar(-clipDataIn.fOrigin.fX),
SkIntToScalar(-clipDataIn.fOrigin.fY));
- helper.init(*resultBounds, &matrix);
+ helper.init(*devResultBounds, &matrix);
bool clearToInside;
SkRegion::Op firstOp = SkRegion::kReplace_Op; // suppress warning
GrClip::Iter iter(*clipDataIn.fClipStack,
GrClip::Iter::kBottom_IterStart);
const GrClip::Iter::Clip* clip = process_initial_clip_elements(&iter,
- *resultBounds,
+ *devResultBounds,
&clearToInside,
&firstOp,
clipDataIn);
// difference we invert all the pixels before clearing the ones
// outside the geometry.
if (SkRegion::kReverseDifference_Op == op) {
- SkRect temp = SkRect::MakeLTRB(
- SkIntToScalar(resultBounds->left()),
- SkIntToScalar(resultBounds->top()),
- SkIntToScalar(resultBounds->right()),
- SkIntToScalar(resultBounds->bottom()));
+ SkRect temp;
+ temp.set(*devResultBounds);
// invert the entire scene
helper.draw(temp, SkRegion::kXOR_Op, false, 0xFF);
GrClipMaskCache fAACache; // cache for the AA path
bool createStencilClipMask(const GrClipData& clipDataIn,
- const GrIRect& bounds);
+ const GrIRect& devClipBounds);
bool createAlphaClipMask(const GrClipData& clipDataIn,
GrTexture** result,
- GrIRect *resultBounds);
+ GrIRect *devResultBounds);
bool createSoftwareClipMask(const GrClipData& clipDataIn,
GrTexture** result,
- GrIRect *resultBounds);
+ GrIRect *devResultBounds);
bool clipMaskPreamble(const GrClipData& clipDataIn,
GrTexture** result,
- GrIRect *resultBounds);
+ GrIRect *devResultBounds);
bool useSWOnlyPath(const GrClip& clipIn);
bool get_path_and_clip_bounds(const GrDrawTarget* target,
const SkPath& path,
const GrMatrix& matrix,
- GrIRect* pathBounds,
- GrIRect* clipBounds) {
+ GrIRect* devPathBounds,
+ GrIRect* devClipBounds) {
// compute bounds as intersection of rt size, clip, and path
const GrRenderTarget* rt = target->getDrawState().getRenderTarget();
if (NULL == rt) {
return false;
}
- *pathBounds = GrIRect::MakeWH(rt->width(), rt->height());
+ *devPathBounds = GrIRect::MakeWH(rt->width(), rt->height());
- target->getClip()->getConservativeBounds(rt, clipBounds);
- if (!pathBounds->intersect(*clipBounds)) {
+ target->getClip()->getConservativeBounds(rt, devClipBounds);
+
+ // TODO: getConservativeBounds already intersects with the
+ // render target's bounding box. Remove this next line
+ if (!devPathBounds->intersect(*devClipBounds)) {
return false;
}
matrix.mapRect(&pathSBounds, path.getBounds());
GrIRect pathIBounds;
pathSBounds.roundOut(&pathIBounds);
- if (!pathBounds->intersect(pathIBounds)) {
+ if (!devPathBounds->intersect(pathIBounds)) {
// set the correct path bounds, as this would be used later.
- *pathBounds = pathIBounds;
+ *devPathBounds = pathIBounds;
return false;
}
} else {
- *pathBounds = GrIRect::EmptyIRect();
+ *devPathBounds = GrIRect::EmptyIRect();
return false;
}
return true;
////////////////////////////////////////////////////////////////////////////////
void draw_around_inv_path(GrDrawTarget* target,
- const GrIRect& clipBounds,
- const GrIRect& pathBounds) {
+ const GrIRect& devClipBounds,
+ const GrIRect& devPathBounds) {
GrDrawTarget::AutoDeviceCoordDraw adcd(target);
if (!adcd.succeeded()) {
return;
}
GrRect rect;
- if (clipBounds.fTop < pathBounds.fTop) {
- rect.iset(clipBounds.fLeft, clipBounds.fTop,
- clipBounds.fRight, pathBounds.fTop);
+ if (devClipBounds.fTop < devPathBounds.fTop) {
+ rect.iset(devClipBounds.fLeft, devClipBounds.fTop,
+ devClipBounds.fRight, devPathBounds.fTop);
target->drawSimpleRect(rect, NULL);
}
- if (clipBounds.fLeft < pathBounds.fLeft) {
- rect.iset(clipBounds.fLeft, pathBounds.fTop,
- pathBounds.fLeft, pathBounds.fBottom);
+ if (devClipBounds.fLeft < devPathBounds.fLeft) {
+ rect.iset(devClipBounds.fLeft, devPathBounds.fTop,
+ devPathBounds.fLeft, devPathBounds.fBottom);
target->drawSimpleRect(rect, NULL);
}
- if (clipBounds.fRight > pathBounds.fRight) {
- rect.iset(pathBounds.fRight, pathBounds.fTop,
- clipBounds.fRight, pathBounds.fBottom);
+ if (devClipBounds.fRight > devPathBounds.fRight) {
+ rect.iset(devPathBounds.fRight, devPathBounds.fTop,
+ devClipBounds.fRight, devPathBounds.fBottom);
target->drawSimpleRect(rect, NULL);
}
- if (clipBounds.fBottom > pathBounds.fBottom) {
- rect.iset(clipBounds.fLeft, pathBounds.fBottom,
- clipBounds.fRight, clipBounds.fBottom);
+ if (devClipBounds.fBottom > devPathBounds.fBottom) {
+ rect.iset(devClipBounds.fLeft, devPathBounds.fBottom,
+ devClipBounds.fRight, devClipBounds.fBottom);
target->drawSimpleRect(rect, NULL);
}
}
vm.postTranslate(translate->fX, translate->fY);
}
- GrIRect pathBounds, clipBounds;
+ GrIRect devPathBounds, devClipBounds;
if (!get_path_and_clip_bounds(target, path, vm,
- &pathBounds, &clipBounds)) {
+ &devPathBounds, &devClipBounds)) {
if (GrIsFillInverted(fill)) {
- draw_around_inv_path(target, clipBounds, pathBounds);
+ draw_around_inv_path(target, devClipBounds, devPathBounds);
}
return true;
}
SkAutoTUnref<GrTexture> texture(
GrSWMaskHelper::DrawPathMaskToTexture(fContext, path,
- pathBounds, fill,
+ devPathBounds, fill,
antiAlias, &vm));
if (NULL == texture) {
return false;
}
- GrSWMaskHelper::DrawToTargetWithPathMask(texture, target, pathBounds);
+ GrSWMaskHelper::DrawToTargetWithPathMask(texture, target, devPathBounds);
if (GrIsFillInverted(fill)) {
- draw_around_inv_path(target, clipBounds, pathBounds);
+ draw_around_inv_path(target, devClipBounds, devPathBounds);
}
return true;
fDrawTarget = NULL;
}
+namespace {
+
+// 'rect' enters in canvas coordinates and leaves in device coordinates
+void canvas_to_device(SkRect* rect, const SkIPoint& origin) {
+ GrAssert(NULL != rect);
+
+ rect->fLeft -= SkIntToScalar(origin.fX);
+ rect->fTop -= SkIntToScalar(origin.fY);
+ rect->fRight -= SkIntToScalar(origin.fX);
+ rect->fBottom -= SkIntToScalar(origin.fY);
+}
+
+};
+
GrTextContext::GrTextContext(GrContext* context,
const GrPaint& paint,
const GrMatrix* extMatrix) : fPaint(paint) {
const GrClipData* clipData = context->getClip();
GrRect conservativeBound = clipData->fClipStack->getConservativeBounds();
- conservativeBound.offset(SkIntToScalar(-clipData->fOrigin.fX),
- SkIntToScalar(-clipData->fOrigin.fY));
+ canvas_to_device(&conservativeBound, clipData->fOrigin);
if (!fExtMatrix.isIdentity()) {
GrMatrix inverse;
int renderTargetWidth,
int renderTargetHeight) {
- SkIRect bound;
- SkClipStack::BoundsType boundType;
- SkRect temp;
+ SkIRect devBound;
+
+ devBound.setLTRB(0, 0, renderTargetWidth, renderTargetHeight);
- bound.setLTRB(0, 0, renderTargetWidth, renderTargetHeight);
+ SkClipStack::BoundsType boundType;
+ SkRect canvTemp;
- clipStack.getBounds(&temp, &boundType);
+ clipStack.getBounds(&canvTemp, &boundType);
if (SkClipStack::kNormal_BoundsType == boundType) {
- SkIRect temp2;
+ SkIRect devTemp;
- temp.roundOut(&temp2);
+ canvTemp.roundOut(&devTemp);
- temp2.offset(-origin.fX, -origin.fY);
+ devTemp.offset(-origin.fX, -origin.fY);
- if (!bound.intersect(temp2)) {
- bound.setEmpty();
+ if (!devBound.intersect(devTemp)) {
+ devBound.setEmpty();
}
}
-// GrAssert(bound.contains(clipRegion.getBounds()));
+// GrAssert(devBound.contains(clipRegion.getBounds()));
}
#endif
renderTargetWidth, renderTargetHeight);
#endif
- SkRect bounds;
+ SkRect devClipBounds;
bool isIntersectionOfRects = false;
clipStack.getConservativeBounds(0, 0,
renderTargetWidth,
renderTargetHeight,
- &bounds,
+ &devClipBounds,
&isIntersectionOfRects);
- result->setFromIterator(&iter, bounds);
+ result->setFromIterator(&iter, devClipBounds);
GrAssert(result->isRect() == isIntersectionOfRects);
this->flushScissor();
this->flushAAState(type);
- GrIRect* rect = NULL;
- GrIRect clipBounds;
+ GrIRect* devRect = NULL;
+ GrIRect devClipBounds;
if (drawState.isClipState()) {
- fClip->getConservativeBounds(drawState.getRenderTarget(), &clipBounds);
- rect = &clipBounds;
+ fClip->getConservativeBounds(drawState.getRenderTarget(),
+ &devClipBounds);
+ devRect = &devClipBounds;
}
// This must come after textures are flushed because a texture may need
// to be msaa-resolved (which will modify bound FBO state).
- this->flushRenderTarget(rect);
+ this->flushRenderTarget(devRect);
return true;
}
stack.clipDevRect(clipRect, SkRegion::kReplace_Op, false);
bool isIntersectionOfRects = true;
- SkRect stackBounds;
+ SkRect devStackBounds;
stack.getConservativeBounds(0, 0, kXSize, kYSize,
- &stackBounds,
+ &devStackBounds,
&isIntersectionOfRects);
// make sure that the SkClipStack is behaving itself
- REPORTER_ASSERT(reporter, screen == stackBounds);
+ REPORTER_ASSERT(reporter, screen == devStackBounds);
REPORTER_ASSERT(reporter, isIntersectionOfRects);
// convert the SkClipStack to a GrClip
iter.reset(stack);
GrClip clip;
- clip.setFromIterator(&iter, stackBounds);
+ clip.setFromIterator(&iter, devStackBounds);
- const GrRect& grBound = clip.getConservativeBounds();
+ const GrRect& canvGrClipBound = clip.getConservativeBounds();
// make sure that GrClip is behaving itself
- REPORTER_ASSERT(reporter, clipRect == grBound);
+ REPORTER_ASSERT(reporter, clipRect == canvGrClipBound);
REPORTER_ASSERT(reporter, clip.isRect());
// wrap the GrClip in a GrClipData
GrClipData clipData;
clipData.fClipStack = &clip;
- SkIRect intGrBound;
+ SkIRect devGrClipDataBound;
clipData.getConservativeBounds(texture,
- &intGrBound,
+ &devGrClipDataBound,
&isIntersectionOfRects);
// make sure that GrClipData is behaving itself
- REPORTER_ASSERT(reporter, intScreen == intGrBound);
+ REPORTER_ASSERT(reporter, intScreen == devGrClipDataBound);
REPORTER_ASSERT(reporter, isIntersectionOfRects);
}
clipB.addRoundRect(rectB, SkIntToScalar(5), SkIntToScalar(5));
SkClipStack stack;
- SkRect bound;
+ SkRect devClipBound;
bool isIntersectionOfRects = false;
int testCase = 0;
REPORTER_ASSERT(reporter, !stack.isWideOpen());
- stack.getConservativeBounds(0, 0, 100, 100, &bound,
+ stack.getConservativeBounds(0, 0, 100, 100, &devClipBound,
&isIntersectionOfRects);
if (useRects) {
}
SkASSERT(testCase < gNumCases);
- REPORTER_ASSERT(reporter, bound == gAnswerRectsBW[testCase]);
+ REPORTER_ASSERT(reporter, devClipBound == gAnswerRectsBW[testCase]);
++testCase;
stack.restore();