Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/private/GrContext_Base.h" |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 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: |
Robert Phillips | ea3489a | 2021-08-02 13:10:57 -0400 | [diff] [blame] | 18 | GrContext_Base* context() { return fContext; } |
| 19 | const GrContext_Base* context() const { return fContext; } |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 20 | |
Robert Phillips | ea3489a | 2021-08-02 13:10:57 -0400 | [diff] [blame] | 21 | uint32_t contextID() const { return this->context()->contextID(); } |
Robert Phillips | fe0963c | 2019-02-07 13:25:07 -0500 | [diff] [blame] | 22 | |
Robert Phillips | ea3489a | 2021-08-02 13:10:57 -0400 | [diff] [blame] | 23 | bool matches(GrContext_Base* candidate) const { return this->context()->matches(candidate); } |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 24 | |
Robert Phillips | ea3489a | 2021-08-02 13:10:57 -0400 | [diff] [blame] | 25 | const GrContextOptions& options() const { return this->context()->options(); } |
| 26 | |
| 27 | const GrCaps* caps() const { return this->context()->caps(); } |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 28 | sk_sp<const GrCaps> refCaps() const; |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 29 | |
Robert Phillips | ea3489a | 2021-08-02 13:10:57 -0400 | [diff] [blame] | 30 | GrImageContext* asImageContext() { return this->context()->asImageContext(); } |
| 31 | GrRecordingContext* asRecordingContext() { return this->context()->asRecordingContext(); } |
| 32 | GrDirectContext* asDirectContext() { return this->context()->asDirectContext(); } |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 33 | |
Brian Osman | bd4f872 | 2020-03-06 15:23:54 -0500 | [diff] [blame] | 34 | GrContextOptions::ShaderErrorHandler* getShaderErrorHandler() const; |
| 35 | |
Robert Phillips | ea3489a | 2021-08-02 13:10:57 -0400 | [diff] [blame] | 36 | protected: |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 37 | explicit GrBaseContextPriv(GrContext_Base* context) : fContext(context) {} |
Robert Phillips | ea3489a | 2021-08-02 13:10:57 -0400 | [diff] [blame] | 38 | |
| 39 | GrContext_Base* fContext; |
| 40 | |
| 41 | private: |
John Stiles | b35c3b8 | 2020-08-06 19:58:52 -0400 | [diff] [blame] | 42 | GrBaseContextPriv(const GrBaseContextPriv&) = delete; |
| 43 | GrBaseContextPriv& operator=(const GrBaseContextPriv&) = delete; |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 44 | |
| 45 | // No taking addresses of this type. |
| 46 | const GrBaseContextPriv* operator&() const; |
| 47 | GrBaseContextPriv* operator&(); |
| 48 | |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 49 | friend class GrContext_Base; // to construct/copy this type. |
| 50 | }; |
| 51 | |
| 52 | inline GrBaseContextPriv GrContext_Base::priv() { return GrBaseContextPriv(this); } |
| 53 | |
John Stiles | ec9b4aa | 2020-08-07 13:05:14 -0400 | [diff] [blame] | 54 | inline const GrBaseContextPriv GrContext_Base::priv () const { // NOLINT(readability-const-return-type) |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 55 | return GrBaseContextPriv(const_cast<GrContext_Base*>(this)); |
| 56 | } |
| 57 | |
| 58 | #endif |