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: |
Herb Derby | bc4d13a | 2020-06-25 15:35:23 -0400 | [diff] [blame] | 24 | void init(sk_sp<const GrCaps> caps) const { |
| 25 | fProxy->init(std::move(caps)); |
| 26 | } |
Brian Salomon | 52aacd6 | 2018-05-10 12:57:17 -0400 | [diff] [blame] | 27 | |
Adlai Holler | e219d1c | 2020-06-02 11:23:16 -0400 | [diff] [blame] | 28 | bool matches(GrContext_Base* candidate) const { |
| 29 | return fProxy == candidate->threadSafeProxy().get(); |
| 30 | } |
Robert Phillips | fe0963c | 2019-02-07 13:25:07 -0500 | [diff] [blame] | 31 | |
Adlai Holler | e219d1c | 2020-06-02 11:23:16 -0400 | [diff] [blame] | 32 | GrBackend backend() const { return fProxy->fBackend; } |
| 33 | const GrContextOptions& options() const { return fProxy->fOptions; } |
| 34 | uint32_t contextID() const { return fProxy->fContextID; } |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 35 | |
Adlai Holler | e219d1c | 2020-06-02 11:23:16 -0400 | [diff] [blame] | 36 | const GrCaps* caps() const { return fProxy->fCaps.get(); } |
| 37 | sk_sp<const GrCaps> refCaps() const { return fProxy->fCaps; } |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 38 | |
Herb Derby | bc4d13a | 2020-06-25 15:35:23 -0400 | [diff] [blame] | 39 | GrTextBlobCache* getTextBlobCache() { return fProxy->fTextBlobCache.get(); } |
| 40 | const GrTextBlobCache* getTextBlobCache() const { return fProxy->fTextBlobCache.get(); } |
| 41 | |
Robert Phillips | d464feb | 2020-10-08 11:00:02 -0400 | [diff] [blame] | 42 | GrThreadSafeCache* threadSafeCache() { return fProxy->fThreadSafeCache.get(); } |
| 43 | const GrThreadSafeCache* threadSafeCache() const { return fProxy->fThreadSafeCache.get(); } |
Robert Phillips | 12d06a3 | 2020-09-16 12:31:34 -0400 | [diff] [blame] | 44 | |
Adlai Holler | 43b1579 | 2020-06-01 10:11:49 -0400 | [diff] [blame] | 45 | void abandonContext() { fProxy->abandonContext(); } |
| 46 | bool abandoned() const { return fProxy->abandoned(); } |
| 47 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 48 | // GrContextThreadSafeProxyPriv |
Adlai Holler | e219d1c | 2020-06-02 11:23:16 -0400 | [diff] [blame] | 49 | static sk_sp<GrContextThreadSafeProxy> Make(GrBackendApi, const GrContextOptions&); |
Brian Salomon | 52aacd6 | 2018-05-10 12:57:17 -0400 | [diff] [blame] | 50 | |
| 51 | private: |
| 52 | explicit GrContextThreadSafeProxyPriv(GrContextThreadSafeProxy* proxy) : fProxy(proxy) {} |
| 53 | GrContextThreadSafeProxyPriv(const GrContextThreadSafeProxy&) = delete; |
| 54 | GrContextThreadSafeProxyPriv& operator=(const GrContextThreadSafeProxyPriv&) = delete; |
| 55 | |
| 56 | // No taking addresses of this type. |
| 57 | const GrContextThreadSafeProxyPriv* operator&() const = delete; |
| 58 | GrContextThreadSafeProxyPriv* operator&() = delete; |
| 59 | |
| 60 | GrContextThreadSafeProxy* fProxy; |
| 61 | |
| 62 | friend class GrContextThreadSafeProxy; // to construct/copy this type. |
| 63 | }; |
| 64 | |
| 65 | inline GrContextThreadSafeProxyPriv GrContextThreadSafeProxy::priv() { |
| 66 | return GrContextThreadSafeProxyPriv(this); |
| 67 | } |
| 68 | |
John Stiles | ec9b4aa | 2020-08-07 13:05:14 -0400 | [diff] [blame] | 69 | inline const GrContextThreadSafeProxyPriv GrContextThreadSafeProxy::priv() const { // NOLINT(readability-const-return-type) |
Brian Salomon | 52aacd6 | 2018-05-10 12:57:17 -0400 | [diff] [blame] | 70 | return GrContextThreadSafeProxyPriv(const_cast<GrContextThreadSafeProxy*>(this)); |
| 71 | } |
| 72 | |
| 73 | #endif |