1 | /* |
2 | * Copyright 2014 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 GrSmallPathRenderer_DEFINED |
9 | #define GrSmallPathRenderer_DEFINED |
10 | |
11 | #include "src/gpu/GrDrawOpAtlas.h" |
12 | #include "src/gpu/GrOnFlushResourceProvider.h" |
13 | #include "src/gpu/GrPathRenderer.h" |
14 | #include "src/gpu/geometry/GrRect.h" |
15 | #include "src/gpu/geometry/GrShape.h" |
16 | |
17 | #include "src/core/SkOpts.h" |
18 | #include "src/core/SkTDynamicHash.h" |
19 | |
20 | class GrRecordingContext; |
21 | |
22 | class ShapeData; |
23 | class ShapeDataKey; |
24 | |
25 | class GrSmallPathRenderer : public GrPathRenderer, |
26 | public GrOnFlushCallbackObject, |
27 | public GrDrawOpAtlas::EvictionCallback, |
28 | public GrDrawOpAtlas::GenerationCounter { |
29 | public: |
30 | GrSmallPathRenderer(); |
31 | ~GrSmallPathRenderer() override; |
32 | |
33 | // GrOnFlushCallbackObject overrides |
34 | // |
35 | // Note: because this class is associated with a path renderer we want it to be removed from |
36 | // the list of active OnFlushBackkbackObjects in an freeGpuResources call (i.e., we accept the |
37 | // default retainOnFreeGpuResources implementation). |
38 | |
39 | void preFlush(GrOnFlushResourceProvider* onFlushRP, const uint32_t*, int) override { |
40 | if (fAtlas) { |
41 | fAtlas->instantiate(onFlushRP); |
42 | } |
43 | } |
44 | |
45 | void postFlush(GrDeferredUploadToken startTokenForNextFlush, |
46 | const uint32_t* /*opsTaskIDs*/, int /*numOpsTaskIDs*/) override { |
47 | if (fAtlas) { |
48 | fAtlas->compact(startTokenForNextFlush); |
49 | } |
50 | } |
51 | |
52 | using ShapeCache = SkTDynamicHash<ShapeData, ShapeDataKey>; |
53 | typedef SkTInternalLList<ShapeData> ShapeDataList; |
54 | |
55 | static std::unique_ptr<GrDrawOp> createOp_TestingOnly(GrRecordingContext*, |
56 | GrPaint&&, |
57 | const GrShape&, |
58 | const SkMatrix& viewMatrix, |
59 | GrDrawOpAtlas* atlas, |
60 | ShapeCache*, |
61 | ShapeDataList*, |
62 | bool gammaCorrect, |
63 | const GrUserStencilSettings*); |
64 | struct PathTestStruct; |
65 | |
66 | private: |
67 | class SmallPathOp; |
68 | |
69 | StencilSupport onGetStencilSupport(const GrShape&) const override { |
70 | return GrPathRenderer::kNoSupport_StencilSupport; |
71 | } |
72 | |
73 | CanDrawPath onCanDrawPath(const CanDrawPathArgs&) const override; |
74 | |
75 | bool onDrawPath(const DrawPathArgs&) override; |
76 | |
77 | void evict(GrDrawOpAtlas::PlotLocator) override; |
78 | |
79 | std::unique_ptr<GrDrawOpAtlas> fAtlas; |
80 | ShapeCache fShapeCache; |
81 | ShapeDataList fShapeList; |
82 | |
83 | typedef GrPathRenderer INHERITED; |
84 | }; |
85 | |
86 | #endif |
87 | |