blob: 86a299a4229930cf0a4e08f37cddf0933c5a1076 [file] [log] [blame]
Robert Phillipseb35f4d2017-03-21 07:56:47 -04001/*
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
18class GrDrawingManager;
19class GrOpList;
20class GrPreFlushResourceProvider;
21class GrRenderTargetOpList;
22class GrRenderTargetContext;
23class GrSurfaceProxy;
24
25class SkColorSpace;
26class 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 */
32class GrPreFlushCallbackObject : public GrNonAtomicRef<GrPreFlushCallbackObject> {
33public:
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
46private:
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 */
55class GrPreFlushResourceProvider {
56public:
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
67private:
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