GrGpuCommandBuffer.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright 2016 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 GrGpuCommandBuffer_DEFINED
  8. #define GrGpuCommandBuffer_DEFINED
  9. #include "include/core/SkDrawable.h"
  10. #include "src/gpu/GrPipeline.h"
  11. #include "src/gpu/ops/GrDrawOp.h"
  12. class GrOpFlushState;
  13. class GrFixedClip;
  14. class GrGpu;
  15. class GrMesh;
  16. class GrPipeline;
  17. class GrPrimitiveProcessor;
  18. class GrRenderTarget;
  19. class GrSemaphore;
  20. struct SkIRect;
  21. struct SkRect;
  22. class GrGpuRTCommandBuffer;
  23. class GrGpuCommandBuffer {
  24. public:
  25. virtual ~GrGpuCommandBuffer() {}
  26. // Copy src into current surface owned by either a GrGpuTextureCommandBuffer or
  27. // GrGpuRenderTargetCommandBuffer. The srcRect and dstPoint must be in dst coords and have
  28. // already been adjusted for any origin flips.
  29. virtual void copy(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) = 0;
  30. // Initiates a transfer from the surface owned by the command buffer to the GrGpuBuffer.
  31. virtual void transferFrom(const SkIRect& srcRect, GrColorType bufferColorType,
  32. GrGpuBuffer* transferBuffer, size_t offset) = 0;
  33. virtual void insertEventMarker(const char*) = 0;
  34. virtual GrGpuRTCommandBuffer* asRTCommandBuffer() { return nullptr; }
  35. };
  36. class GrGpuTextureCommandBuffer : public GrGpuCommandBuffer{
  37. public:
  38. void set(GrTexture* texture, GrSurfaceOrigin origin) {
  39. SkASSERT(!fTexture);
  40. fTexture = texture;
  41. }
  42. protected:
  43. GrGpuTextureCommandBuffer() : fTexture(nullptr) {}
  44. GrGpuTextureCommandBuffer(GrTexture* texture, GrSurfaceOrigin origin) : fTexture(texture) {}
  45. GrTexture* fTexture;
  46. private:
  47. typedef GrGpuCommandBuffer INHERITED;
  48. };
  49. /**
  50. * The GrGpuRenderTargetCommandBuffer is a series of commands (draws, clears, and discards), which
  51. * all target the same render target. It is possible that these commands execute immediately (GL),
  52. * or get buffered up for later execution (Vulkan). GrOps will execute their draw commands into a
  53. * GrGpuCommandBuffer.
  54. */
  55. class GrGpuRTCommandBuffer : public GrGpuCommandBuffer {
  56. public:
  57. struct LoadAndStoreInfo {
  58. GrLoadOp fLoadOp;
  59. GrStoreOp fStoreOp;
  60. SkPMColor4f fClearColor;
  61. };
  62. // Load-time clears of the stencil buffer are always to 0 so we don't store
  63. // an 'fStencilClearValue'
  64. struct StencilLoadAndStoreInfo {
  65. GrLoadOp fLoadOp;
  66. GrStoreOp fStoreOp;
  67. };
  68. GrGpuRTCommandBuffer* asRTCommandBuffer() { return this; }
  69. virtual void begin() = 0;
  70. // Signals the end of recording to the command buffer and that it can now be submitted.
  71. virtual void end() = 0;
  72. // We pass in an array of meshCount GrMesh to the draw. The backend should loop over each
  73. // GrMesh object and emit a draw for it. Each draw will use the same GrPipeline and
  74. // GrPrimitiveProcessor. This may fail if the draw would exceed any resource limits (e.g.
  75. // number of vertex attributes is too large).
  76. bool draw(const GrPrimitiveProcessor&,
  77. const GrPipeline&,
  78. const GrPipeline::FixedDynamicState*,
  79. const GrPipeline::DynamicStateArrays*,
  80. const GrMesh[],
  81. int meshCount,
  82. const SkRect& bounds);
  83. // Performs an upload of vertex data in the middle of a set of a set of draws
  84. virtual void inlineUpload(GrOpFlushState*, GrDeferredTextureUploadFn&) = 0;
  85. /**
  86. * Clear the owned render target. Ignores the draw state and clip.
  87. */
  88. void clear(const GrFixedClip&, const SkPMColor4f&);
  89. void clearStencilClip(const GrFixedClip&, bool insideStencilMask);
  90. /**
  91. * Executes the SkDrawable object for the underlying backend.
  92. */
  93. virtual void executeDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>) {}
  94. protected:
  95. GrGpuRTCommandBuffer() : fOrigin(kTopLeft_GrSurfaceOrigin), fRenderTarget(nullptr) {}
  96. GrGpuRTCommandBuffer(GrRenderTarget* rt, GrSurfaceOrigin origin)
  97. : fOrigin(origin)
  98. , fRenderTarget(rt) {
  99. }
  100. void set(GrRenderTarget* rt, GrSurfaceOrigin origin) {
  101. SkASSERT(!fRenderTarget);
  102. fRenderTarget = rt;
  103. fOrigin = origin;
  104. }
  105. GrSurfaceOrigin fOrigin;
  106. GrRenderTarget* fRenderTarget;
  107. private:
  108. virtual GrGpu* gpu() = 0;
  109. // overridden by backend-specific derived class to perform the draw call.
  110. virtual void onDraw(const GrPrimitiveProcessor&,
  111. const GrPipeline&,
  112. const GrPipeline::FixedDynamicState*,
  113. const GrPipeline::DynamicStateArrays*,
  114. const GrMesh[],
  115. int meshCount,
  116. const SkRect& bounds) = 0;
  117. // overridden by backend-specific derived class to perform the clear.
  118. virtual void onClear(const GrFixedClip&, const SkPMColor4f&) = 0;
  119. virtual void onClearStencilClip(const GrFixedClip&, bool insideStencilMask) = 0;
  120. typedef GrGpuCommandBuffer INHERITED;
  121. };
  122. #endif