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
11#include "include/gpu/GrContextThreadSafeProxy.h"
12#include "include/private/GrContext_Base.h"
13
14#include "src/gpu/GrCaps.h"
15#include "src/gpu/text/GrTextBlobCache.h"
16
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 */
22class GrContextThreadSafeProxyPriv {
23public:
24 void init(sk_sp<const GrCaps> caps) const {
25 fProxy->init(std::move(caps));
26 }
27
28 bool matches(GrContext_Base* candidate) const {
29 return fProxy == candidate->threadSafeProxy().get();
30 }
31
32 GrBackend backend() const { return fProxy->fBackend; }
33 const GrContextOptions& options() const { return fProxy->fOptions; }
34 uint32_t contextID() const { return fProxy->fContextID; }
35
36 const GrCaps* caps() const { return fProxy->fCaps.get(); }
37 sk_sp<const GrCaps> refCaps() const { return fProxy->fCaps; }
38
39 GrTextBlobCache* getTextBlobCache() { return fProxy->fTextBlobCache.get(); }
40 const GrTextBlobCache* getTextBlobCache() const { return fProxy->fTextBlobCache.get(); }
41
42 void abandonContext() { fProxy->abandonContext(); }
43 bool abandoned() const { return fProxy->abandoned(); }
44
45 // GrContextThreadSafeProxyPriv
46 static sk_sp<GrContextThreadSafeProxy> Make(GrBackendApi, const GrContextOptions&);
47
48private:
49 explicit GrContextThreadSafeProxyPriv(GrContextThreadSafeProxy* proxy) : fProxy(proxy) {}
50 GrContextThreadSafeProxyPriv(const GrContextThreadSafeProxy&) = delete;
51 GrContextThreadSafeProxyPriv& operator=(const GrContextThreadSafeProxyPriv&) = delete;
52
53 // No taking addresses of this type.
54 const GrContextThreadSafeProxyPriv* operator&() const = delete;
55 GrContextThreadSafeProxyPriv* operator&() = delete;
56
57 GrContextThreadSafeProxy* fProxy;
58
59 friend class GrContextThreadSafeProxy; // to construct/copy this type.
60};
61
62inline GrContextThreadSafeProxyPriv GrContextThreadSafeProxy::priv() {
63 return GrContextThreadSafeProxyPriv(this);
64}
65
66inline const GrContextThreadSafeProxyPriv GrContextThreadSafeProxy::priv() const { // NOLINT(readability-const-return-type)
67 return GrContextThreadSafeProxyPriv(const_cast<GrContextThreadSafeProxy*>(this));
68}
69
70#endif
71