blob: b29dc9c73ee95385beed34198557551a577ae241 [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 Phillipseb35f4d2017-03-21 07:56:47 -040012#include "SkRefCnt.h"
Chris Daltonfe199b72017-05-05 11:26:15 -040013#include "SkTArray.h"
Robert Phillipseb35f4d2017-03-21 07:56:47 -040014
15class GrDrawingManager;
16class GrOpList;
Chris Daltonfe199b72017-05-05 11:26:15 -040017class GrOnFlushResourceProvider;
Robert Phillipseb35f4d2017-03-21 07:56:47 -040018class GrRenderTargetOpList;
19class GrRenderTargetContext;
20class GrSurfaceProxy;
21
22class SkColorSpace;
23class SkSurfaceProps;
24
25/*
Robert Phillipsf5442bb2017-04-17 14:18:34 -040026 * This is the base class from which all pre-flush callback objects must be derived. It
Chris Daltonfe199b72017-05-05 11:26:15 -040027 * provides the "preFlush" / "postFlush" interface.
Robert Phillipseb35f4d2017-03-21 07:56:47 -040028 */
Chris Daltonfe199b72017-05-05 11:26:15 -040029class GrOnFlushCallbackObject {
Robert Phillipseb35f4d2017-03-21 07:56:47 -040030public:
Chris Daltonfe199b72017-05-05 11:26:15 -040031 virtual ~GrOnFlushCallbackObject() { }
Robert Phillipseb35f4d2017-03-21 07:56:47 -040032
33 /*
Chris Daltonfe199b72017-05-05 11:26:15 -040034 * The onFlush callback allows subsystems (e.g., text, path renderers) to create atlases
Robert Phillipseb35f4d2017-03-21 07:56:47 -040035 * for a specific flush. All the GrOpList IDs required for the flush are passed into the
36 * callback. The callback should return the render target contexts used to render the atlases
37 * in 'results'.
38 */
Chris Daltonfe199b72017-05-05 11:26:15 -040039 virtual void preFlush(GrOnFlushResourceProvider*,
Robert Phillipseb35f4d2017-03-21 07:56:47 -040040 const uint32_t* opListIDs, int numOpListIDs,
41 SkTArray<sk_sp<GrRenderTargetContext>>* results) = 0;
42
Chris Daltonfe199b72017-05-05 11:26:15 -040043 /**
44 * Called once flushing is complete and all ops indicated by preFlush have been executed and
45 * released.
46 */
47 virtual void postFlush() {}
48
Robert Phillipseb35f4d2017-03-21 07:56:47 -040049private:
50 typedef SkRefCnt INHERITED;
51};
52
53/*
54 * This class is a shallow wrapper around the drawing manager. It is passed into the
Chris Daltonfe199b72017-05-05 11:26:15 -040055 * onFlush callbacks and is intended to limit the functionality available to them.
Robert Phillipseb35f4d2017-03-21 07:56:47 -040056 * It should never have additional data members or virtual methods.
57 */
Chris Daltonfe199b72017-05-05 11:26:15 -040058class GrOnFlushResourceProvider {
Robert Phillipseb35f4d2017-03-21 07:56:47 -040059public:
60 sk_sp<GrRenderTargetContext> makeRenderTargetContext(const GrSurfaceDesc& desc,
61 sk_sp<SkColorSpace> colorSpace,
62 const SkSurfaceProps* props);
63
64 // TODO: we only need this entry point as long as we have to pre-allocate the atlas.
65 // Remove it ASAP.
66 sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy> proxy,
67 sk_sp<SkColorSpace> colorSpace,
68 const SkSurfaceProps* props);
69
70private:
Chris Daltonfe199b72017-05-05 11:26:15 -040071 explicit GrOnFlushResourceProvider(GrDrawingManager* drawingMgr) : fDrawingMgr(drawingMgr) {}
72 GrOnFlushResourceProvider(const GrOnFlushResourceProvider&) = delete;
73 GrOnFlushResourceProvider& operator=(const GrOnFlushResourceProvider&) = delete;
Robert Phillipseb35f4d2017-03-21 07:56:47 -040074
75 GrDrawingManager* fDrawingMgr;
76
77 friend class GrDrawingManager; // to construct this type.
78};
79
80#endif