1 /* 2 * Copyright 2017 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkAutoBlitterChoose_DEFINED 9 #define SkAutoBlitterChoose_DEFINED 10 11 #include "include/private/SkMacros.h" 12 #include "src/core/SkArenaAlloc.h" 13 #include "src/core/SkBlitter.h" 14 #include "src/core/SkDraw.h" 15 #include "src/core/SkRasterClip.h" 16 17 class SkMatrix; 18 class SkPaint; 19 class SkPixmap; 20 21 class SkAutoBlitterChoose : SkNoncopyable { 22 public: SkAutoBlitterChoose()23 SkAutoBlitterChoose() {} 24 SkAutoBlitterChoose(const SkDraw& draw, const SkMatrixProvider* matrixProvider, 25 const SkPaint& paint, bool drawCoverage = false) { 26 this->choose(draw, matrixProvider, paint, drawCoverage); 27 } 28 29 SkBlitter* operator->() { return fBlitter; } get()30 SkBlitter* get() const { return fBlitter; } 31 32 SkBlitter* choose(const SkDraw& draw, const SkMatrixProvider* matrixProvider, 33 const SkPaint& paint, bool drawCoverage = false) { 34 SkASSERT(!fBlitter); 35 if (!matrixProvider) { 36 matrixProvider = draw.fMatrixProvider; 37 } 38 fBlitter = SkBlitter::Choose(draw.fDst, *matrixProvider, paint, &fAlloc, drawCoverage, 39 draw.fRC->clipShader()); 40 41 if (draw.fCoverage) { 42 // hmm, why can't choose ignore the paint if drawCoverage is true? 43 SkBlitter* coverageBlitter = 44 SkBlitter::Choose(*draw.fCoverage, *matrixProvider, SkPaint(), &fAlloc, true, 45 draw.fRC->clipShader()); 46 fBlitter = fAlloc.make<SkPairBlitter>(fBlitter, coverageBlitter); 47 } 48 return fBlitter; 49 } 50 51 private: 52 // Owned by fAlloc, which will handle the delete. 53 SkBlitter* fBlitter = nullptr; 54 55 SkSTArenaAlloc<kSkBlitterContextSize> fAlloc; 56 }; 57 58 #endif 59