| 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 |
| 22 | uint32_t contextID() const { return fContext->contextID(); } |
| 23 | |
| 24 | bool matches(GrContext_Base* candidate) const { return fContext->matches(candidate); } |
| 25 | |
| 26 | const GrContextOptions& options() const { return fContext->options(); } |
| 27 | |
| 28 | const GrCaps* caps() const { return fContext->caps(); } |
| 29 | sk_sp<const GrCaps> refCaps() const; |
| 30 | |
| 31 | GrImageContext* asImageContext() { return fContext->asImageContext(); } |
| 32 | GrRecordingContext* asRecordingContext() { return fContext->asRecordingContext(); } |
| 33 | |
| 34 | // from GrImageContext |
| 35 | GrProxyProvider* proxyProvider() { return fContext->proxyProvider(); } |
| 36 | const GrProxyProvider* proxyProvider() const { return fContext->proxyProvider(); } |
| 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 | 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 | |
| 70 | GrAuditTrail* auditTrail() { return fContext->auditTrail(); } |
| 71 | |
| 72 | // CONTEXT TODO: remove this backdoor |
| 73 | // In order to make progress we temporarily need a way to break CL impasses. |
| 74 | GrContext* backdoor(); |
| 75 | |
| 76 | #if GR_TEST_UTILS |
| 77 | // Used by tests that intentionally exercise codepaths that print warning messages, in order to |
| 78 | // not confuse users with output that looks like a testing failure. |
| 79 | class AutoSuppressWarningMessages { |
| 80 | public: |
| 81 | AutoSuppressWarningMessages(GrRecordingContext* context) : fContext(context) { |
| 82 | ++fContext->fSuppressWarningMessages; |
| 83 | } |
| 84 | ~AutoSuppressWarningMessages() { |
| 85 | --fContext->fSuppressWarningMessages; |
| 86 | } |
| 87 | private: |
| 88 | GrRecordingContext* fContext; |
| 89 | }; |
| 90 | void incrSuppressWarningMessages() { ++fContext->fSuppressWarningMessages; } |
| 91 | void decrSuppressWarningMessages() { --fContext->fSuppressWarningMessages; } |
| 92 | #endif |
| 93 | |
| 94 | void printWarningMessage(const char* msg) const { |
| 95 | #if GR_TEST_UTILS |
| 96 | if (fContext->fSuppressWarningMessages > 0) { |
| 97 | return; |
| 98 | } |
| 99 | #endif |
| 100 | SkDebugf(msg); |
| 101 | } |
| 102 | |
| 103 | GrRecordingContext::Stats* stats() { |
| 104 | return &fContext->fStats; |
| 105 | } |
| 106 | |
| 107 | GrSDFTOptions SDFTOptions() const { |
| 108 | return {this->options().fMinDistanceFieldFontSize, this->options().fGlyphsAsPathsFontSize}; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Create a GrRecordingContext without a resource cache |
| 113 | */ |
| 114 | static sk_sp<GrRecordingContext> MakeDDL(sk_sp<GrContextThreadSafeProxy>); |
| 115 | |
| 116 | private: |
| 117 | explicit GrRecordingContextPriv(GrRecordingContext* context) : fContext(context) {} |
| 118 | GrRecordingContextPriv(const GrRecordingContextPriv&) = delete; |
| 119 | GrRecordingContextPriv& operator=(const GrRecordingContextPriv&) = delete; |
| 120 | |
| 121 | // No taking addresses of this type. |
| 122 | const GrRecordingContextPriv* operator&() const; |
| 123 | GrRecordingContextPriv* operator&(); |
| 124 | |
| 125 | GrRecordingContext* fContext; |
| 126 | |
| 127 | friend class GrRecordingContext; // to construct/copy this type. |
| 128 | }; |
| 129 | |
| 130 | inline GrRecordingContextPriv GrRecordingContext::priv() { return GrRecordingContextPriv(this); } |
| 131 | |
| 132 | inline const GrRecordingContextPriv GrRecordingContext::priv () const { // NOLINT(readability-const-return-type) |
| 133 | return GrRecordingContextPriv(const_cast<GrRecordingContext*>(this)); |
| 134 | } |
| 135 | |
| 136 | #endif |
| 137 |