diff options
author | 2017-08-24 21:28:04 +0000 | |
---|---|---|
committer | 2017-08-24 21:34:38 +0000 | |
commit | 87ae9895692e4a97873a510178003d1ba70ab79a (patch) | |
tree | e7c66b2fc574bf3795a27ca81bf9b3301cd9d0a1 /src/gpu/GrSoftwarePathRenderer.cpp | |
parent | 59c7a6e6e252359dfcd84dc82986354398e2e8c3 (diff) |
Revert "Threaded generation of software paths"
This reverts commit 76323bc0615044a5921afef0e19a350f3d04ffe0.
Reason for revert: Breaking NUC bots in threaded gm comparison:
https://chromium-swarm.appspot.com/task?id=382e589753187f10&refresh=10
Original change's description:
> Threaded generation of software paths
>
> All information needed by the thread is captured by the prepare
> callback object, the lambda captures a pointer to that, and does the
> mask render. Once it's done, it signals the semaphore (also owned by the
> callback). The callback defers the semaphore wait even longer (into the
> ASAP upload), so the odds of waiting for the thread are REALLY low.
>
> Also did a bunch of cleanup along the way, and put in some trace markers
> so we can monitor how well this is working.
>
> Traces of a GM that includes GPU and SW path rendering (path-reverse):
>
> Original:
> https://screenshot.googleplex.com/f5BG3901tQg.png
> Threaded, with wait in the callback (notice pre flush callback blocking):
> https://screenshot.googleplex.com/htOSZFE2s04.png
> Current version, with wait deferred to ASAP upload function:
> https://screenshot.googleplex.com/GHjD0U3C34q.png
>
> Bug: skia:
> Change-Id: I3d5a230bbd68eb35e1f0574b308485c691435790
> Reviewed-on: https://skia-review.googlesource.com/36560
> Commit-Queue: Brian Osman <brianosman@google.com>
> Reviewed-by: Brian Salomon <bsalomon@google.com>
TBR=egdaniel@google.com,mtklein@google.com,bsalomon@google.com,robertphillips@google.com,brianosman@google.com
Change-Id: Icac0918a3771859f671b69ae07ae0fedd3ebb3db
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/38560
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/gpu/GrSoftwarePathRenderer.cpp')
-rw-r--r-- | src/gpu/GrSoftwarePathRenderer.cpp | 135 |
1 files changed, 14 insertions, 121 deletions
diff --git a/src/gpu/GrSoftwarePathRenderer.cpp b/src/gpu/GrSoftwarePathRenderer.cpp index e76af89933..27ba8e6436 100644 --- a/src/gpu/GrSoftwarePathRenderer.cpp +++ b/src/gpu/GrSoftwarePathRenderer.cpp @@ -8,16 +8,9 @@ #include "GrSoftwarePathRenderer.h" #include "GrAuditTrail.h" #include "GrClip.h" -#include "GrContextPriv.h" #include "GrGpuResourcePriv.h" -#include "GrOpFlushState.h" -#include "GrOpList.h" #include "GrResourceProvider.h" #include "GrSWMaskHelper.h" -#include "SkMakeUnique.h" -#include "SkSemaphore.h" -#include "SkTaskGroup.h" -#include "SkTraceEvent.h" #include "ops/GrDrawOp.h" #include "ops/GrRectOpFactory.h" @@ -152,84 +145,10 @@ void GrSoftwarePathRenderer::DrawToTargetWithShapeMask( maskMatrix.preConcat(viewMatrix); paint.addCoverageFragmentProcessor(GrSimpleTextureEffect::Make( std::move(proxy), nullptr, maskMatrix, GrSamplerParams::kNone_FilterMode)); - DrawNonAARect(renderTargetContext, std::move(paint), userStencilSettings, clip, SkMatrix::I(), - dstRect, invert); -} - -static sk_sp<GrTextureProxy> make_deferred_mask_texture_proxy(GrContext* context, SkBackingFit fit, - int width, int height) { - GrSurfaceDesc desc; - desc.fOrigin = kTopLeft_GrSurfaceOrigin; - desc.fWidth = width; - desc.fHeight = height; - desc.fConfig = kAlpha_8_GrPixelConfig; - - sk_sp<GrSurfaceContext> sContext = - context->contextPriv().makeDeferredSurfaceContext(desc, fit, SkBudgeted::kYes); - if (!sContext || !sContext->asTextureProxy()) { - return nullptr; - } - return sContext->asTextureProxyRef(); -} - -namespace { - -class GrMaskUploaderPrepareCallback : public GrPrepareCallback { -public: - GrMaskUploaderPrepareCallback(sk_sp<GrTextureProxy> proxy, const SkIRect& maskBounds, - const SkMatrix& viewMatrix, const GrShape& shape, GrAA aa) - : fProxy(std::move(proxy)) - , fMaskBounds(maskBounds) - , fViewMatrix(viewMatrix) - , fShape(shape) - , fAA(aa) - , fWaited(false) {} - - ~GrMaskUploaderPrepareCallback() override { - if (!fWaited) { - // This can happen if our owning op list fails to instantiate (so it never prepares) - fPixelsReady.wait(); - } - } - - void operator()(GrOpFlushState* flushState) override { - TRACE_EVENT0("skia", "Mask Uploader Pre Flush Callback"); - auto uploadMask = [this](GrDrawOp::WritePixelsFn& writePixelsFn) { - TRACE_EVENT0("skia", "Mask Upload"); - this->fPixelsReady.wait(); - this->fWaited = true; - // If the worker thread was unable to allocate pixels, this check will fail, and we'll - // end up drawing with an uninitialized mask texture, but at least we won't crash. - if (this->fPixels.addr()) { - writePixelsFn(this->fProxy.get(), 0, 0, - this->fPixels.width(), this->fPixels.height(), - kAlpha_8_GrPixelConfig, - this->fPixels.addr(), this->fPixels.rowBytes()); - } - }; - flushState->addASAPUpload(std::move(uploadMask)); - } - - SkAutoPixmapStorage* getPixels() { return &fPixels; } - SkSemaphore* getSemaphore() { return &fPixelsReady; } - const SkIRect& getMaskBounds() const { return fMaskBounds; } - const SkMatrix* getViewMatrix() const { return &fViewMatrix; } - const GrShape& getShape() const { return fShape; } - GrAA getAA() const { return fAA; } - -private: - // NOTE: This ref cnt isn't thread safe! - sk_sp<GrTextureProxy> fProxy; - SkAutoPixmapStorage fPixels; - SkSemaphore fPixelsReady; - - SkIRect fMaskBounds; - SkMatrix fViewMatrix; - GrShape fShape; - GrAA fAA; - bool fWaited; -}; - + renderTargetContext->addDrawOp(clip, + GrRectOpFactory::MakeNonAAFillWithLocalMatrix( + std::move(paint), SkMatrix::I(), invert, dstRect, + GrAAType::kNone, &userStencilSettings)); } //////////////////////////////////////////////////////////////////////////////// @@ -286,6 +205,11 @@ bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) { } GrUniqueKey maskKey; + struct KeyData { + SkScalar fFractionalTranslateX; + SkScalar fFractionalTranslateY; + }; + if (useCache) { // We require the upper left 2x2 of the matrix to match exactly for a cache hit. SkScalar sx = args.fViewMatrix->get(SkMatrix::kMScaleX); @@ -316,6 +240,8 @@ bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) { builder[4] = fracX | (fracY >> 8); args.fShape->writeUnstyledKey(&builder[5]); #endif + // FIXME: Doesn't the key need to consider whether we're using AA or not? In practice that + // should always be true, though. } sk_sp<GrTextureProxy> proxy; @@ -325,42 +251,9 @@ bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) { if (!proxy) { SkBackingFit fit = useCache ? SkBackingFit::kExact : SkBackingFit::kApprox; GrAA aa = GrAAType::kCoverage == args.fAAType ? GrAA::kYes : GrAA::kNo; - - SkTaskGroup* taskGroup = args.fContext->contextPriv().getTaskGroup(); - if (taskGroup) { - proxy = make_deferred_mask_texture_proxy(args.fContext, fit, - boundsForMask->width(), - boundsForMask->height()); - if (!proxy) { - return false; - } - - auto uploader = skstd::make_unique<GrMaskUploaderPrepareCallback>( - proxy, *boundsForMask, *args.fViewMatrix, *args.fShape, aa); - GrMaskUploaderPrepareCallback* uploaderRaw = uploader.get(); - - 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); - } else { - SkDEBUGFAIL("Unable to allocate SW mask."); - } - uploaderRaw->getSemaphore()->signal(); - }; - taskGroup->add(std::move(drawAndUploadMask)); - args.fRenderTargetContext->getOpList()->addPrepareCallback(std::move(uploader)); - } else { - GrSWMaskHelper helper; - if (!helper.init(*boundsForMask, args.fViewMatrix)) { - return false; - } - helper.drawShape(*args.fShape, SkRegion::kReplace_Op, aa, 0xFF); - proxy = helper.toTextureProxy(args.fContext, fit); - } - + proxy = GrSWMaskHelper::DrawShapeMaskToTexture(args.fContext, *args.fShape, + *boundsForMask, aa, + fit, args.fViewMatrix); if (!proxy) { return false; } |