diff options
author | 2017-08-30 13:55:35 -0400 | |
---|---|---|
committer | 2017-08-30 18:14:26 +0000 | |
commit | 740775606d0af0a03ceebba7428d88fb279c5d94 (patch) | |
tree | eaa03efb6d733d62c9e26fed04b2ee10e5021e18 /src/gpu | |
parent | 71554bc256b705fe959b7aa2fb2f24ed48782362 (diff) |
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>
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/GrClipStackClip.cpp | 10 | ||||
-rw-r--r-- | src/gpu/GrSWMaskHelper.cpp | 34 | ||||
-rw-r--r-- | src/gpu/GrSWMaskHelper.h | 8 | ||||
-rw-r--r-- | src/gpu/GrSoftwarePathRenderer.cpp | 10 |
4 files changed, 34 insertions, 28 deletions
diff --git a/src/gpu/GrClipStackClip.cpp b/src/gpu/GrClipStackClip.cpp index 5e366a7a0c..ef71941686 100644 --- a/src/gpu/GrClipStackClip.cpp +++ b/src/gpu/GrClipStackClip.cpp @@ -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); } } diff --git a/src/gpu/GrSWMaskHelper.cpp b/src/gpu/GrSWMaskHelper.cpp index af0d1bdc22..5d0c3755d0 100644 --- a/src/gpu/GrSWMaskHelper.cpp +++ b/src/gpu/GrSWMaskHelper.cpp @@ -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); } -} - -bool GrSWMaskHelper::init(const SkIRect& resultBounds, const SkMatrix* matrix) { - if (matrix) { - fMatrix = *matrix; - } else { - fMatrix.setIdentity(); - } + SkDEBUGCODE(fDraw.fMatrix = (SkMatrix*)0xbbbbbbbb); +}; - // 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; } diff --git a/src/gpu/GrSWMaskHelper.h b/src/gpu/GrSWMaskHelper.h index 4e1363c3df..6590143469 100644 --- a/src/gpu/GrSWMaskHelper.h +++ b/src/gpu/GrSWMaskHelper.h @@ -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; diff --git a/src/gpu/GrSoftwarePathRenderer.cpp b/src/gpu/GrSoftwarePathRenderer.cpp index e76af89933..1363e1ae7c 100644 --- a/src/gpu/GrSoftwarePathRenderer.cpp +++ b/src/gpu/GrSoftwarePathRenderer.cpp @@ -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); } |