• 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/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 SkDeferredDisplayList;
19 namespace skgpu {
20     class SurfaceContext;
21     class SurfaceFillContext;
22     class Swizzle;
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     GrTextBlobRedrawCoordinator* getTextBlobCache() {
57         return this->context()->getTextBlobRedrawCoordinator();
58     }
59 
threadSafeCache()60     GrThreadSafeCache* threadSafeCache() { return this->context()->threadSafeCache(); }
61 
62     void moveRenderTasksToDDL(SkDeferredDisplayList*);
63 
64     /**
65      * Registers an object for flush-related callbacks. (See GrOnFlushCallbackObject.)
66      *
67      * NOTE: the drawing manager tracks this object as a raw pointer; it is up to the caller to
68      * ensure its lifetime is tied to that of the context.
69      */
70     void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
71 
auditTrail()72     GrAuditTrail* auditTrail() { return this->context()->fAuditTrail.get(); }
73 
74 #if GR_TEST_UTILS
75     // Used by tests that intentionally exercise codepaths that print warning messages, in order to
76     // not confuse users with output that looks like a testing failure.
77     class AutoSuppressWarningMessages {
78     public:
AutoSuppressWarningMessages(GrRecordingContext * context)79         AutoSuppressWarningMessages(GrRecordingContext* context) : fContext(context) {
80             ++fContext->fSuppressWarningMessages;
81         }
~AutoSuppressWarningMessages()82         ~AutoSuppressWarningMessages() {
83             --fContext->fSuppressWarningMessages;
84         }
85     private:
86         GrRecordingContext* fContext;
87     };
incrSuppressWarningMessages()88     void incrSuppressWarningMessages() { ++this->context()->fSuppressWarningMessages; }
decrSuppressWarningMessages()89     void decrSuppressWarningMessages() { --this->context()->fSuppressWarningMessages; }
90 #endif
91 
printWarningMessage(const char * msg)92     void printWarningMessage(const char* msg) const {
93 #if GR_TEST_UTILS
94         if (this->context()->fSuppressWarningMessages > 0) {
95             return;
96         }
97 #endif
98         SkDebugf("%s", msg);
99     }
100 
stats()101     GrRecordingContext::Stats* stats() {
102         return &this->context()->fStats;
103     }
104 
105 #if GR_GPU_STATS && GR_TEST_UTILS
106     using DMSAAStats = GrRecordingContext::DMSAAStats;
dmsaaStats()107     DMSAAStats& dmsaaStats() { return this->context()->fDMSAAStats; }
108 #endif
109 
110     GrSDFTControl getSDFTControl(bool useSDFTForSmallText) const;
111 
112     /**
113      * Create a GrRecordingContext without a resource cache
114      */
115     static sk_sp<GrRecordingContext> MakeDDL(sk_sp<GrContextThreadSafeProxy>);
116 
117     sk_sp<skgpu::BaseDevice> createDevice(GrColorType,
118                                           sk_sp<GrSurfaceProxy>,
119                                           sk_sp<SkColorSpace>,
120                                           GrSurfaceOrigin,
121                                           const SkSurfaceProps&,
122                                           skgpu::BaseDevice::InitContents);
123     sk_sp<skgpu::BaseDevice> createDevice(SkBudgeted,
124                                           const SkImageInfo&,
125                                           SkBackingFit,
126                                           int sampleCount,
127                                           GrMipmapped,
128                                           GrProtected,
129                                           GrSurfaceOrigin,
130                                           const SkSurfaceProps&,
131                                           skgpu::BaseDevice::InitContents);
132 
133     // If the passed in GrSurfaceProxy is renderable this will return a SurfaceDrawContext,
134     // otherwise it will return a SurfaceContext.
135     std::unique_ptr<skgpu::SurfaceContext> makeSC(GrSurfaceProxyView readView,
136                                                   const GrColorInfo&);
137 
138     // Makes either a SurfaceContext, SurfaceFillContext, or a SurfaceDrawContext, depending on
139     // GrRenderable and the GrImageInfo.
140     std::unique_ptr<skgpu::SurfaceContext> makeSC(const GrImageInfo&,
141                                                   const GrBackendFormat&,
142                                                   SkBackingFit = SkBackingFit::kExact,
143                                                   GrSurfaceOrigin = kTopLeft_GrSurfaceOrigin,
144                                                   GrRenderable = GrRenderable::kNo,
145                                                   int renderTargetSampleCnt = 1,
146                                                   GrMipmapped = GrMipmapped::kNo,
147                                                   GrProtected = GrProtected::kNo,
148                                                   SkBudgeted = SkBudgeted::kYes);
149 
150     /**
151      * Uses GrImageInfo's color type to pick the default texture format. Will return a
152      * SurfaceDrawContext if possible.
153      */
154     std::unique_ptr<skgpu::SurfaceFillContext> makeSFC(
155         GrImageInfo,
156         SkBackingFit = SkBackingFit::kExact,
157         int sampleCount = 1,
158         GrMipmapped = GrMipmapped::kNo,
159         GrProtected = GrProtected::kNo,
160         GrSurfaceOrigin = kTopLeft_GrSurfaceOrigin,
161         SkBudgeted = SkBudgeted::kYes);
162 
163     /**
164      * Makes a custom configured SurfaceFillContext where the caller specifies the specific
165      * texture format and swizzles. The color type will be kUnknown. Returns a SurfaceDrawContext
166      * if possible.
167      */
168     std::unique_ptr<skgpu::SurfaceFillContext> makeSFC(SkAlphaType,
169                                                        sk_sp<SkColorSpace>,
170                                                        SkISize dimensions,
171                                                        SkBackingFit,
172                                                        const GrBackendFormat&,
173                                                        int sampleCount,
174                                                        GrMipmapped,
175                                                        GrProtected,
176                                                        skgpu::Swizzle readSwizzle,
177                                                        skgpu::Swizzle writeSwizzle,
178                                                        GrSurfaceOrigin,
179                                                        SkBudgeted);
180 
181     /**
182      * Like the above but uses GetFallbackColorTypeAndFormat to find a fallback color type (and
183      * compatible format) if the passed GrImageInfo's color type is not renderable.
184      */
185     std::unique_ptr<skgpu::SurfaceFillContext> makeSFCWithFallback(
186             GrImageInfo,
187             SkBackingFit = SkBackingFit::kExact,
188             int sampleCount = 1,
189             GrMipmapped = GrMipmapped::kNo,
190             GrProtected = GrProtected::kNo,
191             GrSurfaceOrigin = kTopLeft_GrSurfaceOrigin,
192             SkBudgeted = SkBudgeted::kYes);
193 
194     /**
195      * Creates a SurfaceFillContext from an existing GrBackendTexture. The GrColorInfo's color
196      * type must be compatible with backend texture's format or this will fail. All formats are
197      * considered compatible with kUnknown. Returns a SurfaceDrawContext if possible.
198      */
199     std::unique_ptr<skgpu::SurfaceFillContext> makeSFCFromBackendTexture(
200             GrColorInfo,
201             const GrBackendTexture&,
202             int sampleCount,
203             GrSurfaceOrigin,
204             sk_sp<GrRefCntedCallback> releaseHelper);
205 
206 protected:
GrRecordingContextPriv(GrRecordingContext * rContext)207     explicit GrRecordingContextPriv(GrRecordingContext* rContext) : GrImageContextPriv(rContext) {}
208 
209 private:
210     GrRecordingContextPriv(const GrRecordingContextPriv&) = delete;
211     GrRecordingContextPriv& operator=(const GrRecordingContextPriv&) = delete;
212 
213     // No taking addresses of this type.
214     const GrRecordingContextPriv* operator&() const;
215     GrRecordingContextPriv* operator&();
216 
217     friend class GrRecordingContext; // to construct/copy this type.
218 
219     using INHERITED = GrImageContextPriv;
220 };
221 
priv()222 inline GrRecordingContextPriv GrRecordingContext::priv() { return GrRecordingContextPriv(this); }
223 
priv()224 inline const GrRecordingContextPriv GrRecordingContext::priv () const {  // NOLINT(readability-const-return-type)
225     return GrRecordingContextPriv(const_cast<GrRecordingContext*>(this));
226 }
227 
228 #endif
229