blob: c4873bb98473b7aa4c912cf095507d9b6aaf3317 [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"
15
Brian Salomon52aacd62018-05-10 12:57:17 -040016/**
17 * Class that adds methods to GrContextThreadSafeProxy that are only intended for use internal to
18 * Skia. This class is purely a privileged window into GrContextThreadSafeProxy. It should never
19 * have additional data members or virtual methods.
20 */
21class GrContextThreadSafeProxyPriv {
22public:
Adlai Hollere219d1c2020-06-02 11:23:16 -040023 void init(sk_sp<const GrCaps> caps) const { fProxy->init(std::move(caps)); }
Brian Salomon52aacd62018-05-10 12:57:17 -040024
Adlai Hollere219d1c2020-06-02 11:23:16 -040025 bool matches(GrContext_Base* candidate) const {
26 return fProxy == candidate->threadSafeProxy().get();
27 }
Robert Phillipsfe0963c2019-02-07 13:25:07 -050028
Adlai Hollere219d1c2020-06-02 11:23:16 -040029 GrBackend backend() const { return fProxy->fBackend; }
30 const GrContextOptions& options() const { return fProxy->fOptions; }
31 uint32_t contextID() const { return fProxy->fContextID; }
Robert Phillipsc1541ae2019-02-04 12:05:37 -050032
Adlai Hollere219d1c2020-06-02 11:23:16 -040033 const GrCaps* caps() const { return fProxy->fCaps.get(); }
34 sk_sp<const GrCaps> refCaps() const { return fProxy->fCaps; }
Robert Phillipsc1541ae2019-02-04 12:05:37 -050035
Adlai Holler43b15792020-06-01 10:11:49 -040036 void abandonContext() { fProxy->abandonContext(); }
37 bool abandoned() const { return fProxy->abandoned(); }
38
Robert Phillipsbb606772019-02-04 17:50:57 -050039 // GrContextThreadSafeProxyPriv
Adlai Hollere219d1c2020-06-02 11:23:16 -040040 static sk_sp<GrContextThreadSafeProxy> Make(GrBackendApi, const GrContextOptions&);
Brian Salomon52aacd62018-05-10 12:57:17 -040041
42private:
43 explicit GrContextThreadSafeProxyPriv(GrContextThreadSafeProxy* proxy) : fProxy(proxy) {}
44 GrContextThreadSafeProxyPriv(const GrContextThreadSafeProxy&) = delete;
45 GrContextThreadSafeProxyPriv& operator=(const GrContextThreadSafeProxyPriv&) = delete;
46
47 // No taking addresses of this type.
48 const GrContextThreadSafeProxyPriv* operator&() const = delete;
49 GrContextThreadSafeProxyPriv* operator&() = delete;
50
51 GrContextThreadSafeProxy* fProxy;
52
53 friend class GrContextThreadSafeProxy; // to construct/copy this type.
54};
55
56inline GrContextThreadSafeProxyPriv GrContextThreadSafeProxy::priv() {
57 return GrContextThreadSafeProxyPriv(this);
58}
59
60inline const GrContextThreadSafeProxyPriv GrContextThreadSafeProxy::priv() const {
61 return GrContextThreadSafeProxyPriv(const_cast<GrContextThreadSafeProxy*>(this));
62}
63
64#endif