blob: 606aa16ee068993dd8ab2f829c8baf8c02e5ea3a [file] [log] [blame]
Brian Salomon52aacd62018-05-10 12:57:17 -04001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/gpu/GrContextThreadSafeProxy.h"
Adlai Hollere219d1c2020-06-02 11:23:16 -040012#include "include/private/GrContext_Base.h"
Brian Salomon52aacd62018-05-10 12:57:17 -040013
Hal Canary02eefbe2019-06-26 13:54:14 -040014#include "src/gpu/GrCaps.h"
Herb Derbybc4d13a2020-06-25 15:35:23 -040015#include "src/gpu/text/GrTextBlobCache.h"
Hal Canary02eefbe2019-06-26 13:54:14 -040016
Brian Salomon52aacd62018-05-10 12:57:17 -040017/**
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 */
22class GrContextThreadSafeProxyPriv {
23public:
Herb Derbybc4d13a2020-06-25 15:35:23 -040024 void init(sk_sp<const GrCaps> caps) const {
25 fProxy->init(std::move(caps));
26 }
Brian Salomon52aacd62018-05-10 12:57:17 -040027
Adlai Hollere219d1c2020-06-02 11:23:16 -040028 bool matches(GrContext_Base* candidate) const {
29 return fProxy == candidate->threadSafeProxy().get();
30 }
Robert Phillipsfe0963c2019-02-07 13:25:07 -050031
Adlai Hollere219d1c2020-06-02 11:23:16 -040032 GrBackend backend() const { return fProxy->fBackend; }
33 const GrContextOptions& options() const { return fProxy->fOptions; }
34 uint32_t contextID() const { return fProxy->fContextID; }
Robert Phillipsc1541ae2019-02-04 12:05:37 -050035
Adlai Hollere219d1c2020-06-02 11:23:16 -040036 const GrCaps* caps() const { return fProxy->fCaps.get(); }
37 sk_sp<const GrCaps> refCaps() const { return fProxy->fCaps; }
Robert Phillipsc1541ae2019-02-04 12:05:37 -050038
Herb Derbybc4d13a2020-06-25 15:35:23 -040039 GrTextBlobCache* getTextBlobCache() { return fProxy->fTextBlobCache.get(); }
40 const GrTextBlobCache* getTextBlobCache() const { return fProxy->fTextBlobCache.get(); }
41
Robert Phillipsd464feb2020-10-08 11:00:02 -040042 GrThreadSafeCache* threadSafeCache() { return fProxy->fThreadSafeCache.get(); }
43 const GrThreadSafeCache* threadSafeCache() const { return fProxy->fThreadSafeCache.get(); }
Robert Phillips12d06a32020-09-16 12:31:34 -040044
Adlai Holler43b15792020-06-01 10:11:49 -040045 void abandonContext() { fProxy->abandonContext(); }
46 bool abandoned() const { return fProxy->abandoned(); }
47
Robert Phillipsbb606772019-02-04 17:50:57 -050048 // GrContextThreadSafeProxyPriv
Adlai Hollere219d1c2020-06-02 11:23:16 -040049 static sk_sp<GrContextThreadSafeProxy> Make(GrBackendApi, const GrContextOptions&);
Brian Salomon52aacd62018-05-10 12:57:17 -040050
51private:
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
65inline GrContextThreadSafeProxyPriv GrContextThreadSafeProxy::priv() {
66 return GrContextThreadSafeProxyPriv(this);
67}
68
John Stilesec9b4aa2020-08-07 13:05:14 -040069inline const GrContextThreadSafeProxyPriv GrContextThreadSafeProxy::priv() const { // NOLINT(readability-const-return-type)
Brian Salomon52aacd62018-05-10 12:57:17 -040070 return GrContextThreadSafeProxyPriv(const_cast<GrContextThreadSafeProxy*>(this));
71}
72
73#endif