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