blob: e2c0b730758a0e47a9717722a9f2325bd106d0b1 [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
Chris Daltonfe199b72017-05-05 11:26:15 -04008#ifndef GrOnFlushResourceProvider_DEFINED
9#define GrOnFlushResourceProvider_DEFINED
Robert Phillipseb35f4d2017-03-21 07:56:47 -040010
11#include "GrTypes.h"
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040012#include "GrResourceProvider.h"
Robert Phillipseb35f4d2017-03-21 07:56:47 -040013#include "SkRefCnt.h"
Chris Daltonfe199b72017-05-05 11:26:15 -040014#include "SkTArray.h"
Robert Phillipseb35f4d2017-03-21 07:56:47 -040015
16class GrDrawingManager;
17class GrOpList;
Chris Daltonfe199b72017-05-05 11:26:15 -040018class GrOnFlushResourceProvider;
Robert Phillipseb35f4d2017-03-21 07:56:47 -040019class GrRenderTargetOpList;
20class GrRenderTargetContext;
21class GrSurfaceProxy;
22
23class SkColorSpace;
24class SkSurfaceProps;
25
26/*
Robert Phillipsf5442bb2017-04-17 14:18:34 -040027 * This is the base class from which all pre-flush callback objects must be derived. It
Chris Daltonfe199b72017-05-05 11:26:15 -040028 * provides the "preFlush" / "postFlush" interface.
Robert Phillipseb35f4d2017-03-21 07:56:47 -040029 */
Chris Daltonfe199b72017-05-05 11:26:15 -040030class GrOnFlushCallbackObject {
Robert Phillipseb35f4d2017-03-21 07:56:47 -040031public:
Chris Daltonfe199b72017-05-05 11:26:15 -040032 virtual ~GrOnFlushCallbackObject() { }
Robert Phillipseb35f4d2017-03-21 07:56:47 -040033
34 /*
Chris Daltonfe199b72017-05-05 11:26:15 -040035 * The onFlush callback allows subsystems (e.g., text, path renderers) to create atlases
Robert Phillipseb35f4d2017-03-21 07:56:47 -040036 * for a specific flush. All the GrOpList IDs required for the flush are passed into the
37 * callback. The callback should return the render target contexts used to render the atlases
38 * in 'results'.
39 */
Chris Daltonfe199b72017-05-05 11:26:15 -040040 virtual void preFlush(GrOnFlushResourceProvider*,
Robert Phillipseb35f4d2017-03-21 07:56:47 -040041 const uint32_t* opListIDs, int numOpListIDs,
42 SkTArray<sk_sp<GrRenderTargetContext>>* results) = 0;
43
Chris Daltonfe199b72017-05-05 11:26:15 -040044 /**
45 * Called once flushing is complete and all ops indicated by preFlush have been executed and
46 * released.
47 */
48 virtual void postFlush() {}
49
Robert Phillipseb35f4d2017-03-21 07:56:47 -040050private:
51 typedef SkRefCnt INHERITED;
52};
53
54/*
55 * This class is a shallow wrapper around the drawing manager. It is passed into the
Chris Daltonfe199b72017-05-05 11:26:15 -040056 * onFlush callbacks and is intended to limit the functionality available to them.
Robert Phillipseb35f4d2017-03-21 07:56:47 -040057 * It should never have additional data members or virtual methods.
58 */
Chris Daltonfe199b72017-05-05 11:26:15 -040059class GrOnFlushResourceProvider {
Robert Phillipseb35f4d2017-03-21 07:56:47 -040060public:
61 sk_sp<GrRenderTargetContext> makeRenderTargetContext(const GrSurfaceDesc& desc,
62 sk_sp<SkColorSpace> colorSpace,
63 const SkSurfaceProps* props);
64
65 // TODO: we only need this entry point as long as we have to pre-allocate the atlas.
66 // Remove it ASAP.
67 sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy> proxy,
68 sk_sp<SkColorSpace> colorSpace,
69 const SkSurfaceProps* props);
70
Chris Dalton6081ebb2017-06-20 11:35:59 -070071 // Creates a GPU buffer with a "dynamic" access pattern.
72 sk_sp<GrBuffer> makeBuffer(GrBufferType, size_t, const void* data = nullptr);
73
Chris Daltone9e91dd2017-07-14 08:48:57 -060074 // Either finds and refs, or creates a static GPU buffer with the given data.
75 sk_sp<GrBuffer> findOrMakeStaticBuffer(const GrUniqueKey&, GrBufferType,
76 size_t, const void* data);
77
Chris Dalton6081ebb2017-06-20 11:35:59 -070078 const GrCaps* caps() const;
79
Robert Phillipseb35f4d2017-03-21 07:56:47 -040080private:
Chris Daltonfe199b72017-05-05 11:26:15 -040081 explicit GrOnFlushResourceProvider(GrDrawingManager* drawingMgr) : fDrawingMgr(drawingMgr) {}
82 GrOnFlushResourceProvider(const GrOnFlushResourceProvider&) = delete;
83 GrOnFlushResourceProvider& operator=(const GrOnFlushResourceProvider&) = delete;
Robert Phillipseb35f4d2017-03-21 07:56:47 -040084
85 GrDrawingManager* fDrawingMgr;
86
87 friend class GrDrawingManager; // to construct this type.
88};
89
90#endif