1/*
2 * Copyright 2021 Google LLC
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 skgpu_ContextPriv_DEFINED
9#define skgpu_ContextPriv_DEFINED
10
11#include "experimental/graphite/include/Context.h"
12
13namespace skgpu {
14
15class Gpu;
16class ResourceProvider;
17
18/** Class that adds methods to Context that are only intended for use internal to Skia.
19    This class is purely a privileged window into Context. It should never have additional
20    data members or virtual methods. */
21class ContextPriv {
22public:
23    Gpu* gpu();
24    const Gpu* gpu() const;
25
26    ResourceProvider* resourceProvider();
27
28private:
29    friend class Context; // to construct/copy this type.
30
31    explicit ContextPriv(Context* context) : fContext(context) {}
32
33    // Required until C++17 copy elision
34    ContextPriv(const ContextPriv&) = default;
35    ContextPriv& operator=(const ContextPriv&) = delete;
36
37    // No taking addresses of this type.
38    const ContextPriv* operator&() const;
39    ContextPriv *operator&();
40
41    Context* fContext;
42};
43
44inline ContextPriv Context::priv() { return ContextPriv(this); }
45
46// NOLINTNEXTLINE(readability-const-return-type)
47inline const ContextPriv Context::priv() const {
48    return ContextPriv(const_cast<Context *>(this));
49}
50
51} // namespace skgpu
52
53#endif // skgpu_ContextPriv_DEFINED
54