blob: 5e24adef7cfa4b85d4f69780ffb0bfcf13858047 [file] [log] [blame]
Robert Phillips4217ea72019-01-30 13:08:28 -05001/*
2 * Copyright 2019 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 GrBaseContextPriv_DEFINED
9#define GrBaseContextPriv_DEFINED
10
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/private/GrContext_Base.h"
Robert Phillips4217ea72019-01-30 13:08:28 -050012
13/** Class that exposes methods on GrContext_Base that are only intended for use internal to Skia.
14 This class is purely a privileged window into GrContext_Base. It should never have
15 additional data members or virtual methods. */
16class GrBaseContextPriv {
17public:
Robert Phillipsea3489a2021-08-02 13:10:57 -040018 GrContext_Base* context() { return fContext; }
19 const GrContext_Base* context() const { return fContext; }
Robert Phillips4217ea72019-01-30 13:08:28 -050020
Robert Phillipsea3489a2021-08-02 13:10:57 -040021 uint32_t contextID() const { return this->context()->contextID(); }
Robert Phillipsfe0963c2019-02-07 13:25:07 -050022
Robert Phillipsea3489a2021-08-02 13:10:57 -040023 bool matches(GrContext_Base* candidate) const { return this->context()->matches(candidate); }
Robert Phillipsc1541ae2019-02-04 12:05:37 -050024
Robert Phillipsea3489a2021-08-02 13:10:57 -040025 const GrContextOptions& options() const { return this->context()->options(); }
26
27 const GrCaps* caps() const { return this->context()->caps(); }
Robert Phillipsa41c6852019-02-07 10:44:10 -050028 sk_sp<const GrCaps> refCaps() const;
Robert Phillipsbb606772019-02-04 17:50:57 -050029
Robert Phillipsea3489a2021-08-02 13:10:57 -040030 GrImageContext* asImageContext() { return this->context()->asImageContext(); }
31 GrRecordingContext* asRecordingContext() { return this->context()->asRecordingContext(); }
32 GrDirectContext* asDirectContext() { return this->context()->asDirectContext(); }
Robert Phillipsbb606772019-02-04 17:50:57 -050033
Brian Osmanbd4f8722020-03-06 15:23:54 -050034 GrContextOptions::ShaderErrorHandler* getShaderErrorHandler() const;
35
Robert Phillipsea3489a2021-08-02 13:10:57 -040036protected:
Robert Phillips4217ea72019-01-30 13:08:28 -050037 explicit GrBaseContextPriv(GrContext_Base* context) : fContext(context) {}
Robert Phillipsea3489a2021-08-02 13:10:57 -040038
39 GrContext_Base* fContext;
40
41private:
John Stilesb35c3b82020-08-06 19:58:52 -040042 GrBaseContextPriv(const GrBaseContextPriv&) = delete;
43 GrBaseContextPriv& operator=(const GrBaseContextPriv&) = delete;
Robert Phillips4217ea72019-01-30 13:08:28 -050044
45 // No taking addresses of this type.
46 const GrBaseContextPriv* operator&() const;
47 GrBaseContextPriv* operator&();
48
Robert Phillips4217ea72019-01-30 13:08:28 -050049 friend class GrContext_Base; // to construct/copy this type.
50};
51
52inline GrBaseContextPriv GrContext_Base::priv() { return GrBaseContextPriv(this); }
53
John Stilesec9b4aa2020-08-07 13:05:14 -040054inline const GrBaseContextPriv GrContext_Base::priv () const { // NOLINT(readability-const-return-type)
Robert Phillips4217ea72019-01-30 13:08:28 -050055 return GrBaseContextPriv(const_cast<GrContext_Base*>(this));
56}
57
58#endif