Remove SkBlitter:resetShaderContext()
authorFlorin Malita <fmalita@chromium.org>
Fri, 27 Jan 2017 17:05:27 +0000 (12:05 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Fri, 27 Jan 2017 17:48:08 +0000 (17:48 +0000)
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>

src/core/SkBlitter.cpp
src/core/SkBlitter.h
src/core/SkCoreBlitters.h
src/core/SkDraw.cpp

index d3c60b7..d8e3dfd 100644 (file)
@@ -25,10 +25,6 @@ SkBlitter::~SkBlitter() {}
 
 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 @@ SkShaderBlitter::~SkShaderBlitter() {
     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
index ac4712e..cab2afc 100644 (file)
@@ -108,11 +108,6 @@ public:
     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
index 3ff1e1d..62bf73e 100644 (file)
@@ -37,13 +37,6 @@ public:
                     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;
index f9f9a28..d63abd3 100644 (file)
@@ -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 @@ void SkDraw::drawVertices(SkCanvas::VertexMode vmode, int count,
         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 @@ void SkDraw::drawVertices(SkCanvas::VertexMode vmode, int count,
             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.