• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/SkDraw.h"
15 #include "src/core/SkMatrixProvider.h"
16 #include "src/core/SkRasterClip.h"
17 #include "src/core/SkSurfacePriv.h"
18 
19 class SkMatrix;
20 class SkPaint;
21 class SkPixmap;
22 
23 class SkAutoBlitterChoose : SkNoncopyable {
24 public:
SkAutoBlitterChoose()25     SkAutoBlitterChoose() {}
26     SkAutoBlitterChoose(const SkDraw& draw, const SkMatrixProvider* matrixProvider,
27                         const SkPaint& paint, bool drawCoverage = false) {
28         this->choose(draw, matrixProvider, paint, drawCoverage);
29     }
30 
31     SkBlitter*  operator->() { return fBlitter; }
get()32     SkBlitter*  get() const { return fBlitter; }
33 
34     SkBlitter* choose(const SkDraw& draw, const SkMatrixProvider* matrixProvider,
35                       const SkPaint& paint, bool drawCoverage = false) {
36         SkASSERT(!fBlitter);
37         if (!matrixProvider) {
38             matrixProvider = draw.fMatrixProvider;
39         }
40         fBlitter = SkBlitter::Choose(draw.fDst,
41                                      matrixProvider->localToDevice(),
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     SkSTArenaAlloc<kSkBlitterContextSize> fAlloc;
55 };
56 
57 #endif
58