blob: 9cbcddc4f54600320bd4f22fabdea308aa7a67c7 [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
Chris Dalton3968ff92017-11-27 12:26:31 -070011#include "GrDeferredUpload.h"
Jim Van Verth106b5c42017-09-26 12:45:29 -040012#include "GrOpFlushState.h"
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040013#include "GrResourceProvider.h"
Robert Phillipseb35f4d2017-03-21 07:56:47 -040014#include "SkRefCnt.h"
Chris Daltonfe199b72017-05-05 11:26:15 -040015#include "SkTArray.h"
Robert Phillipseb35f4d2017-03-21 07:56:47 -040016
17class GrDrawingManager;
18class GrOpList;
Chris Daltonfe199b72017-05-05 11:26:15 -040019class GrOnFlushResourceProvider;
Robert Phillipseb35f4d2017-03-21 07:56:47 -040020class GrRenderTargetOpList;
21class GrRenderTargetContext;
22class GrSurfaceProxy;
Robert Phillipseb35f4d2017-03-21 07:56:47 -040023class 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:
Brian Salomon238069b2018-07-11 15:58:57 -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
Jim Van Verth106b5c42017-09-26 12:45:29 -040046 * released. startTokenForNextFlush can be used to track resources used in the current flush.
Chris Daltonfe199b72017-05-05 11:26:15 -040047 */
Chris Dalton3968ff92017-11-27 12:26:31 -070048 virtual void postFlush(GrDeferredUploadToken startTokenForNextFlush,
49 const uint32_t* opListIDs, int numOpListIDs) {}
Jim Van Verth106b5c42017-09-26 12:45:29 -040050
51 /**
Jim Van Verth62ea0cd2017-09-27 12:59:45 -040052 * Tells the callback owner to hold onto this object when freeing GPU resources
53 *
54 * In particular, GrDrawingManager::freeGPUResources() deletes all the path renderers.
55 * Any OnFlushCallbackObject associated with a path renderer will need to be deleted.
56 */
Jim Van Verth106b5c42017-09-26 12:45:29 -040057 virtual bool retainOnFreeGpuResources() { return false; }
Robert Phillipseb35f4d2017-03-21 07:56:47 -040058};
59
60/*
61 * This class is a shallow wrapper around the drawing manager. It is passed into the
Chris Daltonfe199b72017-05-05 11:26:15 -040062 * onFlush callbacks and is intended to limit the functionality available to them.
Robert Phillipseb35f4d2017-03-21 07:56:47 -040063 * It should never have additional data members or virtual methods.
64 */
Chris Daltonfe199b72017-05-05 11:26:15 -040065class GrOnFlushResourceProvider {
Robert Phillipseb35f4d2017-03-21 07:56:47 -040066public:
Robert Phillips4bc70112018-03-01 10:24:02 -050067 explicit GrOnFlushResourceProvider(GrDrawingManager* drawingMgr) : fDrawingMgr(drawingMgr) {}
68
Greg Daniel4065d452018-11-16 15:43:41 -050069#if 0
Robert Phillipscd5099c2018-02-09 09:56:56 -050070 sk_sp<GrRenderTargetContext> makeRenderTargetContext(const GrSurfaceDesc&,
Brian Salomon2a4f9832018-03-03 22:43:43 -050071 GrSurfaceOrigin,
Robert Phillipscd5099c2018-02-09 09:56:56 -050072 sk_sp<SkColorSpace>,
73 const SkSurfaceProps*);
Greg Daniel4065d452018-11-16 15:43:41 -050074#endif
Robert Phillipseb35f4d2017-03-21 07:56:47 -040075
Robert Phillipscd5099c2018-02-09 09:56:56 -050076 sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy>,
77 sk_sp<SkColorSpace>,
78 const SkSurfaceProps*);
79
Chris Dalton2de13dd2019-01-03 15:11:59 -070080 // Proxy unique key management. See GrProxyProvider.h.
Chris Dalton50edafa2018-05-17 21:45:25 -060081 bool assignUniqueKeyToProxy(const GrUniqueKey&, GrTextureProxy*);
Chris Dalton2de13dd2019-01-03 15:11:59 -070082 void removeUniqueKeyFromProxy(GrTextureProxy*);
83 void processInvalidUniqueKey(const GrUniqueKey&);
Chris Dalton50edafa2018-05-17 21:45:25 -060084 sk_sp<GrTextureProxy> findOrCreateProxyByUniqueKey(const GrUniqueKey&, GrSurfaceOrigin);
85
Robert Phillipscd5099c2018-02-09 09:56:56 -050086 bool instatiateProxy(GrSurfaceProxy*);
Robert Phillipseb35f4d2017-03-21 07:56:47 -040087
Chris Dalton6081ebb2017-06-20 11:35:59 -070088 // Creates a GPU buffer with a "dynamic" access pattern.
89 sk_sp<GrBuffer> makeBuffer(GrBufferType, size_t, const void* data = nullptr);
90
Chris Daltone9e91dd2017-07-14 08:48:57 -060091 // Either finds and refs, or creates a static GPU buffer with the given data.
Chris Dalton5d2de082017-12-19 10:40:23 -070092 sk_sp<const GrBuffer> findOrMakeStaticBuffer(GrBufferType, size_t, const void* data,
93 const GrUniqueKey&);
Chris Daltone9e91dd2017-07-14 08:48:57 -060094
Brian Salomon238069b2018-07-11 15:58:57 -040095 uint32_t contextUniqueID() const;
Chris Dalton6081ebb2017-06-20 11:35:59 -070096 const GrCaps* caps() const;
97
Robert Phillipseb35f4d2017-03-21 07:56:47 -040098private:
Chris Daltonfe199b72017-05-05 11:26:15 -040099 GrOnFlushResourceProvider(const GrOnFlushResourceProvider&) = delete;
100 GrOnFlushResourceProvider& operator=(const GrOnFlushResourceProvider&) = delete;
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400101
102 GrDrawingManager* fDrawingMgr;
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400103};
104
105#endif