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/gpu/GrRecordingContext.h"
12 #include "src/gpu/text/GrSDFTOptions.h"
13 
14 class SkDeferredDisplayList;
15 
16 /** Class that exposes methods to GrRecordingContext that are only intended for use internal to
17     Skia. This class is purely a privileged window into GrRecordingContext. It should never have
18     additional data members or virtual methods. */
19 class GrRecordingContextPriv {
20 public:
21     // from GrContext_Base
contextID()22     uint32_t contextID() const { return fContext->contextID(); }
23 
matches(GrContext_Base * candidate)24     bool matches(GrContext_Base* candidate) const { return fContext->matches(candidate); }
25 
options()26     const GrContextOptions& options() const { return fContext->options(); }
27 
caps()28     const GrCaps* caps() const { return fContext->caps(); }
29     sk_sp<const GrCaps> refCaps() const;
30 
asImageContext()31     GrImageContext* asImageContext() { return fContext->asImageContext(); }
asRecordingContext()32     GrRecordingContext* asRecordingContext() { return fContext->asRecordingContext(); }
33 
34     // from GrImageContext
proxyProvider()35     GrProxyProvider* proxyProvider() { return fContext->proxyProvider(); }
proxyProvider()36     const GrProxyProvider* proxyProvider() const { return fContext->proxyProvider(); }
37 
38     /** This is only useful for debug purposes */
SkDEBUGCODE(GrSingleOwner * singleOwner ()const{ return fContext->singleOwner(); } )39     SkDEBUGCODE(GrSingleOwner* singleOwner() const { return fContext->singleOwner(); } )
40 
41     // from GrRecordingContext
42     GrDrawingManager* drawingManager() { return fContext->drawingManager(); }
43 
opMemoryPool()44     GrMemoryPool* opMemoryPool() { return fContext->arenas().opMemoryPool(); }
recordTimeAllocator()45     SkArenaAlloc* recordTimeAllocator() { return fContext->arenas().recordTimeAllocator(); }
arenas()46     GrRecordingContext::Arenas arenas() { return fContext->arenas(); }
47 
detachArenas()48     GrRecordingContext::OwnedArenas&& detachArenas() { return fContext->detachArenas(); }
49 
recordProgramInfo(const GrProgramInfo * programInfo)50     void recordProgramInfo(const GrProgramInfo* programInfo) {
51         fContext->recordProgramInfo(programInfo);
52     }
53 
detachProgramData(SkTArray<GrRecordingContext::ProgramData> * dst)54     void detachProgramData(SkTArray<GrRecordingContext::ProgramData>* dst) {
55         fContext->detachProgramData(dst);
56     }
57 
getTextBlobCache()58     GrTextBlobCache* getTextBlobCache() { return fContext->getTextBlobCache(); }
59 
threadSafeCache()60     GrThreadSafeCache* threadSafeCache() { return fContext->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 fContext->auditTrail(); }
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() { ++fContext->fSuppressWarningMessages; }
decrSuppressWarningMessages()89     void decrSuppressWarningMessages() { --fContext->fSuppressWarningMessages; }
90 #endif
91 
printWarningMessage(const char * msg)92     void printWarningMessage(const char* msg) const {
93 #if GR_TEST_UTILS
94         if (fContext->fSuppressWarningMessages > 0) {
95             return;
96         }
97 #endif
98         SkDebugf(msg);
99     }
100 
stats()101     GrRecordingContext::Stats* stats() {
102         return &fContext->fStats;
103     }
104 
SDFTOptions()105     GrSDFTOptions SDFTOptions() const {
106         return {this->options().fMinDistanceFieldFontSize, this->options().fGlyphsAsPathsFontSize};
107     }
108 
109     /**
110      * Create a GrRecordingContext without a resource cache
111      */
112     static sk_sp<GrRecordingContext> MakeDDL(sk_sp<GrContextThreadSafeProxy>);
113 
114 private:
GrRecordingContextPriv(GrRecordingContext * context)115     explicit GrRecordingContextPriv(GrRecordingContext* context) : fContext(context) {}
116     GrRecordingContextPriv(const GrRecordingContextPriv&) = delete;
117     GrRecordingContextPriv& operator=(const GrRecordingContextPriv&) = delete;
118 
119     // No taking addresses of this type.
120     const GrRecordingContextPriv* operator&() const;
121     GrRecordingContextPriv* operator&();
122 
123     GrRecordingContext* fContext;
124 
125     friend class GrRecordingContext; // to construct/copy this type.
126 };
127 
priv()128 inline GrRecordingContextPriv GrRecordingContext::priv() { return GrRecordingContextPriv(this); }
129 
priv()130 inline const GrRecordingContextPriv GrRecordingContext::priv () const {  // NOLINT(readability-const-return-type)
131     return GrRecordingContextPriv(const_cast<GrRecordingContext*>(this));
132 }
133 
134 #endif
135