Brian Salomon | 52aacd6 | 2018-05-10 12:57:17 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 GrContextThreadSafeProxyPriv_DEFINED |
| 9 | #define GrContextThreadSafeProxyPriv_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/gpu/GrContextThreadSafeProxy.h" |
Adlai Holler | e219d1c | 2020-06-02 11:23:16 -0400 | [diff] [blame] | 12 | #include "include/private/GrContext_Base.h" |
Brian Salomon | 52aacd6 | 2018-05-10 12:57:17 -0400 | [diff] [blame] | 13 | |
Hal Canary | 02eefbe | 2019-06-26 13:54:14 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrCaps.h" |
Herb Derby | bc4d13a | 2020-06-25 15:35:23 -0400 | [diff] [blame] | 15 | #include "src/gpu/text/GrTextBlobCache.h" |
Hal Canary | 02eefbe | 2019-06-26 13:54:14 -0400 | [diff] [blame] | 16 | |
Brian Salomon | 52aacd6 | 2018-05-10 12:57:17 -0400 | [diff] [blame] | 17 | /** |
| 18 | * Class that adds methods to GrContextThreadSafeProxy that are only intended for use internal to |
| 19 | * Skia. This class is purely a privileged window into GrContextThreadSafeProxy. It should never |
| 20 | * have additional data members or virtual methods. |
| 21 | */ |
| 22 | class GrContextThreadSafeProxyPriv { |
| 23 | public: |
Robert Phillips | ae67c52 | 2021-03-03 11:03:38 -0500 | [diff] [blame^] | 24 | void init(sk_sp<const GrCaps>, sk_sp<GrThreadSafePipelineBuilder>) const; |
Brian Salomon | 52aacd6 | 2018-05-10 12:57:17 -0400 | [diff] [blame] | 25 | |
Adlai Holler | e219d1c | 2020-06-02 11:23:16 -0400 | [diff] [blame] | 26 | bool matches(GrContext_Base* candidate) const { |
| 27 | return fProxy == candidate->threadSafeProxy().get(); |
| 28 | } |
Robert Phillips | fe0963c | 2019-02-07 13:25:07 -0500 | [diff] [blame] | 29 | |
Adlai Holler | e219d1c | 2020-06-02 11:23:16 -0400 | [diff] [blame] | 30 | GrBackend backend() const { return fProxy->fBackend; } |
| 31 | const GrContextOptions& options() const { return fProxy->fOptions; } |
| 32 | uint32_t contextID() const { return fProxy->fContextID; } |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 33 | |
Adlai Holler | e219d1c | 2020-06-02 11:23:16 -0400 | [diff] [blame] | 34 | const GrCaps* caps() const { return fProxy->fCaps.get(); } |
| 35 | sk_sp<const GrCaps> refCaps() const { return fProxy->fCaps; } |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 36 | |
Herb Derby | bc4d13a | 2020-06-25 15:35:23 -0400 | [diff] [blame] | 37 | GrTextBlobCache* getTextBlobCache() { return fProxy->fTextBlobCache.get(); } |
| 38 | const GrTextBlobCache* getTextBlobCache() const { return fProxy->fTextBlobCache.get(); } |
| 39 | |
Robert Phillips | d464feb | 2020-10-08 11:00:02 -0400 | [diff] [blame] | 40 | GrThreadSafeCache* threadSafeCache() { return fProxy->fThreadSafeCache.get(); } |
| 41 | const GrThreadSafeCache* threadSafeCache() const { return fProxy->fThreadSafeCache.get(); } |
Robert Phillips | 12d06a3 | 2020-09-16 12:31:34 -0400 | [diff] [blame] | 42 | |
Adlai Holler | 43b1579 | 2020-06-01 10:11:49 -0400 | [diff] [blame] | 43 | void abandonContext() { fProxy->abandonContext(); } |
| 44 | bool abandoned() const { return fProxy->abandoned(); } |
| 45 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 46 | // GrContextThreadSafeProxyPriv |
Adlai Holler | e219d1c | 2020-06-02 11:23:16 -0400 | [diff] [blame] | 47 | static sk_sp<GrContextThreadSafeProxy> Make(GrBackendApi, const GrContextOptions&); |
Brian Salomon | 52aacd6 | 2018-05-10 12:57:17 -0400 | [diff] [blame] | 48 | |
| 49 | private: |
| 50 | explicit GrContextThreadSafeProxyPriv(GrContextThreadSafeProxy* proxy) : fProxy(proxy) {} |
| 51 | GrContextThreadSafeProxyPriv(const GrContextThreadSafeProxy&) = delete; |
| 52 | GrContextThreadSafeProxyPriv& operator=(const GrContextThreadSafeProxyPriv&) = delete; |
| 53 | |
| 54 | // No taking addresses of this type. |
| 55 | const GrContextThreadSafeProxyPriv* operator&() const = delete; |
| 56 | GrContextThreadSafeProxyPriv* operator&() = delete; |
| 57 | |
| 58 | GrContextThreadSafeProxy* fProxy; |
| 59 | |
| 60 | friend class GrContextThreadSafeProxy; // to construct/copy this type. |
| 61 | }; |
| 62 | |
| 63 | inline GrContextThreadSafeProxyPriv GrContextThreadSafeProxy::priv() { |
| 64 | return GrContextThreadSafeProxyPriv(this); |
| 65 | } |
| 66 | |
John Stiles | ec9b4aa | 2020-08-07 13:05:14 -0400 | [diff] [blame] | 67 | inline const GrContextThreadSafeProxyPriv GrContextThreadSafeProxy::priv() const { // NOLINT(readability-const-return-type) |
Brian Salomon | 52aacd6 | 2018-05-10 12:57:17 -0400 | [diff] [blame] | 68 | return GrContextThreadSafeProxyPriv(const_cast<GrContextThreadSafeProxy*>(this)); |
| 69 | } |
| 70 | |
| 71 | #endif |