| 1 |
/* |
| 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 |
|
| 11 |
#include "include/core/SkRefCnt.h" |
| 12 |
#include "include/gpu/ganesh/GrContextOptions.h" |
| 13 |
#include "include/private/gpu/ganesh/GrContext_Base.h" |
| 14 |
|
| 15 |
#include <cstdint> |
| 16 |
|
| 17 |
class GrCaps; |
| 18 |
class GrDirectContext; |
| 19 |
class GrImageContext; |
| 20 |
class GrRecordingContext; |
| 21 |
|
| 22 |
/** Class that exposes methods on GrContext_Base that are only intended for use internal to Skia. |
| 23 |
This class is purely a privileged window into GrContext_Base. It should never have |
| 24 |
additional data members or virtual methods. */ |
| 25 |
class GrBaseContextPriv { |
| 26 |
public: |
| 27 |
GrContext_Base* context() { return fContext; } |
| 28 |
const GrContext_Base* context() const { return fContext; } |
| 29 |
|
| 30 |
uint32_t contextID() const { return this->context()->contextID(); } |
| 31 |
|
| 32 |
bool matches(GrContext_Base* candidate) const { return this->context()->matches(candidate); } |
| 33 |
|
| 34 |
const GrContextOptions& options() const { return this->context()->options(); } |
| 35 |
|
| 36 |
const GrCaps* caps() const { return this->context()->caps(); } |
| 37 |
sk_sp<const GrCaps> refCaps() const; |
| 38 |
|
| 39 |
GrImageContext* asImageContext() { return this->context()->asImageContext(); } |
| 40 |
GrRecordingContext* asRecordingContext() { return this->context()->asRecordingContext(); } |
| 41 |
GrDirectContext* asDirectContext() { return this->context()->asDirectContext(); } |
| 42 |
|
| 43 |
GrContextOptions::ShaderErrorHandler* getShaderErrorHandler() const; |
| 44 |
|
| 45 |
protected: |
| 46 |
explicit GrBaseContextPriv(GrContext_Base* context) : fContext(context) {} |
| 47 |
|
| 48 |
GrContext_Base* fContext; |
| 49 |
|
| 50 |
private: |
| 51 |
GrBaseContextPriv& operator=(const GrBaseContextPriv&) = delete; |
| 52 |
|
| 53 |
// No taking addresses of this type. |
| 54 |
const GrBaseContextPriv* operator&() const; |
| 55 |
GrBaseContextPriv* operator&(); |
| 56 |
|
| 57 |
friend class GrContext_Base; // to construct/copy this type. |
| 58 |
}; |
| 59 |
|
| 60 |
inline GrBaseContextPriv GrContext_Base::priv() { return GrBaseContextPriv(this); } |
| 61 |
|
| 62 |
inline const GrBaseContextPriv GrContext_Base::priv () const { // NOLINT(readability-const-return-type) |
| 63 |
return GrBaseContextPriv(const_cast<GrContext_Base*>(this)); |
| 64 |
} |
| 65 |
|
| 66 |
#endif |