blob: 75b9b0c2b16b40724abb4365c67f2685df4ab991 [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"
Chris Dalton3968ff92017-11-27 12:26:31 -070012#include "GrDeferredUpload.h"
Jim Van Verth106b5c42017-09-26 12:45:29 -040013#include "GrOpFlushState.h"
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040014#include "GrResourceProvider.h"
Robert Phillipseb35f4d2017-03-21 07:56:47 -040015#include "SkRefCnt.h"
Chris Daltonfe199b72017-05-05 11:26:15 -040016#include "SkTArray.h"
Robert Phillipseb35f4d2017-03-21 07:56:47 -040017
18class GrDrawingManager;
19class GrOpList;
Chris Daltonfe199b72017-05-05 11:26:15 -040020class GrOnFlushResourceProvider;
Robert Phillipseb35f4d2017-03-21 07:56:47 -040021class GrRenderTargetOpList;
22class GrRenderTargetContext;
23class GrSurfaceProxy;
24
25class SkColorSpace;
26class SkSurfaceProps;
27
28/*
Robert Phillipsf5442bb2017-04-17 14:18:34 -040029 * This is the base class from which all pre-flush callback objects must be derived. It
Chris Daltonfe199b72017-05-05 11:26:15 -040030 * provides the "preFlush" / "postFlush" interface.
Robert Phillipseb35f4d2017-03-21 07:56:47 -040031 */
Chris Daltonfe199b72017-05-05 11:26:15 -040032class GrOnFlushCallbackObject {
Robert Phillipseb35f4d2017-03-21 07:56:47 -040033public:
Chris Daltonfe199b72017-05-05 11:26:15 -040034 virtual ~GrOnFlushCallbackObject() { }
Robert Phillipseb35f4d2017-03-21 07:56:47 -040035
36 /*
Chris Daltonfe199b72017-05-05 11:26:15 -040037 * The onFlush callback allows subsystems (e.g., text, path renderers) to create atlases
Robert Phillipseb35f4d2017-03-21 07:56:47 -040038 * 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 */
Chris Daltonfe199b72017-05-05 11:26:15 -040042 virtual void preFlush(GrOnFlushResourceProvider*,
Robert Phillipseb35f4d2017-03-21 07:56:47 -040043 const uint32_t* opListIDs, int numOpListIDs,
44 SkTArray<sk_sp<GrRenderTargetContext>>* results) = 0;
45
Chris Daltonfe199b72017-05-05 11:26:15 -040046 /**
47 * Called once flushing is complete and all ops indicated by preFlush have been executed and
Jim Van Verth106b5c42017-09-26 12:45:29 -040048 * released. startTokenForNextFlush can be used to track resources used in the current flush.
Chris Daltonfe199b72017-05-05 11:26:15 -040049 */
Chris Dalton3968ff92017-11-27 12:26:31 -070050 virtual void postFlush(GrDeferredUploadToken startTokenForNextFlush,
51 const uint32_t* opListIDs, int numOpListIDs) {}
Jim Van Verth106b5c42017-09-26 12:45:29 -040052
53 /**
Jim Van Verth62ea0cd2017-09-27 12:59:45 -040054 * Tells the callback owner to hold onto this object when freeing GPU resources
55 *
56 * In particular, GrDrawingManager::freeGPUResources() deletes all the path renderers.
57 * Any OnFlushCallbackObject associated with a path renderer will need to be deleted.
58 */
Jim Van Verth106b5c42017-09-26 12:45:29 -040059 virtual bool retainOnFreeGpuResources() { return false; }
Robert Phillipseb35f4d2017-03-21 07:56:47 -040060};
61
62/*
63 * This class is a shallow wrapper around the drawing manager. It is passed into the
Chris Daltonfe199b72017-05-05 11:26:15 -040064 * onFlush callbacks and is intended to limit the functionality available to them.
Robert Phillipseb35f4d2017-03-21 07:56:47 -040065 * It should never have additional data members or virtual methods.
66 */
Chris Daltonfe199b72017-05-05 11:26:15 -040067class GrOnFlushResourceProvider {
Robert Phillipseb35f4d2017-03-21 07:56:47 -040068public:
Robert Phillips4bc70112018-03-01 10:24:02 -050069 explicit GrOnFlushResourceProvider(GrDrawingManager* drawingMgr) : fDrawingMgr(drawingMgr) {}
70
Robert Phillipscd5099c2018-02-09 09:56:56 -050071 sk_sp<GrRenderTargetContext> makeRenderTargetContext(const GrSurfaceDesc&,
72 sk_sp<SkColorSpace>,
73 const SkSurfaceProps*);
Robert Phillipseb35f4d2017-03-21 07:56:47 -040074
Robert Phillipscd5099c2018-02-09 09:56:56 -050075 sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy>,
76 sk_sp<SkColorSpace>,
77 const SkSurfaceProps*);
78
79 bool instatiateProxy(GrSurfaceProxy*);
Robert Phillipseb35f4d2017-03-21 07:56:47 -040080
Chris Dalton6081ebb2017-06-20 11:35:59 -070081 // Creates a GPU buffer with a "dynamic" access pattern.
82 sk_sp<GrBuffer> makeBuffer(GrBufferType, size_t, const void* data = nullptr);
83
Chris Daltone9e91dd2017-07-14 08:48:57 -060084 // Either finds and refs, or creates a static GPU buffer with the given data.
Chris Dalton5d2de082017-12-19 10:40:23 -070085 sk_sp<const GrBuffer> findOrMakeStaticBuffer(GrBufferType, size_t, const void* data,
86 const GrUniqueKey&);
Chris Daltone9e91dd2017-07-14 08:48:57 -060087
Chris Dalton6081ebb2017-06-20 11:35:59 -070088 const GrCaps* caps() const;
89
Robert Phillipseb35f4d2017-03-21 07:56:47 -040090private:
Chris Daltonfe199b72017-05-05 11:26:15 -040091 GrOnFlushResourceProvider(const GrOnFlushResourceProvider&) = delete;
92 GrOnFlushResourceProvider& operator=(const GrOnFlushResourceProvider&) = delete;
Robert Phillipseb35f4d2017-03-21 07:56:47 -040093
94 GrDrawingManager* fDrawingMgr;
Robert Phillipseb35f4d2017-03-21 07:56:47 -040095};
96
97#endif