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/base/SkMacros.h" 12 #include "src/base/SkArenaAlloc.h" 13 #include "src/core/SkBlitter.h" 14 #include "src/core/SkDrawBase.h" 15 #include "src/core/SkRasterClip.h" 16 #include "src/core/SkSurfacePriv.h" 17 18 class SkMatrix; 19 class SkPaint; 20 class SkPixmap; 21 22 class SkAutoBlitterChoose : SkNoncopyable { 23 public: SkAutoBlitterChoose()24 SkAutoBlitterChoose() {} 25 SkAutoBlitterChoose(const SkDrawBase& draw, 26 const SkMatrix* ctm, 27 const SkPaint& paint, 28 SkDrawCoverage drawCoverage = SkDrawCoverage::kNo) { 29 this->choose(draw, ctm, paint, drawCoverage); 30 } 31 32 SkBlitter* operator->() { return fBlitter; } get()33 SkBlitter* get() const { return fBlitter; } 34 35 SkBlitter* choose(const SkDrawBase& draw, 36 const SkMatrix* ctm, 37 const SkPaint& paint, 38 SkDrawCoverage drawCoverage = SkDrawCoverage::kNo) { 39 SkASSERT(!fBlitter); 40 fBlitter = draw.fBlitterChooser(draw.fDst, 41 ctm ? *ctm : *draw.fCTM, 42 paint, 43 &fAlloc, 44 drawCoverage, 45 draw.fRC->clipShader(), 46 SkSurfacePropsCopyOrDefault(draw.fProps)); 47 return fBlitter; 48 } 49 50 private: 51 // Owned by fAlloc, which will handle the delete. 52 SkBlitter* fBlitter = nullptr; 53 54 // This was determined experimentally by adding logging to SkSTArenaAlloc's destructor 55 // to see what the biggest size observed was while doing some browsing on Chromium. 56 // It's a bit tricky to determine this value statically, as the SkRasterPipelineBuilder 57 // uses the allocator for several things, as do the shaders which make use of the legacy 58 // shader context. In other cases it's easier because the allocator only has the blitter 59 // itself and one could do a static_assert using sizeof(). 60 static constexpr size_t kStackMemory = 2736; 61 SkSTArenaAlloc<kStackMemory> fAlloc; 62 }; 63 64 #endif 65