Threaded generation of software paths
Re-land of: https://skia-review.googlesource.com/36560
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: Idb92f385590749f41328a9aec65b2a93f4775079
Reviewed-on: https://skia-review.googlesource.com/40775
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/gpu/GrSWMaskHelper.cpp b/src/gpu/GrSWMaskHelper.cpp
index eb39865..af0d1bd 100644
--- a/src/gpu/GrSWMaskHelper.cpp
+++ b/src/gpu/GrSWMaskHelper.cpp
@@ -6,12 +6,12 @@
*/
#include "GrSWMaskHelper.h"
+
#include "GrContext.h"
#include "GrContextPriv.h"
#include "GrShape.h"
#include "GrSurfaceContext.h"
#include "GrTextureProxy.h"
-#include "SkDistanceFieldGen.h"
/*
* Convert a boolean operation into a transfer mode code
@@ -76,13 +76,13 @@
SkIRect bounds = SkIRect::MakeWH(resultBounds.width(), resultBounds.height());
const SkImageInfo bmImageInfo = SkImageInfo::MakeA8(bounds.width(), bounds.height());
- if (!fPixels.tryAlloc(bmImageInfo)) {
+ if (!fPixels->tryAlloc(bmImageInfo)) {
return false;
}
- fPixels.erase(0);
+ fPixels->erase(0);
sk_bzero(&fDraw, sizeof(fDraw));
- fDraw.fDst = fPixels;
+ fDraw.fDst = *fPixels;
fRasterClip.setRect(bounds);
fDraw.fRC = &fRasterClip;
fDraw.fMatrix = &fMatrix;
@@ -92,8 +92,8 @@
sk_sp<GrTextureProxy> GrSWMaskHelper::toTextureProxy(GrContext* context, SkBackingFit fit) {
GrSurfaceDesc desc;
desc.fOrigin = kTopLeft_GrSurfaceOrigin;
- desc.fWidth = fPixels.width();
- desc.fHeight = fPixels.height();
+ desc.fWidth = fPixels->width();
+ desc.fHeight = fPixels->height();
desc.fConfig = kAlpha_8_GrPixelConfig;
sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeDeferredSurfaceContext(
@@ -105,39 +105,9 @@
}
SkImageInfo ii = SkImageInfo::MakeA8(desc.fWidth, desc.fHeight);
- if (!sContext->writePixels(ii, fPixels.addr(), fPixels.rowBytes(), 0, 0)) {
+ if (!sContext->writePixels(ii, fPixels->addr(), fPixels->rowBytes(), 0, 0)) {
return nullptr;
}
return sContext->asTextureProxyRef();
}
-
-/**
- * Convert mask generation results to a signed distance field
- */
-void GrSWMaskHelper::toSDF(unsigned char* sdf) {
- SkGenerateDistanceFieldFromA8Image(sdf, (const unsigned char*)fPixels.addr(),
- fPixels.width(), fPixels.height(), fPixels.rowBytes());
-}
-
-////////////////////////////////////////////////////////////////////////////////
-/**
- * Software rasterizes shape to A8 mask and uploads the result to a scratch texture. Returns the
- * resulting texture on success; nullptr on failure.
- */
-sk_sp<GrTextureProxy> GrSWMaskHelper::DrawShapeMaskToTexture(GrContext* context,
- const GrShape& shape,
- const SkIRect& resultBounds,
- GrAA aa,
- SkBackingFit fit,
- const SkMatrix* matrix) {
- GrSWMaskHelper helper;
-
- if (!helper.init(resultBounds, matrix)) {
- return nullptr;
- }
-
- helper.drawShape(shape, SkRegion::kReplace_Op, aa, 0xFF);
-
- return helper.toTextureProxy(context, fit);
-}