GrBaseContextPriv.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #ifndef GrBaseContextPriv_DEFINED
  8. #define GrBaseContextPriv_DEFINED
  9. #include "include/private/GrContext_Base.h"
  10. /** Class that exposes methods on GrContext_Base that are only intended for use internal to Skia.
  11. This class is purely a privileged window into GrContext_Base. It should never have
  12. additional data members or virtual methods. */
  13. class GrBaseContextPriv {
  14. public:
  15. // from GrContext_Base
  16. uint32_t contextID() const { return fContext->contextID(); }
  17. bool matches(GrContext_Base* candidate) const { return fContext->matches(candidate); }
  18. const GrContextOptions& options() const { return fContext->options(); }
  19. const GrCaps* caps() const { return fContext->caps(); }
  20. sk_sp<const GrCaps> refCaps() const;
  21. sk_sp<GrSkSLFPFactoryCache> fpFactoryCache();
  22. GrImageContext* asImageContext() { return fContext->asImageContext(); }
  23. GrRecordingContext* asRecordingContext() { return fContext->asRecordingContext(); }
  24. GrContext* asDirectContext() { return fContext->asDirectContext(); }
  25. private:
  26. explicit GrBaseContextPriv(GrContext_Base* context) : fContext(context) {}
  27. GrBaseContextPriv(const GrBaseContextPriv&); // unimpl
  28. GrBaseContextPriv& operator=(const GrBaseContextPriv&); // unimpl
  29. // No taking addresses of this type.
  30. const GrBaseContextPriv* operator&() const;
  31. GrBaseContextPriv* operator&();
  32. GrContext_Base* fContext;
  33. friend class GrContext_Base; // to construct/copy this type.
  34. };
  35. inline GrBaseContextPriv GrContext_Base::priv() { return GrBaseContextPriv(this); }
  36. inline const GrBaseContextPriv GrContext_Base::priv () const {
  37. return GrBaseContextPriv(const_cast<GrContext_Base*>(this));
  38. }
  39. #endif