1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
|
/*
* Copyright 2019 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrRecordingContext_DEFINED
#define GrRecordingContext_DEFINED
#include "include/core/SkRefCnt.h"
#include "include/private/GrImageContext.h"
#include "include/private/SkTArray.h"
#if GR_GPU_STATS && GR_TEST_UTILS
#include <map>
#include <string>
#endif
class GrAuditTrail;
class GrBackendFormat;
class GrDrawingManager;
class GrOnFlushCallbackObject;
class GrMemoryPool;
class GrProgramDesc;
class GrProgramInfo;
class GrProxyProvider;
class GrRecordingContextPriv;
class GrSubRunAllocator;
class GrSurfaceProxy;
class GrTextBlobRedrawCoordinator;
class GrThreadSafeCache;
class SkArenaAlloc;
class SkJSONWriter;
#if GR_TEST_UTILS
class SkString;
#endif
class GrRecordingContext : public GrImageContext {
public:
~GrRecordingContext() override;
SK_API GrBackendFormat defaultBackendFormat(SkColorType ct, GrRenderable renderable) const {
return INHERITED::defaultBackendFormat(ct, renderable);
}
/**
* Reports whether the GrDirectContext associated with this GrRecordingContext is abandoned.
* When called on a GrDirectContext it may actively check whether the underlying 3D API
* device/context has been disconnected before reporting the status. If so, calling this
* method will transition the GrDirectContext to the abandoned state.
*/
bool abandoned() override { return INHERITED::abandoned(); }
/*
* Can a SkSurface be created with the given color type. To check whether MSAA is supported
* use maxSurfaceSampleCountForColorType().
*/
SK_API bool colorTypeSupportedAsSurface(SkColorType colorType) const {
if (kR16G16_unorm_SkColorType == colorType ||
kA16_unorm_SkColorType == colorType ||
kA16_float_SkColorType == colorType ||
kR16G16_float_SkColorType == colorType ||
kR16G16B16A16_unorm_SkColorType == colorType ||
kGray_8_SkColorType == colorType) {
return false;
}
return this->maxSurfaceSampleCountForColorType(colorType) > 0;
}
/**
* Gets the maximum supported texture size.
*/
SK_API int maxTextureSize() const;
/**
* Gets the maximum supported render target size.
*/
SK_API int maxRenderTargetSize() const;
/**
* Can a SkImage be created with the given color type.
*/
SK_API bool colorTypeSupportedAsImage(SkColorType) const;
/**
* Gets the maximum supported sample count for a color type. 1 is returned if only non-MSAA
* rendering is supported for the color type. 0 is returned if rendering to this color type
* is not supported at all.
*/
SK_API int maxSurfaceSampleCountForColorType(SkColorType) const;
// Provides access to functions that aren't part of the public API.
GrRecordingContextPriv priv();
const GrRecordingContextPriv priv() const; // NOLINT(readability-const-return-type)
// The collection of specialized memory arenas for different types of data recorded by a
// GrRecordingContext. Arenas does not maintain ownership of the pools it groups together.
class Arenas {
public:
Arenas(SkArenaAlloc*, GrSubRunAllocator*);
// For storing pipelines and other complex data as-needed by ops
SkArenaAlloc* recordTimeAllocator() { return fRecordTimeAllocator; }
// For storing GrTextBlob SubRuns
GrSubRunAllocator* recordTimeSubRunAllocator() { return fRecordTimeSubRunAllocator; }
private:
SkArenaAlloc* fRecordTimeAllocator;
GrSubRunAllocator* fRecordTimeSubRunAllocator;
};
protected:
friend class GrRecordingContextPriv; // for hidden functions
friend class SkDeferredDisplayList; // for OwnedArenas
friend class SkDeferredDisplayListPriv; // for ProgramData
// Like Arenas, but preserves ownership of the underlying pools.
class OwnedArenas {
public:
OwnedArenas(bool ddlRecording);
~OwnedArenas();
Arenas get();
OwnedArenas& operator=(OwnedArenas&&);
private:
bool fDDLRecording;
std::unique_ptr<SkArenaAlloc> fRecordTimeAllocator;
std::unique_ptr<GrSubRunAllocator> fRecordTimeSubRunAllocator;
};
GrRecordingContext(sk_sp<GrContextThreadSafeProxy>, bool ddlRecording);
bool init() override;
void abandonContext() override;
GrDrawingManager* drawingManager();
// There is no going back from this method. It should only be called to control the timing
// during abandon or destruction of the context.
void destroyDrawingManager();
Arenas arenas() { return fArenas.get(); }
// This entry point should only be used for DDL creation where we want the ops' lifetime to
// match that of the DDL.
OwnedArenas&& detachArenas();
GrProxyProvider* proxyProvider() { return fProxyProvider.get(); }
const GrProxyProvider* proxyProvider() const { return fProxyProvider.get(); }
struct ProgramData {
ProgramData(std::unique_ptr<const GrProgramDesc>, const GrProgramInfo*);
ProgramData(ProgramData&&); // for SkTArray
ProgramData(const ProgramData&) = delete;
~ProgramData();
const GrProgramDesc& desc() const { return *fDesc; }
const GrProgramInfo& info() const { return *fInfo; }
private:
// TODO: store the GrProgramDescs in the 'fRecordTimeData' arena
std::unique_ptr<const GrProgramDesc> fDesc;
// The program infos should be stored in 'fRecordTimeData' so do not need to be ref
// counted or deleted in the destructor.
const GrProgramInfo* fInfo = nullptr;
};
// This entry point gives the recording context a chance to cache the provided
// programInfo. The DDL context takes this opportunity to store programInfos as a sidecar
// to the DDL.
virtual void recordProgramInfo(const GrProgramInfo*) {}
// This asks the recording context to return any programInfos it may have collected
// via the 'recordProgramInfo' call. It is up to the caller to ensure that the lifetime
// of the programInfos matches the intended use. For example, in DDL-record mode it
// is known that all the programInfos will have been allocated in an arena with the
// same lifetime at the DDL itself.
virtual void detachProgramData(SkTArray<ProgramData>*) {}
GrTextBlobRedrawCoordinator* getTextBlobRedrawCoordinator();
const GrTextBlobRedrawCoordinator* getTextBlobRedrawCoordinator() const;
GrThreadSafeCache* threadSafeCache();
const GrThreadSafeCache* threadSafeCache() const;
/**
* Registers an object for flush-related callbacks. (See GrOnFlushCallbackObject.)
*
* NOTE: the drawing manager tracks this object as a raw pointer; it is up to the caller to
* ensure its lifetime is tied to that of the context.
*/
void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
GrRecordingContext* asRecordingContext() override { return this; }
class Stats {
public:
Stats() = default;
#if GR_GPU_STATS
void reset() { *this = {}; }
int numPathMasksGenerated() const { return fNumPathMasksGenerated; }
void incNumPathMasksGenerated() { fNumPathMasksGenerated++; }
int numPathMaskCacheHits() const { return fNumPathMaskCacheHits; }
void incNumPathMasksCacheHits() { fNumPathMaskCacheHits++; }
#if GR_TEST_UTILS
void dump(SkString* out) const;
void dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
#endif
private:
int fNumPathMasksGenerated{0};
int fNumPathMaskCacheHits{0};
#else // GR_GPU_STATS
void incNumPathMasksGenerated() {}
void incNumPathMasksCacheHits() {}
#if GR_TEST_UTILS
void dump(SkString*) const {}
void dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const {}
#endif
#endif // GR_GPU_STATS
} fStats;
#if GR_GPU_STATS && GR_TEST_UTILS
struct DMSAAStats {
void dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
void dump() const;
void merge(const DMSAAStats&);
int fNumRenderPasses = 0;
int fNumMultisampleRenderPasses = 0;
std::map<std::string, int> fTriggerCounts;
};
DMSAAStats fDMSAAStats;
#endif
Stats* stats() { return &fStats; }
const Stats* stats() const { return &fStats; }
void dumpJSON(SkJSONWriter*) const;
protected:
// Delete last in case other objects call it during destruction.
std::unique_ptr<GrAuditTrail> fAuditTrail;
private:
OwnedArenas fArenas;
std::unique_ptr<GrDrawingManager> fDrawingManager;
std::unique_ptr<GrProxyProvider> fProxyProvider;
#if GR_TEST_UTILS
int fSuppressWarningMessages = 0;
#endif
using INHERITED = GrImageContext;
};
/**
* Safely cast a possibly-null base context to direct context.
*/
static inline GrDirectContext* GrAsDirectContext(GrContext_Base* base) {
return base ? base->asDirectContext() : nullptr;
}
#endif
|