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 GrBaseContextPriv_DEFINED 9 #define GrBaseContextPriv_DEFINED 10 11 #include "include/private/GrContext_Base.h" 12 13 /** Class that exposes methods on GrContext_Base that are only intended for use internal to Skia. 14 This class is purely a privileged window into GrContext_Base. It should never have 15 additional data members or virtual methods. */ 16 class GrBaseContextPriv { 17 public: context()18 GrContext_Base* context() { return fContext; } context()19 const GrContext_Base* context() const { return fContext; } 20 contextID()21 uint32_t contextID() const { return this->context()->contextID(); } 22 matches(GrContext_Base * candidate)23 bool matches(GrContext_Base* candidate) const { return this->context()->matches(candidate); } 24 options()25 const GrContextOptions& options() const { return this->context()->options(); } 26 caps()27 const GrCaps* caps() const { return this->context()->caps(); } 28 sk_sp<const GrCaps> refCaps() const; 29 asImageContext()30 GrImageContext* asImageContext() { return this->context()->asImageContext(); } asRecordingContext()31 GrRecordingContext* asRecordingContext() { return this->context()->asRecordingContext(); } asDirectContext()32 GrDirectContext* asDirectContext() { return this->context()->asDirectContext(); } 33 34 GrContextOptions::ShaderErrorHandler* getShaderErrorHandler() const; 35 36 protected: 37 // Required until C++17 copy elision 38 GrBaseContextPriv(const GrBaseContextPriv&) = default; GrBaseContextPriv(GrContext_Base * context)39 explicit GrBaseContextPriv(GrContext_Base* context) : fContext(context) {} 40 41 GrContext_Base* fContext; 42 43 private: 44 GrBaseContextPriv& operator=(const GrBaseContextPriv&) = delete; 45 46 // No taking addresses of this type. 47 const GrBaseContextPriv* operator&() const; 48 GrBaseContextPriv* operator&(); 49 50 friend class GrContext_Base; // to construct/copy this type. 51 }; 52 priv()53inline GrBaseContextPriv GrContext_Base::priv() { return GrBaseContextPriv(this); } 54 priv()55inline const GrBaseContextPriv GrContext_Base::priv () const { // NOLINT(readability-const-return-type) 56 return GrBaseContextPriv(const_cast<GrContext_Base*>(this)); 57 } 58 59 #endif 60