1 /*
2 * Copyright 2019 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
8 #ifndef GrRecordingContextPriv_DEFINED
9 #define GrRecordingContextPriv_DEFINED
10
11 #include "include/core/SkPaint.h"
12 #include "include/gpu/GrRecordingContext.h"
13 #include "src/gpu/BaseDevice.h"
14 #include "src/gpu/GrImageContextPriv.h"
15 #include "src/gpu/text/GrSDFTControl.h"
16
17 class GrImageInfo;
18 class GrSwizzle;
19 class SkDeferredDisplayList;
20 namespace skgpu {
21 class SurfaceContext;
22 class SurfaceFillContext;
23 }
24
25 /** Class that exposes methods on GrRecordingContext that are only intended for use internal to
26 Skia. This class is purely a privileged window into GrRecordingContext. It should never have
27 additional data members or virtual methods. */
28 class GrRecordingContextPriv : public GrImageContextPriv {
29 public:
context()30 GrRecordingContext* context() { return static_cast<GrRecordingContext*>(fContext); }
context()31 const GrRecordingContext* context() const {
32 return static_cast<const GrRecordingContext*>(fContext);
33 }
34
proxyProvider()35 GrProxyProvider* proxyProvider() { return this->context()->proxyProvider(); }
proxyProvider()36 const GrProxyProvider* proxyProvider() const { return this->context()->proxyProvider(); }
37
drawingManager()38 GrDrawingManager* drawingManager() { return this->context()->drawingManager(); }
39
recordTimeAllocator()40 SkArenaAlloc* recordTimeAllocator() { return this->context()->arenas().recordTimeAllocator(); }
recordTimeSubRunAllocator()41 GrSubRunAllocator* recordTimeSubRunAllocator() {
42 return this->context()->arenas().recordTimeSubRunAllocator();
43 }
arenas()44 GrRecordingContext::Arenas arenas() { return this->context()->arenas(); }
45
detachArenas()46 GrRecordingContext::OwnedArenas&& detachArenas() { return this->context()->detachArenas(); }
47
recordProgramInfo(const GrProgramInfo * programInfo)48 void recordProgramInfo(const GrProgramInfo* programInfo) {
49 this->context()->recordProgramInfo(programInfo);
50 }
51
detachProgramData(SkTArray<GrRecordingContext::ProgramData> * dst)52 void detachProgramData(SkTArray<GrRecordingContext::ProgramData>* dst) {
53 this->context()->detachProgramData(dst);
54 }
55
getTextBlobCache()56 GrTextBlobCache* getTextBlobCache() { return this->context()->getTextBlobCache(); }
57
threadSafeCache()58 GrThreadSafeCache* threadSafeCache() { return this->context()->threadSafeCache(); }
59
60 void moveRenderTasksToDDL(SkDeferredDisplayList*);
61
62 /**
63 * Registers an object for flush-related callbacks. (See GrOnFlushCallbackObject.)
64 *
65 * NOTE: the drawing manager tracks this object as a raw pointer; it is up to the caller to
66 * ensure its lifetime is tied to that of the context.
67 */
68 void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
69
auditTrail()70 GrAuditTrail* auditTrail() { return this->context()->fAuditTrail.get(); }
71
72 #if GR_TEST_UTILS
73 // Used by tests that intentionally exercise codepaths that print warning messages, in order to
74 // not confuse users with output that looks like a testing failure.
75 class AutoSuppressWarningMessages {
76 public:
AutoSuppressWarningMessages(GrRecordingContext * context)77 AutoSuppressWarningMessages(GrRecordingContext* context) : fContext(context) {
78 ++fContext->fSuppressWarningMessages;
79 }
~AutoSuppressWarningMessages()80 ~AutoSuppressWarningMessages() {
81 --fContext->fSuppressWarningMessages;
82 }
83 private:
84 GrRecordingContext* fContext;
85 };
incrSuppressWarningMessages()86 void incrSuppressWarningMessages() { ++this->context()->fSuppressWarningMessages; }
decrSuppressWarningMessages()87 void decrSuppressWarningMessages() { --this->context()->fSuppressWarningMessages; }
88 #endif
89
printWarningMessage(const char * msg)90 void printWarningMessage(const char* msg) const {
91 #if GR_TEST_UTILS
92 if (this->context()->fSuppressWarningMessages > 0) {
93 return;
94 }
95 #endif
96 SkDebugf("%s", msg);
97 }
98
stats()99 GrRecordingContext::Stats* stats() {
100 return &this->context()->fStats;
101 }
102
103 #if GR_GPU_STATS && GR_TEST_UTILS
104 using DMSAAStats = GrRecordingContext::DMSAAStats;
dmsaaStats()105 DMSAAStats& dmsaaStats() { return this->context()->fDMSAAStats; }
106 #endif
107
108 GrSDFTControl getSDFTControl(bool useSDFTForSmallText) const;
109
110 /**
111 * Create a GrRecordingContext without a resource cache
112 */
113 static sk_sp<GrRecordingContext> MakeDDL(sk_sp<GrContextThreadSafeProxy>);
114
115 sk_sp<skgpu::BaseDevice> createDevice(GrColorType,
116 sk_sp<GrSurfaceProxy>,
117 sk_sp<SkColorSpace>,
118 GrSurfaceOrigin,
119 const SkSurfaceProps&,
120 skgpu::BaseDevice::InitContents);
121 sk_sp<skgpu::BaseDevice> createDevice(SkBudgeted,
122 const SkImageInfo&,
123 SkBackingFit,
124 int sampleCount,
125 GrMipmapped,
126 GrProtected,
127 GrSurfaceOrigin,
128 const SkSurfaceProps&,
129 skgpu::BaseDevice::InitContents);
130
131 // If the passed in GrSurfaceProxy is renderable this will return a SurfaceDrawContext,
132 // otherwise it will return a SurfaceContext.
133 std::unique_ptr<skgpu::SurfaceContext> makeSC(GrSurfaceProxyView readView,
134 const GrColorInfo&);
135
136 // Makes either a SurfaceContext, SurfaceFillContext, or a SurfaceDrawContext, depending on
137 // GrRenderable and the GrImageInfo.
138 std::unique_ptr<skgpu::SurfaceContext> makeSC(const GrImageInfo&,
139 const GrBackendFormat&,
140 SkBackingFit = SkBackingFit::kExact,
141 GrSurfaceOrigin = kTopLeft_GrSurfaceOrigin,
142 GrRenderable = GrRenderable::kNo,
143 int renderTargetSampleCnt = 1,
144 GrMipmapped = GrMipmapped::kNo,
145 GrProtected = GrProtected::kNo,
146 SkBudgeted = SkBudgeted::kYes);
147
148 /**
149 * Uses GrImageInfo's color type to pick the default texture format. Will return a
150 * SurfaceDrawContext if possible.
151 */
152 std::unique_ptr<skgpu::SurfaceFillContext> makeSFC(
153 GrImageInfo,
154 SkBackingFit = SkBackingFit::kExact,
155 int sampleCount = 1,
156 GrMipmapped = GrMipmapped::kNo,
157 GrProtected = GrProtected::kNo,
158 GrSurfaceOrigin = kTopLeft_GrSurfaceOrigin,
159 SkBudgeted = SkBudgeted::kYes);
160
161 /**
162 * Makes a custom configured SurfaceFillContext where the caller specifies the specific
163 * texture format and swizzles. The color type will be kUnknown. Returns a SurfaceDrawContext
164 * if possible.
165 */
166 std::unique_ptr<skgpu::SurfaceFillContext> makeSFC(SkAlphaType,
167 sk_sp<SkColorSpace>,
168 SkISize dimensions,
169 SkBackingFit,
170 const GrBackendFormat&,
171 int sampleCount,
172 GrMipmapped,
173 GrProtected,
174 GrSwizzle readSwizzle,
175 GrSwizzle writeSwizzle,
176 GrSurfaceOrigin,
177 SkBudgeted);
178
179 /**
180 * Like the above but uses GetFallbackColorTypeAndFormat to find a fallback color type (and
181 * compatible format) if the passed GrImageInfo's color type is not renderable.
182 */
183 std::unique_ptr<skgpu::SurfaceFillContext> makeSFCWithFallback(
184 GrImageInfo,
185 SkBackingFit = SkBackingFit::kExact,
186 int sampleCount = 1,
187 GrMipmapped = GrMipmapped::kNo,
188 GrProtected = GrProtected::kNo,
189 GrSurfaceOrigin = kTopLeft_GrSurfaceOrigin,
190 SkBudgeted = SkBudgeted::kYes);
191
192 /**
193 * Creates a SurfaceFillContext from an existing GrBackendTexture. The GrColorInfo's color
194 * type must be compatible with backend texture's format or this will fail. All formats are
195 * considered compatible with kUnknown. Returns a SurfaceDrawContext if possible.
196 */
197 std::unique_ptr<skgpu::SurfaceFillContext> makeSFCFromBackendTexture(
198 GrColorInfo,
199 const GrBackendTexture&,
200 int sampleCount,
201 GrSurfaceOrigin,
202 sk_sp<GrRefCntedCallback> releaseHelper);
203
204 protected:
GrRecordingContextPriv(GrRecordingContext * rContext)205 explicit GrRecordingContextPriv(GrRecordingContext* rContext) : GrImageContextPriv(rContext) {}
206 // Required until C++17 copy elision
207 GrRecordingContextPriv(const GrRecordingContextPriv&) = default;
208
209 private:
210 GrRecordingContextPriv& operator=(const GrRecordingContextPriv&) = delete;
211
212 // No taking addresses of this type.
213 const GrRecordingContextPriv* operator&() const;
214 GrRecordingContextPriv* operator&();
215
216 friend class GrRecordingContext; // to construct/copy this type.
217
218 using INHERITED = GrImageContextPriv;
219 };
220
priv()221 inline GrRecordingContextPriv GrRecordingContext::priv() { return GrRecordingContextPriv(this); }
222
priv()223 inline const GrRecordingContextPriv GrRecordingContext::priv () const { // NOLINT(readability-const-return-type)
224 return GrRecordingContextPriv(const_cast<GrRecordingContext*>(this));
225 }
226
227 #endif
228