GrRecordingContextPriv.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 GrRecordingContextPriv_DEFINED
  8. #define GrRecordingContextPriv_DEFINED
  9. #include "include/private/GrRecordingContext.h"
  10. /** Class that exposes methods to GrRecordingContext that are only intended for use internal to
  11. Skia. This class is purely a privileged window into GrRecordingContext. It should never have
  12. additional data members or virtual methods. */
  13. class GrRecordingContextPriv {
  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. // from GrImageContext
  26. GrProxyProvider* proxyProvider() { return fContext->proxyProvider(); }
  27. const GrProxyProvider* proxyProvider() const { return fContext->proxyProvider(); }
  28. bool abandoned() const { return fContext->abandoned(); }
  29. /** This is only useful for debug purposes */
  30. SkDEBUGCODE(GrSingleOwner* singleOwner() const { return fContext->singleOwner(); } )
  31. // from GrRecordingContext
  32. GrDrawingManager* drawingManager() { return fContext->drawingManager(); }
  33. sk_sp<GrOpMemoryPool> refOpMemoryPool();
  34. GrOpMemoryPool* opMemoryPool() { return fContext->opMemoryPool(); }
  35. GrStrikeCache* getGrStrikeCache() { return fContext->getGrStrikeCache(); }
  36. GrTextBlobCache* getTextBlobCache() { return fContext->getTextBlobCache(); }
  37. /**
  38. * Registers an object for flush-related callbacks. (See GrOnFlushCallbackObject.)
  39. *
  40. * NOTE: the drawing manager tracks this object as a raw pointer; it is up to the caller to
  41. * ensure its lifetime is tied to that of the context.
  42. */
  43. void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
  44. sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy>,
  45. GrColorType,
  46. SkAlphaType,
  47. sk_sp<SkColorSpace> = nullptr,
  48. const SkSurfaceProps* = nullptr);
  49. /** Create a new texture context backed by a deferred-style GrTextureProxy. */
  50. sk_sp<GrTextureContext> makeDeferredTextureContext(
  51. SkBackingFit,
  52. int width,
  53. int height,
  54. GrColorType,
  55. SkAlphaType,
  56. sk_sp<SkColorSpace>,
  57. GrMipMapped = GrMipMapped::kNo,
  58. GrSurfaceOrigin = kTopLeft_GrSurfaceOrigin,
  59. SkBudgeted = SkBudgeted::kYes,
  60. GrProtected = GrProtected::kNo);
  61. /*
  62. * Create a new render target context backed by a deferred-style
  63. * GrRenderTargetProxy. We guarantee that "asTextureProxy" will succeed for
  64. * renderTargetContexts created via this entry point.
  65. */
  66. sk_sp<GrRenderTargetContext> makeDeferredRenderTargetContext(
  67. SkBackingFit fit,
  68. int width,
  69. int height,
  70. GrColorType,
  71. sk_sp<SkColorSpace> colorSpace,
  72. int sampleCnt = 1,
  73. GrMipMapped = GrMipMapped::kNo,
  74. GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin,
  75. const SkSurfaceProps* surfaceProps = nullptr,
  76. SkBudgeted = SkBudgeted::kYes,
  77. GrProtected isProtected = GrProtected::kNo);
  78. /*
  79. * This method will attempt to create a renderTargetContext that has, at least, the number of
  80. * channels and precision per channel as requested in 'config' (e.g., A8 and 888 can be
  81. * converted to 8888). It may also swizzle the channels (e.g., BGRA -> RGBA).
  82. * SRGB-ness will be preserved.
  83. */
  84. sk_sp<GrRenderTargetContext> makeDeferredRenderTargetContextWithFallback(
  85. SkBackingFit fit,
  86. int width,
  87. int height,
  88. GrColorType,
  89. sk_sp<SkColorSpace> colorSpace,
  90. int sampleCnt = 1,
  91. GrMipMapped = GrMipMapped::kNo,
  92. GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin,
  93. const SkSurfaceProps* surfaceProps = nullptr,
  94. SkBudgeted budgeted = SkBudgeted::kYes,
  95. GrProtected isProtected = GrProtected::kNo);
  96. GrAuditTrail* auditTrail() { return fContext->auditTrail(); }
  97. // CONTEXT TODO: remove this backdoor
  98. // In order to make progress we temporarily need a way to break CL impasses.
  99. GrContext* backdoor();
  100. private:
  101. explicit GrRecordingContextPriv(GrRecordingContext* context) : fContext(context) {}
  102. GrRecordingContextPriv(const GrRecordingContextPriv&); // unimpl
  103. GrRecordingContextPriv& operator=(const GrRecordingContextPriv&); // unimpl
  104. // No taking addresses of this type.
  105. const GrRecordingContextPriv* operator&() const;
  106. GrRecordingContextPriv* operator&();
  107. GrRecordingContext* fContext;
  108. friend class GrRecordingContext; // to construct/copy this type.
  109. };
  110. inline GrRecordingContextPriv GrRecordingContext::priv() { return GrRecordingContextPriv(this); }
  111. inline const GrRecordingContextPriv GrRecordingContext::priv () const {
  112. return GrRecordingContextPriv(const_cast<GrRecordingContext*>(this));
  113. }
  114. #endif