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