Make GrSWMaskHelper take a matrix for each draw

Change-Id: I52659857174848696f360d64552a9690db24ed50
Reviewed-on: https://skia-review.googlesource.com/40883
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Salomon 2017-08-30 13:55:35 -04:00 committed by Skia Commit-Bot
parent 71554bc256
commit 740775606d
4 changed files with 34 additions and 28 deletions

View File

@ -444,7 +444,7 @@ sk_sp<GrTextureProxy> GrClipStackClip::createSoftwareClipMask(
SkMatrix translate;
translate.setTranslate(SkIntToScalar(-reducedClip.left()), SkIntToScalar(-reducedClip.top()));
if (!helper.init(maskSpaceIBounds, &translate)) {
if (!helper.init(maskSpaceIBounds)) {
return nullptr;
}
helper.clear(InitialState::kAllIn == reducedClip.initialState() ? 0xFF : 0x00);
@ -462,25 +462,25 @@ sk_sp<GrTextureProxy> GrClipStackClip::createSoftwareClipMask(
if (kReverseDifference_SkClipOp == op) {
SkRect temp = SkRect::Make(reducedClip.ibounds());
// invert the entire scene
helper.drawRect(temp, SkRegion::kXOR_Op, GrAA::kNo, 0xFF);
helper.drawRect(temp, translate, SkRegion::kXOR_Op, GrAA::kNo, 0xFF);
}
SkPath clipPath;
element->asDeviceSpacePath(&clipPath);
clipPath.toggleInverseFillType();
GrShape shape(clipPath, GrStyle::SimpleFill());
helper.drawShape(shape, SkRegion::kReplace_Op, aa, 0x00);
helper.drawShape(shape, translate, SkRegion::kReplace_Op, aa, 0x00);
continue;
}
// The other ops (union, xor, diff) only affect pixels inside
// the geometry so they can just be drawn normally
if (Element::DeviceSpaceType::kRect == element->getDeviceSpaceType()) {
helper.drawRect(element->getDeviceSpaceRect(), (SkRegion::Op)op, aa, 0xFF);
helper.drawRect(element->getDeviceSpaceRect(), translate, (SkRegion::Op)op, aa, 0xFF);
} else {
SkPath path;
element->asDeviceSpacePath(&path);
GrShape shape(path, GrStyle::SimpleFill());
helper.drawShape(shape, (SkRegion::Op)op, aa, 0xFF);
helper.drawShape(shape, translate, (SkRegion::Op)op, aa, 0xFF);
}
}

View File

@ -33,25 +33,35 @@ static SkBlendMode op_to_mode(SkRegion::Op op) {
/**
* Draw a single rect element of the clip stack into the accumulation bitmap
*/
void GrSWMaskHelper::drawRect(const SkRect& rect, SkRegion::Op op, GrAA aa, uint8_t alpha) {
void GrSWMaskHelper::drawRect(const SkRect& rect, const SkMatrix& matrix, SkRegion::Op op, GrAA aa,
uint8_t alpha) {
SkPaint paint;
paint.setBlendMode(op_to_mode(op));
paint.setAntiAlias(GrAA::kYes == aa);
paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha));
SkMatrix translatedMatrix = matrix;
translatedMatrix.postTranslate(fTranslate.fX, fTranslate.fY);
fDraw.fMatrix = &translatedMatrix;
fDraw.drawRect(rect, paint);
SkDEBUGCODE(fDraw.fMatrix = (SkMatrix*)0xbbbbbbbb);
}
/**
* Draw a single path element of the clip stack into the accumulation bitmap
*/
void GrSWMaskHelper::drawShape(const GrShape& shape, SkRegion::Op op, GrAA aa, uint8_t alpha) {
void GrSWMaskHelper::drawShape(const GrShape& shape, const SkMatrix& matrix, SkRegion::Op op,
GrAA aa, uint8_t alpha) {
SkPaint paint;
paint.setPathEffect(shape.style().refPathEffect());
shape.style().strokeRec().applyToPaint(&paint);
paint.setAntiAlias(GrAA::kYes == aa);
SkMatrix translatedMatrix = matrix;
translatedMatrix.postTranslate(fTranslate.fX, fTranslate.fY);
fDraw.fMatrix = &translatedMatrix;
SkPath path;
shape.asPath(&path);
if (SkRegion::kReplace_Op == op && 0xFF == alpha) {
@ -62,17 +72,12 @@ void GrSWMaskHelper::drawShape(const GrShape& shape, SkRegion::Op op, GrAA aa, u
paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha));
fDraw.drawPath(path, paint);
}
}
SkDEBUGCODE(fDraw.fMatrix = (SkMatrix*)0xbbbbbbbb);
};
bool GrSWMaskHelper::init(const SkIRect& resultBounds, const SkMatrix* matrix) {
if (matrix) {
fMatrix = *matrix;
} else {
fMatrix.setIdentity();
}
// Now translate so the bound's UL corner is at the origin
fMatrix.postTranslate(-SkIntToScalar(resultBounds.fLeft), -SkIntToScalar(resultBounds.fTop));
bool GrSWMaskHelper::init(const SkIRect& resultBounds) {
// We will need to translate draws so the bound's UL corner is at the origin
fTranslate = {-SkIntToScalar(resultBounds.fLeft), -SkIntToScalar(resultBounds.fTop)};
SkIRect bounds = SkIRect::MakeWH(resultBounds.width(), resultBounds.height());
const SkImageInfo bmImageInfo = SkImageInfo::MakeA8(bounds.width(), bounds.height());
@ -85,7 +90,8 @@ bool GrSWMaskHelper::init(const SkIRect& resultBounds, const SkMatrix* matrix) {
fDraw.fDst = *fPixels;
fRasterClip.setRect(bounds);
fDraw.fRC = &fRasterClip;
fDraw.fMatrix = &fMatrix;
// Each draw must specify the matrix.
SkDEBUGCODE(fDraw.fMatrix = (SkMatrix*)0xbbbbbbbb);
return true;
}

View File

@ -41,13 +41,13 @@ public:
// may be accumulated in the helper during creation, "resultBounds"
// allows the caller to specify the region of interest - to limit the
// amount of work.
bool init(const SkIRect& resultBounds, const SkMatrix* matrix);
bool init(const SkIRect& resultBounds);
// Draw a single rect into the accumulation bitmap using the specified op
void drawRect(const SkRect& rect, SkRegion::Op op, GrAA, uint8_t alpha);
void drawRect(const SkRect& rect, const SkMatrix& matrix, SkRegion::Op op, GrAA, uint8_t alpha);
// Draw a single path into the accumuation bitmap using the specified op
void drawShape(const GrShape&, SkRegion::Op op, GrAA, uint8_t alpha);
void drawShape(const GrShape&, const SkMatrix& matrix, SkRegion::Op op, GrAA, uint8_t alpha);
sk_sp<GrTextureProxy> toTextureProxy(GrContext*, SkBackingFit fit);
@ -57,7 +57,7 @@ public:
}
private:
SkMatrix fMatrix;
SkVector fTranslate;
SkAutoPixmapStorage* fPixels;
SkAutoPixmapStorage fPixelsStorage;
SkDraw fDraw;

View File

@ -342,9 +342,9 @@ bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) {
auto drawAndUploadMask = [uploaderRaw] {
TRACE_EVENT0("skia", "Threaded SW Mask Render");
GrSWMaskHelper helper(uploaderRaw->getPixels());
if (helper.init(uploaderRaw->getMaskBounds(), uploaderRaw->getViewMatrix())) {
helper.drawShape(uploaderRaw->getShape(), SkRegion::kReplace_Op,
uploaderRaw->getAA(), 0xFF);
if (helper.init(uploaderRaw->getMaskBounds())) {
helper.drawShape(uploaderRaw->getShape(), *uploaderRaw->getViewMatrix(),
SkRegion::kReplace_Op, uploaderRaw->getAA(), 0xFF);
} else {
SkDEBUGFAIL("Unable to allocate SW mask.");
}
@ -354,10 +354,10 @@ bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) {
args.fRenderTargetContext->getOpList()->addPrepareCallback(std::move(uploader));
} else {
GrSWMaskHelper helper;
if (!helper.init(*boundsForMask, args.fViewMatrix)) {
if (!helper.init(*boundsForMask)) {
return false;
}
helper.drawShape(*args.fShape, SkRegion::kReplace_Op, aa, 0xFF);
helper.drawShape(*args.fShape, *args.fViewMatrix, SkRegion::kReplace_Op, aa, 0xFF);
proxy = helper.toTextureProxy(args.fContext, fit);
}