Remove SkBlitter:resetShaderContext()
Refactor SkDraw::drawVertices() to reset the whole blitter instead.
No noticeable bench diff.
out/Release/nanobench --config 8888 -m patch_grid_colors_tex
Before:
9/9 MB 1 9.24ms 11.4ms 11.5ms 15ms 16% █▆▅▄▄▃▂▂▁▁ 8888 patch_grid_colors_texs_big
9/9 MB 1 5.2ms 5.2ms 5.2ms 5.21ms 0% █▃▂▁▂▂▃▂▂▁ 8888 patch_grid_colors_texs_medium
9/9 MB 2 378µs 380µs 380µs 382µs 0% █▆▅▄▄▁▄▄▆▄ 8888 patch_grid_colors_texs_small
After:
9/9 MB 1 9.29ms 11.5ms 11.6ms 15.3ms 17% █▇▅▄▄▃▂▂▁▁ 8888 patch_grid_colors_texs_big
9/9 MB 1 5.15ms 5.16ms 5.16ms 5.18ms 0% █▄▁▁▄▂▁▂▃▂ 8888 patch_grid_colors_texs_medium
9/9 MB 2 378µs 380µs 380µs 382µs 0% █▅▄▃▁▄▄▄▃▄ 8888 patch_grid_colors_texs_small
R=reed@google.com,mtklein@google.com,herb@google.com
BUG=skia:6168
Change-Id: I0b6b7d1297323681d8d2838040450c4e1afabc17
Reviewed-on: https://skia-review.googlesource.com/7626
Reviewed-by: Mike Klein <mtklein@chromium.org>
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
diff --git a/src/core/SkBlitter.cpp b/src/core/SkBlitter.cpp
index d3c60b7..d8e3dfd 100644
--- a/src/core/SkBlitter.cpp
+++ b/src/core/SkBlitter.cpp
@@ -25,10 +25,6 @@
bool SkBlitter::isNullBlitter() const { return false; }
-bool SkBlitter::resetShaderContext(const SkShader::ContextRec&) {
- return true;
-}
-
const SkPixmap* SkBlitter::justAnOpaqueColor(uint32_t* value) {
return nullptr;
}
@@ -1005,23 +1001,6 @@
fShader->unref();
}
-bool SkShaderBlitter::resetShaderContext(const SkShader::ContextRec& rec) {
- // Only destroy the old context if we have a new one. We need to ensure to have a
- // live context in fShaderContext because the storage is owned by an SkSmallAllocator
- // outside of this class.
- // The new context will be of the same size as the old one because we use the same
- // shader to create it. It is therefore safe to re-use the storage.
- fShaderContext->~Context();
- SkShader::Context* ctx = fShader->createContext(rec, (void*)fShaderContext);
- if (nullptr == ctx) {
- // Need a valid context in fShaderContext's storage, so we can later (or our caller) call
- // the in-place destructor.
- new (fShaderContext) SkZeroShaderContext(*fShader, rec);
- return false;
- }
- return true;
-}
-
///////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef SK_DEBUG
diff --git a/src/core/SkBlitter.h b/src/core/SkBlitter.h
index ac4712e..cab2afc 100644
--- a/src/core/SkBlitter.h
+++ b/src/core/SkBlitter.h
@@ -108,11 +108,6 @@
virtual bool isNullBlitter() const;
/**
- * Special methods for SkShaderBlitter. On all other classes this is a no-op.
- */
- virtual bool resetShaderContext(const SkShader::ContextRec&);
-
- /**
* Special methods for blitters that can blit more than one row at a time.
* This function returns the number of rows that this blitter could optimally
* process at a time. It is still required to support blitting one scanline
diff --git a/src/core/SkCoreBlitters.h b/src/core/SkCoreBlitters.h
index 3ff1e1d..62bf73e 100644
--- a/src/core/SkCoreBlitters.h
+++ b/src/core/SkCoreBlitters.h
@@ -37,13 +37,6 @@
SkShader::Context* shaderContext);
virtual ~SkShaderBlitter();
- /**
- * Create a new shader context and uses it instead of the old one if successful.
- * Will create the context at the same location as the old one (this is safe
- * because the shader itself is unchanged).
- */
- bool resetShaderContext(const SkShader::ContextRec&) override;
-
protected:
uint32_t fShaderFlags;
const SkShader* fShader;
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp
index f9f9a28..d63abd3 100644
--- a/src/core/SkDraw.cpp
+++ b/src/core/SkDraw.cpp
@@ -15,6 +15,7 @@
#include "SkDeviceLooper.h"
#include "SkFindAndPlaceGlyph.h"
#include "SkFixed.h"
+#include "SkLocalMatrixShader.h"
#include "SkMaskFilter.h"
#include "SkMatrix.h"
#include "SkPaint.h"
@@ -24,7 +25,6 @@
#include "SkRRect.h"
#include "SkScan.h"
#include "SkShader.h"
-#include "SkSmallAllocator.h"
#include "SkString.h"
#include "SkStroke.h"
#include "SkStrokeRec.h"
@@ -1952,13 +1952,21 @@
SkTriColorShader::TriColorShaderData verticesSetup = { vertices, colors, &state };
while (vertProc(&state)) {
+ auto* blitterPtr = blitter.get();
+
+ SkTLazy<SkLocalMatrixShader> localShader;
+ SkTLazy<SkAutoBlitterChoose> localBlitter;
+
if (textures) {
SkMatrix tempM;
if (texture_to_matrix(state, vertices, textures, &tempM)) {
- SkShader::ContextRec rec(p, *fMatrix, &tempM,
- SkBlitter::PreferredShaderDest(fDst.info()),
- fDst.colorSpace());
- if (!blitter->resetShaderContext(rec)) {
+ localShader.init(p.refShader(), tempM);
+
+ SkPaint localPaint(p);
+ localPaint.setShader(sk_ref_sp(localShader.get()));
+
+ blitterPtr = localBlitter.init(fDst, *fMatrix, localPaint)->get();
+ if (blitterPtr->isNullBlitter()) {
continue;
}
}
@@ -1970,8 +1978,8 @@
SkPoint tmp[] = {
devVerts[state.f0], devVerts[state.f1], devVerts[state.f2]
};
- SkScan::FillTriangle(tmp, *fRC, blitter.get());
- triShader->bindSetupData(NULL);
+ SkScan::FillTriangle(tmp, *fRC, blitterPtr);
+ triShader->bindSetupData(nullptr);
}
} else {
// no colors[] and no texture, stroke hairlines with paint's color.