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 */ 22class GrContextThreadSafeProxyPriv { 23public: 24 void init(sk_sp<const GrCaps>, sk_sp<GrThreadSafePipelineBuilder>) const; 25 26 bool matches(GrContext_Base* candidate) const { 27 return fProxy == candidate->threadSafeProxy().get(); 28 } 29 30 GrBackend backend() const { return fProxy->fBackend; } 31 const GrContextOptions& options() const { return fProxy->fOptions; } 32 uint32_t contextID() const { return fProxy->fContextID; } 33 34 const GrCaps* caps() const { return fProxy->fCaps.get(); } 35 sk_sp<const GrCaps> refCaps() const { return fProxy->fCaps; } 36 37 GrTextBlobCache* getTextBlobCache() { return fProxy->fTextBlobCache.get(); } 38 const GrTextBlobCache* getTextBlobCache() const { return fProxy->fTextBlobCache.get(); } 39 40 GrThreadSafeCache* threadSafeCache() { return fProxy->fThreadSafeCache.get(); } 41 const GrThreadSafeCache* threadSafeCache() const { return fProxy->fThreadSafeCache.get(); } 42 43 void abandonContext() { fProxy->abandonContext(); } 44 bool abandoned() const { return fProxy->abandoned(); } 45 46 // GrContextThreadSafeProxyPriv 47 static sk_sp<GrContextThreadSafeProxy> Make(GrBackendApi, const GrContextOptions&); 48 49private: 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 64inline GrContextThreadSafeProxyPriv GrContextThreadSafeProxy::priv() { 65 return GrContextThreadSafeProxyPriv(this); 66} 67 68inline const GrContextThreadSafeProxyPriv GrContextThreadSafeProxy::priv() const { // NOLINT(readability-const-return-type) 69 return GrContextThreadSafeProxyPriv(const_cast<GrContextThreadSafeProxy*>(this)); 70} 71 72#endif 73