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/private/GrRecordingContext.h" |
12 | |
13 | /** Class that exposes methods to GrRecordingContext that are only intended for use internal to |
14 | Skia. This class is purely a privileged window into GrRecordingContext. It should never have |
15 | additional data members or virtual methods. */ |
16 | class GrRecordingContextPriv { |
17 | public: |
18 | // from GrContext_Base |
19 | uint32_t contextID() const { return fContext->contextID(); } |
20 | |
21 | bool matches(GrContext_Base* candidate) const { return fContext->matches(candidate); } |
22 | |
23 | const GrContextOptions& options() const { return fContext->options(); } |
24 | |
25 | const GrCaps* caps() const { return fContext->caps(); } |
26 | sk_sp<const GrCaps> refCaps() const; |
27 | |
28 | GrImageContext* asImageContext() { return fContext->asImageContext(); } |
29 | GrRecordingContext* asRecordingContext() { return fContext->asRecordingContext(); } |
30 | GrContext* asDirectContext() { return fContext->asDirectContext(); } |
31 | |
32 | // from GrImageContext |
33 | GrProxyProvider* proxyProvider() { return fContext->proxyProvider(); } |
34 | const GrProxyProvider* proxyProvider() const { return fContext->proxyProvider(); } |
35 | |
36 | bool abandoned() const { return fContext->abandoned(); } |
37 | |
38 | /** This is only useful for debug purposes */ |
39 | SkDEBUGCODE(GrSingleOwner* singleOwner() const { return fContext->singleOwner(); } ) |
40 | |
41 | // from GrRecordingContext |
42 | GrDrawingManager* drawingManager() { return fContext->drawingManager(); } |
43 | |
44 | GrOpMemoryPool* opMemoryPool() { return fContext->arenas().opMemoryPool(); } |
45 | SkArenaAlloc* recordTimeAllocator() { return fContext->arenas().recordTimeAllocator(); } |
46 | GrRecordingContext::Arenas arenas() { return fContext->arenas(); } |
47 | |
48 | GrRecordingContext::OwnedArenas&& detachArenas() { return fContext->detachArenas(); } |
49 | |
50 | void recordProgramInfo(const GrProgramInfo* programInfo) { |
51 | fContext->recordProgramInfo(programInfo); |
52 | } |
53 | |
54 | void detachProgramData(SkTArray<GrRecordingContext::ProgramData>* dst) { |
55 | fContext->detachProgramData(dst); |
56 | } |
57 | |
58 | GrTextBlobCache* getTextBlobCache() { return fContext->getTextBlobCache(); } |
59 | |
60 | /** |
61 | * Registers an object for flush-related callbacks. (See GrOnFlushCallbackObject.) |
62 | * |
63 | * NOTE: the drawing manager tracks this object as a raw pointer; it is up to the caller to |
64 | * ensure its lifetime is tied to that of the context. |
65 | */ |
66 | void addOnFlushCallbackObject(GrOnFlushCallbackObject*); |
67 | |
68 | GrAuditTrail* auditTrail() { return fContext->auditTrail(); } |
69 | |
70 | // CONTEXT TODO: remove this backdoor |
71 | // In order to make progress we temporarily need a way to break CL impasses. |
72 | GrContext* backdoor(); |
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: |
79 | AutoSuppressWarningMessages(GrRecordingContext* context) : fContext(context) { |
80 | ++fContext->fSuppressWarningMessages; |
81 | } |
82 | ~AutoSuppressWarningMessages() { |
83 | --fContext->fSuppressWarningMessages; |
84 | } |
85 | private: |
86 | GrRecordingContext* fContext; |
87 | }; |
88 | void incrSuppressWarningMessages() { ++fContext->fSuppressWarningMessages; } |
89 | void decrSuppressWarningMessages() { --fContext->fSuppressWarningMessages; } |
90 | #endif |
91 | |
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 | |
101 | private: |
102 | explicit GrRecordingContextPriv(GrRecordingContext* context) : fContext(context) {} |
103 | GrRecordingContextPriv(const GrRecordingContextPriv&); // unimpl |
104 | GrRecordingContextPriv& operator=(const GrRecordingContextPriv&); // unimpl |
105 | |
106 | // No taking addresses of this type. |
107 | const GrRecordingContextPriv* operator&() const; |
108 | GrRecordingContextPriv* operator&(); |
109 | |
110 | GrRecordingContext* fContext; |
111 | |
112 | friend class GrRecordingContext; // to construct/copy this type. |
113 | }; |
114 | |
115 | inline GrRecordingContextPriv GrRecordingContext::priv() { return GrRecordingContextPriv(this); } |
116 | |
117 | inline const GrRecordingContextPriv GrRecordingContext::priv () const { |
118 | return GrRecordingContextPriv(const_cast<GrRecordingContext*>(this)); |
119 | } |
120 | |
121 | #endif |
122 |