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