GrRecordingContext.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 GrRecordingContext_DEFINED
  8. #define GrRecordingContext_DEFINED
  9. #include "include/core/SkRefCnt.h"
  10. #include "include/private/GrImageContext.h"
  11. class GrAuditTrail;
  12. class GrBackendFormat;
  13. class GrDrawingManager;
  14. class GrOnFlushCallbackObject;
  15. class GrOpMemoryPool;
  16. class GrRecordingContextPriv;
  17. class GrStrikeCache;
  18. class GrSurfaceContext;
  19. class GrSurfaceProxy;
  20. class GrTextBlobCache;
  21. class GrTextureContext;
  22. class SK_API GrRecordingContext : public GrImageContext {
  23. public:
  24. ~GrRecordingContext() override;
  25. // Provides access to functions that aren't part of the public API.
  26. GrRecordingContextPriv priv();
  27. const GrRecordingContextPriv priv() const;
  28. protected:
  29. friend class GrRecordingContextPriv; // for hidden functions
  30. GrRecordingContext(GrBackendApi, const GrContextOptions&, uint32_t contextID);
  31. bool init(sk_sp<const GrCaps>, sk_sp<GrSkSLFPFactoryCache>) override;
  32. void setupDrawingManager(bool sortOpLists, bool reduceOpListSplitting);
  33. void abandonContext() override;
  34. GrDrawingManager* drawingManager();
  35. sk_sp<GrOpMemoryPool> refOpMemoryPool();
  36. GrOpMemoryPool* opMemoryPool();
  37. GrStrikeCache* getGrStrikeCache() { return fStrikeCache.get(); }
  38. GrTextBlobCache* getTextBlobCache();
  39. const GrTextBlobCache* getTextBlobCache() const;
  40. /**
  41. * Registers an object for flush-related callbacks. (See GrOnFlushCallbackObject.)
  42. *
  43. * NOTE: the drawing manager tracks this object as a raw pointer; it is up to the caller to
  44. * ensure its lifetime is tied to that of the context.
  45. */
  46. void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
  47. sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy>,
  48. GrColorType,
  49. SkAlphaType,
  50. sk_sp<SkColorSpace> = nullptr,
  51. const SkSurfaceProps* = nullptr);
  52. /** Create a new texture context backed by a deferred-style GrTextureProxy. */
  53. sk_sp<GrTextureContext> makeDeferredTextureContext(
  54. SkBackingFit,
  55. int width,
  56. int height,
  57. GrColorType,
  58. SkAlphaType,
  59. sk_sp<SkColorSpace>,
  60. GrMipMapped = GrMipMapped::kNo,
  61. GrSurfaceOrigin = kTopLeft_GrSurfaceOrigin,
  62. SkBudgeted = SkBudgeted::kYes,
  63. GrProtected = GrProtected::kNo);
  64. /*
  65. * Create a new render target context backed by a deferred-style
  66. * GrRenderTargetProxy. We guarantee that "asTextureProxy" will succeed for
  67. * renderTargetContexts created via this entry point.
  68. */
  69. sk_sp<GrRenderTargetContext> makeDeferredRenderTargetContext(
  70. SkBackingFit fit,
  71. int width,
  72. int height,
  73. GrColorType colorType,
  74. sk_sp<SkColorSpace> colorSpace,
  75. int sampleCnt = 1,
  76. GrMipMapped = GrMipMapped::kNo,
  77. GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin,
  78. const SkSurfaceProps* surfaceProps = nullptr,
  79. SkBudgeted = SkBudgeted::kYes,
  80. GrProtected isProtected = GrProtected::kNo);
  81. /*
  82. * This method will attempt to create a renderTargetContext that has, at least, the number of
  83. * channels and precision per channel as requested in 'config' (e.g., A8 and 888 can be
  84. * converted to 8888). It may also swizzle the channels (e.g., BGRA -> RGBA).
  85. * SRGB-ness will be preserved.
  86. */
  87. sk_sp<GrRenderTargetContext> makeDeferredRenderTargetContextWithFallback(
  88. SkBackingFit fit,
  89. int width,
  90. int height,
  91. GrColorType colorType,
  92. sk_sp<SkColorSpace> colorSpace,
  93. int sampleCnt = 1,
  94. GrMipMapped = GrMipMapped::kNo,
  95. GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin,
  96. const SkSurfaceProps* surfaceProps = nullptr,
  97. SkBudgeted budgeted = SkBudgeted::kYes,
  98. GrProtected isProtected = GrProtected::kNo);
  99. GrAuditTrail* auditTrail() { return fAuditTrail.get(); }
  100. GrRecordingContext* asRecordingContext() override { return this; }
  101. private:
  102. std::unique_ptr<GrDrawingManager> fDrawingManager;
  103. // All the GrOp-derived classes use this pool.
  104. sk_sp<GrOpMemoryPool> fOpMemoryPool;
  105. std::unique_ptr<GrStrikeCache> fStrikeCache;
  106. std::unique_ptr<GrTextBlobCache> fTextBlobCache;
  107. std::unique_ptr<GrAuditTrail> fAuditTrail;
  108. typedef GrImageContext INHERITED;
  109. };
  110. #endif