• 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 GrPreFlushResourceProvider_DEFINED
9 #define GrPreFlushResourceProvider_DEFINED
10 
11 #include "GrTypes.h"
12 #include "GrNonAtomicRef.h"
13 
14 // These two are just for GrPreFlushCallbackObject
15 #include "SkRefCnt.h"
16 #include "SkTDArray.h"
17 
18 class GrDrawingManager;
19 class GrOpList;
20 class GrPreFlushResourceProvider;
21 class GrRenderTargetOpList;
22 class GrRenderTargetContext;
23 class GrSurfaceProxy;
24 
25 class SkColorSpace;
26 class SkSurfaceProps;
27 
28 /*
29  * This is the base class from which all per-flush callback objects must be derived. It
30  * provides the "preFlush" interface.
31  */
32 class GrPreFlushCallbackObject : public GrNonAtomicRef<GrPreFlushCallbackObject> {
33 public:
~GrPreFlushCallbackObject()34     virtual ~GrPreFlushCallbackObject() { }
35 
36     /*
37      * The preFlush callback allows subsystems (e.g., text, path renderers) to create atlases
38      * for a specific flush. All the GrOpList IDs required for the flush are passed into the
39      * callback. The callback should return the render target contexts used to render the atlases
40      * in 'results'.
41      */
42     virtual void preFlush(GrPreFlushResourceProvider*,
43                           const uint32_t* opListIDs, int numOpListIDs,
44                           SkTArray<sk_sp<GrRenderTargetContext>>* results) = 0;
45 
46 private:
47     typedef SkRefCnt INHERITED;
48 };
49 
50 /*
51  * This class is a shallow wrapper around the drawing manager. It is passed into the
52  * preFlush callbacks and is intended to limit the functionality available to them.
53  * It should never have additional data members or virtual methods.
54  */
55 class GrPreFlushResourceProvider {
56 public:
57     sk_sp<GrRenderTargetContext> makeRenderTargetContext(const GrSurfaceDesc& desc,
58                                                          sk_sp<SkColorSpace> colorSpace,
59                                                          const SkSurfaceProps* props);
60 
61     // TODO: we only need this entry point as long as we have to pre-allocate the atlas.
62     // Remove it ASAP.
63     sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy> proxy,
64                                                          sk_sp<SkColorSpace> colorSpace,
65                                                          const SkSurfaceProps* props);
66 
67 private:
GrPreFlushResourceProvider(GrDrawingManager * drawingMgr)68     explicit GrPreFlushResourceProvider(GrDrawingManager* drawingMgr) : fDrawingMgr(drawingMgr) {}
69     GrPreFlushResourceProvider(const GrPreFlushResourceProvider&); // unimpl
70     GrPreFlushResourceProvider& operator=(const GrPreFlushResourceProvider&); // unimpl
71 
72     GrDrawingManager* fDrawingMgr;
73 
74     friend class GrDrawingManager; // to construct this type.
75 };
76 
77 #endif
78