GrContext_Base.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 GrContext_Base_DEFINED
  8. #define GrContext_Base_DEFINED
  9. #include "include/core/SkRefCnt.h"
  10. #include "include/gpu/GrContextOptions.h"
  11. #include "include/gpu/GrTypes.h"
  12. class GrBaseContextPriv;
  13. class GrCaps;
  14. class GrContext;
  15. class GrImageContext;
  16. class GrRecordingContext;
  17. class GrSkSLFPFactoryCache;
  18. class SK_API GrContext_Base : public SkRefCnt {
  19. public:
  20. virtual ~GrContext_Base();
  21. /*
  22. * The 3D API backing this context
  23. */
  24. GrBackendApi backend() const { return fBackend; }
  25. // Provides access to functions that aren't part of the public API.
  26. GrBaseContextPriv priv();
  27. const GrBaseContextPriv priv() const;
  28. protected:
  29. friend class GrBaseContextPriv; // for hidden functions
  30. GrContext_Base(GrBackendApi backend, const GrContextOptions& options, uint32_t contextID);
  31. virtual bool init(sk_sp<const GrCaps>, sk_sp<GrSkSLFPFactoryCache>);
  32. /**
  33. * An identifier for this context. The id is used by all compatible contexts. For example,
  34. * if SkImages are created on one thread using an image creation context, then fed into a
  35. * DDL Recorder on second thread (which has a recording context) and finally replayed on
  36. * a third thread with a direct context, then all three contexts will report the same id.
  37. * It is an error for an image to be used with contexts that report different ids.
  38. */
  39. uint32_t contextID() const { return fContextID; }
  40. bool matches(GrContext_Base* candidate) const {
  41. return candidate->contextID() == this->contextID();
  42. }
  43. /*
  44. * The options in effect for this context
  45. */
  46. const GrContextOptions& options() const { return fOptions; }
  47. const GrCaps* caps() const;
  48. sk_sp<const GrCaps> refCaps() const;
  49. sk_sp<GrSkSLFPFactoryCache> fpFactoryCache();
  50. virtual GrImageContext* asImageContext() { return nullptr; }
  51. virtual GrRecordingContext* asRecordingContext() { return nullptr; }
  52. virtual GrContext* asDirectContext() { return nullptr; }
  53. private:
  54. const GrBackendApi fBackend;
  55. const GrContextOptions fOptions;
  56. const uint32_t fContextID;
  57. sk_sp<const GrCaps> fCaps;
  58. sk_sp<GrSkSLFPFactoryCache> fFPFactoryCache;
  59. typedef SkRefCnt INHERITED;
  60. };
  61. #endif