blob: 0583dbc99a65282564040d1c48f7f95c5d210f60 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkRefCnt.h"
12#include "include/private/SkTArray.h"
13#include "src/gpu/GrDeferredUpload.h"
14#include "src/gpu/GrOpFlushState.h"
15#include "src/gpu/GrResourceProvider.h"
Robert Phillipseb35f4d2017-03-21 07:56:47 -040016
17class GrDrawingManager;
Chris Daltonfe199b72017-05-05 11:26:15 -040018class GrOnFlushResourceProvider;
Robert Phillipseb35f4d2017-03-21 07:56:47 -040019class GrRenderTargetContext;
20class GrSurfaceProxy;
Robert Phillipseb35f4d2017-03-21 07:56:47 -040021class SkColorSpace;
22class SkSurfaceProps;
23
24/*
Robert Phillipsf5442bb2017-04-17 14:18:34 -040025 * This is the base class from which all pre-flush callback objects must be derived. It
Chris Daltonfe199b72017-05-05 11:26:15 -040026 * provides the "preFlush" / "postFlush" interface.
Robert Phillipseb35f4d2017-03-21 07:56:47 -040027 */
Chris Daltonfe199b72017-05-05 11:26:15 -040028class GrOnFlushCallbackObject {
Robert Phillipseb35f4d2017-03-21 07:56:47 -040029public:
Brian Salomon238069b2018-07-11 15:58:57 -040030 virtual ~GrOnFlushCallbackObject() {}
Robert Phillipseb35f4d2017-03-21 07:56:47 -040031
32 /*
Chris Daltonfe199b72017-05-05 11:26:15 -040033 * The onFlush callback allows subsystems (e.g., text, path renderers) to create atlases
Greg Danielf41b2bd2019-08-22 16:19:24 -040034 * for a specific flush. All the GrOpsTask IDs required for the flush are passed into the
Robert Phillipseb35f4d2017-03-21 07:56:47 -040035 * callback. The callback should return the render target contexts used to render the atlases
36 * in 'results'.
37 */
Chris Daltonc4b47352019-08-23 10:10:36 -060038 virtual void preFlush(GrOnFlushResourceProvider*, const uint32_t* opsTaskIDs,
39 int numOpsTaskIDs) = 0;
Robert Phillipseb35f4d2017-03-21 07:56:47 -040040
Chris Daltonfe199b72017-05-05 11:26:15 -040041 /**
42 * Called once flushing is complete and all ops indicated by preFlush have been executed and
Jim Van Verth106b5c42017-09-26 12:45:29 -040043 * released. startTokenForNextFlush can be used to track resources used in the current flush.
Chris Daltonfe199b72017-05-05 11:26:15 -040044 */
Chris Dalton3968ff92017-11-27 12:26:31 -070045 virtual void postFlush(GrDeferredUploadToken startTokenForNextFlush,
Greg Danielf41b2bd2019-08-22 16:19:24 -040046 const uint32_t* opsTaskIDs, int numOpsTaskIDs) {}
Jim Van Verth106b5c42017-09-26 12:45:29 -040047
48 /**
Jim Van Verth62ea0cd2017-09-27 12:59:45 -040049 * Tells the callback owner to hold onto this object when freeing GPU resources
50 *
51 * In particular, GrDrawingManager::freeGPUResources() deletes all the path renderers.
52 * Any OnFlushCallbackObject associated with a path renderer will need to be deleted.
53 */
Jim Van Verth106b5c42017-09-26 12:45:29 -040054 virtual bool retainOnFreeGpuResources() { return false; }
Robert Phillipseb35f4d2017-03-21 07:56:47 -040055};
56
57/*
58 * This class is a shallow wrapper around the drawing manager. It is passed into the
Chris Daltonfe199b72017-05-05 11:26:15 -040059 * onFlush callbacks and is intended to limit the functionality available to them.
Robert Phillipseb35f4d2017-03-21 07:56:47 -040060 * It should never have additional data members or virtual methods.
61 */
Chris Daltonfe199b72017-05-05 11:26:15 -040062class GrOnFlushResourceProvider {
Robert Phillipseb35f4d2017-03-21 07:56:47 -040063public:
Brian Salomonbeb7f522019-08-30 16:19:42 -040064 using UseAllocator = GrSurfaceProxy::UseAllocator;
65
Robert Phillips4bc70112018-03-01 10:24:02 -050066 explicit GrOnFlushResourceProvider(GrDrawingManager* drawingMgr) : fDrawingMgr(drawingMgr) {}
67
Greg Danield11ae2e2020-02-10 16:36:07 -050068 std::unique_ptr<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy>,
69 GrSurfaceOrigin, GrColorType,
70 sk_sp<SkColorSpace>,
71 const SkSurfaceProps*);
Chris Dalton4ece96d2019-08-30 11:26:39 -060072
73 void addTextureResolveTask(sk_sp<GrTextureProxy>, GrSurfaceProxy::ResolveFlags);
Robert Phillipscd5099c2018-02-09 09:56:56 -050074
Chris Dalton2de13dd2019-01-03 15:11:59 -070075 // Proxy unique key management. See GrProxyProvider.h.
Chris Dalton50edafa2018-05-17 21:45:25 -060076 bool assignUniqueKeyToProxy(const GrUniqueKey&, GrTextureProxy*);
Chris Dalton2de13dd2019-01-03 15:11:59 -070077 void removeUniqueKeyFromProxy(GrTextureProxy*);
78 void processInvalidUniqueKey(const GrUniqueKey&);
Brian Salomondf1bd6d2020-03-26 20:37:01 -040079 sk_sp<GrTextureProxy> findOrCreateProxyByUniqueKey(const GrUniqueKey&, UseAllocator);
Chris Dalton50edafa2018-05-17 21:45:25 -060080
Robert Phillipscd5099c2018-02-09 09:56:56 -050081 bool instatiateProxy(GrSurfaceProxy*);
Robert Phillipseb35f4d2017-03-21 07:56:47 -040082
Chris Dalton6081ebb2017-06-20 11:35:59 -070083 // Creates a GPU buffer with a "dynamic" access pattern.
Brian Salomondbf70722019-02-07 11:31:24 -050084 sk_sp<GrGpuBuffer> makeBuffer(GrGpuBufferType, size_t, const void* data = nullptr);
Chris Dalton6081ebb2017-06-20 11:35:59 -070085
Chris Daltone9e91dd2017-07-14 08:48:57 -060086 // Either finds and refs, or creates a static GPU buffer with the given data.
Brian Salomondbf70722019-02-07 11:31:24 -050087 sk_sp<const GrGpuBuffer> findOrMakeStaticBuffer(GrGpuBufferType, size_t, const void* data,
88 const GrUniqueKey&);
Chris Daltone9e91dd2017-07-14 08:48:57 -060089
Robert Phillipsfd0d9702019-02-01 10:19:42 -050090 uint32_t contextID() const;
Chris Dalton6081ebb2017-06-20 11:35:59 -070091 const GrCaps* caps() const;
Chris Dalton4e998532020-02-10 11:06:42 -070092 GrOpMemoryPool* opMemoryPool() const;
Chris Dalton6081ebb2017-06-20 11:35:59 -070093
Chris Dalton5a5fe792020-02-15 11:41:30 -070094 void printWarningMessage(const char* msg) const;
Chris Daltona378b452019-12-11 13:24:11 -050095
Robert Phillipseb35f4d2017-03-21 07:56:47 -040096private:
Chris Daltonfe199b72017-05-05 11:26:15 -040097 GrOnFlushResourceProvider(const GrOnFlushResourceProvider&) = delete;
98 GrOnFlushResourceProvider& operator=(const GrOnFlushResourceProvider&) = delete;
Robert Phillipseb35f4d2017-03-21 07:56:47 -040099
100 GrDrawingManager* fDrawingMgr;
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400101};
102
103#endif