Debian Codegraph @

src/core/SkAutoBlitterChoose.h

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