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 "SkArenaAlloc.h" 12 #include "SkBlitter.h" 13 14 class SkMatrix; 15 class SkPaint; 16 class SkPixmap; 17 18 class SkAutoBlitterChoose : SkNoncopyable { 19 public: SkAutoBlitterChoose()20 SkAutoBlitterChoose() { 21 fBlitter = nullptr; 22 } 23 SkAutoBlitterChoose(const SkPixmap& dst, const SkMatrix& matrix, 24 const SkPaint& paint, bool drawCoverage = false) { 25 fBlitter = SkBlitter::Choose(dst, matrix, paint, &fAlloc, drawCoverage); 26 } 27 28 SkBlitter* operator->() { return fBlitter; } get()29 SkBlitter* get() const { return fBlitter; } 30 31 void choose(const SkPixmap& dst, const SkMatrix& matrix, 32 const SkPaint& paint, bool drawCoverage = false) { 33 SkASSERT(!fBlitter); 34 fBlitter = SkBlitter::Choose(dst, matrix, paint, &fAlloc, drawCoverage); 35 } 36 37 private: 38 // Owned by fAlloc, which will handle the delete. 39 SkBlitter* fBlitter; 40 41 SkSTArenaAlloc<kSkBlitterContextSize> fAlloc; 42 }; 43 #define SkAutoBlitterChoose(...) SK_REQUIRE_LOCAL_VAR(SkAutoBlitterChoose) 44 45 #endif 46