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 GrContext_Base_DEFINED |
| 9 | #define GrContext_Base_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkRefCnt.h" |
| 12 | #include "include/gpu/GrContextOptions.h" |
| 13 | #include "include/gpu/GrTypes.h" |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 14 | |
| 15 | class GrBaseContextPriv; |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 16 | class GrCaps; |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 17 | class GrContext; |
| 18 | class GrImageContext; |
| 19 | class GrRecordingContext; |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 20 | class GrSkSLFPFactoryCache; |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 21 | |
| 22 | class SK_API GrContext_Base : public SkRefCnt { |
| 23 | public: |
| 24 | virtual ~GrContext_Base(); |
| 25 | |
| 26 | /* |
| 27 | * The 3D API backing this context |
| 28 | */ |
| 29 | GrBackendApi backend() const { return fBackend; } |
| 30 | |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 31 | // Provides access to functions that aren't part of the public API. |
| 32 | GrBaseContextPriv priv(); |
| 33 | const GrBaseContextPriv priv() const; |
| 34 | |
| 35 | protected: |
| 36 | friend class GrBaseContextPriv; // for hidden functions |
| 37 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 38 | GrContext_Base(GrBackendApi backend, const GrContextOptions& options, uint32_t contextID); |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 39 | |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 40 | virtual bool init(sk_sp<const GrCaps>, sk_sp<GrSkSLFPFactoryCache>); |
| 41 | |
Robert Phillips | fd0d970 | 2019-02-01 10:19:42 -0500 | [diff] [blame] | 42 | /** |
| 43 | * An identifier for this context. The id is used by all compatible contexts. For example, |
| 44 | * if SkImages are created on one thread using an image creation context, then fed into a |
| 45 | * DDL Recorder on second thread (which has a recording context) and finally replayed on |
| 46 | * a third thread with a direct context, then all three contexts will report the same id. |
| 47 | * It is an error for an image to be used with contexts that report different ids. |
| 48 | */ |
| 49 | uint32_t contextID() const { return fContextID; } |
| 50 | |
Robert Phillips | fe0963c | 2019-02-07 13:25:07 -0500 | [diff] [blame] | 51 | bool matches(GrContext_Base* candidate) const { |
| 52 | return candidate->contextID() == this->contextID(); |
| 53 | } |
| 54 | |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 55 | /* |
| 56 | * The options in effect for this context |
| 57 | */ |
| 58 | const GrContextOptions& options() const { return fOptions; } |
| 59 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 60 | const GrCaps* caps() const; |
| 61 | sk_sp<const GrCaps> refCaps() const; |
| 62 | |
| 63 | sk_sp<GrSkSLFPFactoryCache> fpFactoryCache(); |
| 64 | |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 65 | virtual GrImageContext* asImageContext() { return nullptr; } |
| 66 | virtual GrRecordingContext* asRecordingContext() { return nullptr; } |
| 67 | virtual GrContext* asDirectContext() { return nullptr; } |
| 68 | |
| 69 | private: |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 70 | const GrBackendApi fBackend; |
| 71 | const GrContextOptions fOptions; |
| 72 | const uint32_t fContextID; |
| 73 | sk_sp<const GrCaps> fCaps; |
| 74 | sk_sp<GrSkSLFPFactoryCache> fFPFactoryCache; |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 75 | |
| 76 | typedef SkRefCnt INHERITED; |
| 77 | }; |
| 78 | |
| 79 | #endif |