blob: 40a8afdc6916491b0bf0baa1f0a937481ad2ae77 [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;
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
Robert Phillipscd5099c2018-02-09 09:56:56 -050069 sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy>,
Brian Salomond6287472019-06-24 15:50:07 -040070 GrColorType,
Robert Phillipscd5099c2018-02-09 09:56:56 -050071 sk_sp<SkColorSpace>,
72 const SkSurfaceProps*);
73
Chris Dalton2de13dd2019-01-03 15:11:59 -070074 // Proxy unique key management. See GrProxyProvider.h.
Chris Dalton50edafa2018-05-17 21:45:25 -060075 bool assignUniqueKeyToProxy(const GrUniqueKey&, GrTextureProxy*);
Chris Dalton2de13dd2019-01-03 15:11:59 -070076 void removeUniqueKeyFromProxy(GrTextureProxy*);
77 void processInvalidUniqueKey(const GrUniqueKey&);
Brian Salomon2af3e702019-08-11 19:10:31 -040078 // GrColorType is necessary to set the proxy's texture swizzle.
79 sk_sp<GrTextureProxy> findOrCreateProxyByUniqueKey(const GrUniqueKey&, GrColorType,
80 GrSurfaceOrigin);
Chris Dalton50edafa2018-05-17 21:45:25 -060081
Robert Phillipscd5099c2018-02-09 09:56:56 -050082 bool instatiateProxy(GrSurfaceProxy*);
Robert Phillipseb35f4d2017-03-21 07:56:47 -040083
Chris Dalton6081ebb2017-06-20 11:35:59 -070084 // Creates a GPU buffer with a "dynamic" access pattern.
Brian Salomondbf70722019-02-07 11:31:24 -050085 sk_sp<GrGpuBuffer> makeBuffer(GrGpuBufferType, size_t, const void* data = nullptr);
Chris Dalton6081ebb2017-06-20 11:35:59 -070086
Chris Daltone9e91dd2017-07-14 08:48:57 -060087 // Either finds and refs, or creates a static GPU buffer with the given data.
Brian Salomondbf70722019-02-07 11:31:24 -050088 sk_sp<const GrGpuBuffer> findOrMakeStaticBuffer(GrGpuBufferType, size_t, const void* data,
89 const GrUniqueKey&);
Chris Daltone9e91dd2017-07-14 08:48:57 -060090
Robert Phillipsfd0d9702019-02-01 10:19:42 -050091 uint32_t contextID() const;
Chris Dalton6081ebb2017-06-20 11:35:59 -070092 const GrCaps* caps() const;
93
Robert Phillipseb35f4d2017-03-21 07:56:47 -040094private:
Chris Daltonfe199b72017-05-05 11:26:15 -040095 GrOnFlushResourceProvider(const GrOnFlushResourceProvider&) = delete;
96 GrOnFlushResourceProvider& operator=(const GrOnFlushResourceProvider&) = delete;
Robert Phillipseb35f4d2017-03-21 07:56:47 -040097
98 GrDrawingManager* fDrawingMgr;
Robert Phillipseb35f4d2017-03-21 07:56:47 -040099};
100
101#endif