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/text/GrSDFTControl.h" 14 15 class SkDeferredDisplayList; 16 17 /** Class that exposes methods to GrRecordingContext that are only intended for use internal to 18 Skia. This class is purely a privileged window into GrRecordingContext. It should never have 19 additional data members or virtual methods. */ 20 class GrRecordingContextPriv { 21 public: 22 // from GrContext_Base contextID()23 uint32_t contextID() const { return fContext->contextID(); } 24 matches(GrContext_Base * candidate)25 bool matches(GrContext_Base* candidate) const { return fContext->matches(candidate); } 26 options()27 const GrContextOptions& options() const { return fContext->options(); } 28 caps()29 const GrCaps* caps() const { return fContext->caps(); } 30 sk_sp<const GrCaps> refCaps() const; 31 asImageContext()32 GrImageContext* asImageContext() { return fContext->asImageContext(); } asRecordingContext()33 GrRecordingContext* asRecordingContext() { return fContext->asRecordingContext(); } 34 35 // from GrRecordingContext proxyProvider()36 GrProxyProvider* proxyProvider() { return fContext->proxyProvider(); } proxyProvider()37 const GrProxyProvider* proxyProvider() const { return fContext->proxyProvider(); } 38 39 /** This is only useful for debug purposes */ SkDEBUGCODE(GrSingleOwner * singleOwner ()const{ return fContext->singleOwner(); } )40 SkDEBUGCODE(GrSingleOwner* singleOwner() const { return fContext->singleOwner(); } ) 41 42 // from GrRecordingContext 43 GrDrawingManager* drawingManager() { return fContext->drawingManager(); } 44 recordTimeAllocator()45 SkArenaAlloc* recordTimeAllocator() { return fContext->arenas().recordTimeAllocator(); } recordTimeSubRunAllocator()46 GrSubRunAllocator* recordTimeSubRunAllocator() { 47 return fContext->arenas().recordTimeSubRunAllocator(); 48 } arenas()49 GrRecordingContext::Arenas arenas() { return fContext->arenas(); } 50 detachArenas()51 GrRecordingContext::OwnedArenas&& detachArenas() { return fContext->detachArenas(); } 52 recordProgramInfo(const GrProgramInfo * programInfo)53 void recordProgramInfo(const GrProgramInfo* programInfo) { 54 fContext->recordProgramInfo(programInfo); 55 } 56 detachProgramData(SkTArray<GrRecordingContext::ProgramData> * dst)57 void detachProgramData(SkTArray<GrRecordingContext::ProgramData>* dst) { 58 fContext->detachProgramData(dst); 59 } 60 getTextBlobCache()61 GrTextBlobCache* getTextBlobCache() { return fContext->getTextBlobCache(); } 62 threadSafeCache()63 GrThreadSafeCache* threadSafeCache() { return fContext->threadSafeCache(); } 64 65 void moveRenderTasksToDDL(SkDeferredDisplayList*); 66 67 /** 68 * Registers an object for flush-related callbacks. (See GrOnFlushCallbackObject.) 69 * 70 * NOTE: the drawing manager tracks this object as a raw pointer; it is up to the caller to 71 * ensure its lifetime is tied to that of the context. 72 */ 73 void addOnFlushCallbackObject(GrOnFlushCallbackObject*); 74 auditTrail()75 GrAuditTrail* auditTrail() { return fContext->auditTrail(); } 76 77 #if GR_TEST_UTILS 78 // Used by tests that intentionally exercise codepaths that print warning messages, in order to 79 // not confuse users with output that looks like a testing failure. 80 class AutoSuppressWarningMessages { 81 public: AutoSuppressWarningMessages(GrRecordingContext * context)82 AutoSuppressWarningMessages(GrRecordingContext* context) : fContext(context) { 83 ++fContext->fSuppressWarningMessages; 84 } ~AutoSuppressWarningMessages()85 ~AutoSuppressWarningMessages() { 86 --fContext->fSuppressWarningMessages; 87 } 88 private: 89 GrRecordingContext* fContext; 90 }; incrSuppressWarningMessages()91 void incrSuppressWarningMessages() { ++fContext->fSuppressWarningMessages; } decrSuppressWarningMessages()92 void decrSuppressWarningMessages() { --fContext->fSuppressWarningMessages; } 93 #endif 94 printWarningMessage(const char * msg)95 void printWarningMessage(const char* msg) const { 96 #if GR_TEST_UTILS 97 if (fContext->fSuppressWarningMessages > 0) { 98 return; 99 } 100 #endif 101 SkDebugf(msg); 102 } 103 stats()104 GrRecordingContext::Stats* stats() { 105 return &fContext->fStats; 106 } 107 108 #if GR_GPU_STATS && GR_TEST_UTILS 109 using DMSAAStats = GrRecordingContext::DMSAAStats; dmsaaStats()110 DMSAAStats& dmsaaStats() { return fContext->fDMSAAStats; } 111 #endif 112 113 GrSDFTControl getSDFTControl(bool useSDFTForSmallText) const; 114 115 /** 116 * Create a GrRecordingContext without a resource cache 117 */ 118 static sk_sp<GrRecordingContext> MakeDDL(sk_sp<GrContextThreadSafeProxy>); 119 120 private: GrRecordingContextPriv(GrRecordingContext * context)121 explicit GrRecordingContextPriv(GrRecordingContext* context) : fContext(context) {} 122 GrRecordingContextPriv(const GrRecordingContextPriv&) = delete; 123 GrRecordingContextPriv& operator=(const GrRecordingContextPriv&) = delete; 124 125 // No taking addresses of this type. 126 const GrRecordingContextPriv* operator&() const; 127 GrRecordingContextPriv* operator&(); 128 129 GrRecordingContext* fContext; 130 131 friend class GrRecordingContext; // to construct/copy this type. 132 }; 133 priv()134inline GrRecordingContextPriv GrRecordingContext::priv() { return GrRecordingContextPriv(this); } 135 priv()136inline const GrRecordingContextPriv GrRecordingContext::priv () const { // NOLINT(readability-const-return-type) 137 return GrRecordingContextPriv(const_cast<GrRecordingContext*>(this)); 138 } 139 140 #endif 141