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 | |
| 11 | #include "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: |
| 18 | // from GrContext_Base |
Robert Phillips | fd0d970 | 2019-02-01 10:19:42 -0500 | [diff] [blame] | 19 | uint32_t contextID() const { return fContext->contextID(); } |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 20 | |
Robert Phillips | fe0963c | 2019-02-07 13:25:07 -0500 | [diff] [blame] | 21 | bool matches(GrContext_Base* candidate) const { return fContext->matches(candidate); } |
| 22 | |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 23 | const GrContextOptions& options() const { return fContext->options(); } |
| 24 | |
Robert Phillips | 7e90be9 | 2019-02-15 12:22:59 -0500 | [diff] [blame] | 25 | bool explicitlyAllocateGPUResources() const { |
| 26 | return fContext->explicitlyAllocateGPUResources(); |
| 27 | } |
| 28 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 29 | const GrCaps* caps() const { return fContext->caps(); } |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 30 | sk_sp<const GrCaps> refCaps() const; |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 31 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 32 | sk_sp<GrSkSLFPFactoryCache> fpFactoryCache(); |
| 33 | |
| 34 | GrImageContext* asImageContext() { return fContext->asImageContext(); } |
| 35 | GrRecordingContext* asRecordingContext() { return fContext->asRecordingContext(); } |
| 36 | GrContext* asDirectContext() { return fContext->asDirectContext(); } |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 37 | |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 38 | private: |
| 39 | explicit GrBaseContextPriv(GrContext_Base* context) : fContext(context) {} |
| 40 | GrBaseContextPriv(const GrBaseContextPriv&); // unimpl |
| 41 | GrBaseContextPriv& operator=(const GrBaseContextPriv&); // unimpl |
| 42 | |
| 43 | // No taking addresses of this type. |
| 44 | const GrBaseContextPriv* operator&() const; |
| 45 | GrBaseContextPriv* operator&(); |
| 46 | |
| 47 | GrContext_Base* fContext; |
| 48 | |
| 49 | friend class GrContext_Base; // to construct/copy this type. |
| 50 | }; |
| 51 | |
| 52 | inline GrBaseContextPriv GrContext_Base::priv() { return GrBaseContextPriv(this); } |
| 53 | |
| 54 | inline const GrBaseContextPriv GrContext_Base::priv () const { |
| 55 | return GrBaseContextPriv(const_cast<GrContext_Base*>(this)); |
| 56 | } |
| 57 | |
| 58 | #endif |