1 /* 2 * Copyright 2018 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 GrContextThreadSafeProxyPriv_DEFINED 9 #define GrContextThreadSafeProxyPriv_DEFINED 10 11 #include "include/gpu/GrContextThreadSafeProxy.h" 12 #include "include/private/GrContext_Base.h" 13 14 #include "src/gpu/GrCaps.h" 15 #include "src/gpu/text/GrTextBlobCache.h" 16 17 /** 18 * Class that adds methods to GrContextThreadSafeProxy that are only intended for use internal to 19 * Skia. This class is purely a privileged window into GrContextThreadSafeProxy. It should never 20 * have additional data members or virtual methods. 21 */ 22 class GrContextThreadSafeProxyPriv { 23 public: 24 void init(sk_sp<const GrCaps>, sk_sp<GrThreadSafePipelineBuilder>) const; 25 matches(GrContext_Base* candidate) const26 bool matches(GrContext_Base* candidate) const { 27 return fProxy == candidate->threadSafeProxy().get(); 28 } 29 backend() const30 GrBackend backend() const { return fProxy->fBackend; } options() const31 const GrContextOptions& options() const { return fProxy->fOptions; } contextID() const32 uint32_t contextID() const { return fProxy->fContextID; } 33 caps() const34 const GrCaps* caps() const { return fProxy->fCaps.get(); } refCaps() const35 sk_sp<const GrCaps> refCaps() const { return fProxy->fCaps; } 36 getTextBlobCache()37 GrTextBlobCache* getTextBlobCache() { return fProxy->fTextBlobCache.get(); } getTextBlobCache() const38 const GrTextBlobCache* getTextBlobCache() const { return fProxy->fTextBlobCache.get(); } 39 threadSafeCache()40 GrThreadSafeCache* threadSafeCache() { return fProxy->fThreadSafeCache.get(); } threadSafeCache() const41 const GrThreadSafeCache* threadSafeCache() const { return fProxy->fThreadSafeCache.get(); } 42 abandonContext()43 void abandonContext() { fProxy->abandonContext(); } abandoned() const44 bool abandoned() const { return fProxy->abandoned(); } 45 46 // GrContextThreadSafeProxyPriv 47 static sk_sp<GrContextThreadSafeProxy> Make(GrBackendApi, const GrContextOptions&); 48 49 private: GrContextThreadSafeProxyPriv(GrContextThreadSafeProxy* proxy)50 explicit GrContextThreadSafeProxyPriv(GrContextThreadSafeProxy* proxy) : fProxy(proxy) {} 51 // Required until C++17 copy elision 52 GrContextThreadSafeProxyPriv(const GrContextThreadSafeProxyPriv&) = default; 53 GrContextThreadSafeProxyPriv& operator=(const GrContextThreadSafeProxyPriv&) = delete; 54 55 // No taking addresses of this type. 56 const GrContextThreadSafeProxyPriv* operator&() const = delete; 57 GrContextThreadSafeProxyPriv* operator&() = delete; 58 59 GrContextThreadSafeProxy* fProxy; 60 61 friend class GrContextThreadSafeProxy; // to construct/copy this type. 62 }; 63 priv()64inline GrContextThreadSafeProxyPriv GrContextThreadSafeProxy::priv() { 65 return GrContextThreadSafeProxyPriv(this); 66 } 67 priv() const68inline const GrContextThreadSafeProxyPriv GrContextThreadSafeProxy::priv() const { // NOLINT(readability-const-return-type) 69 return GrContextThreadSafeProxyPriv(const_cast<GrContextThreadSafeProxy*>(this)); 70 } 71 72 #endif 73