GrDawnGpuCommandBuffer.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 GrDawnGpuCommandBuffer_DEFINED
  8. #define GrDawnGpuCommandBuffer_DEFINED
  9. #include "src/gpu/GrGpuCommandBuffer.h"
  10. #include "src/gpu/GrColor.h"
  11. #include "src/gpu/GrMesh.h"
  12. #include "include/gpu/GrTypes.h"
  13. #include "dawn/dawncpp.h"
  14. class GrDawnGpu;
  15. class GrDawnRenderTarget;
  16. class GrDawnGpuTextureCommandBuffer : public GrGpuTextureCommandBuffer {
  17. public:
  18. GrDawnGpuTextureCommandBuffer(GrDawnGpu* gpu, GrTexture* texture, GrSurfaceOrigin origin)
  19. : INHERITED(texture, origin)
  20. , fGpu(gpu) {
  21. }
  22. ~GrDawnGpuTextureCommandBuffer() override;
  23. void copy(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) override;
  24. void insertEventMarker(const char*) override;
  25. private:
  26. void submit();
  27. struct CopyInfo {
  28. CopyInfo(GrSurface* src, GrSurfaceOrigin srcOrigin, const SkIRect& srcRect,
  29. const SkIPoint& dstPoint)
  30. : fSrc(src), fSrcOrigin(srcOrigin), fSrcRect(srcRect), fDstPoint(dstPoint) {}
  31. GrSurface* fSrc;
  32. GrSurfaceOrigin fSrcOrigin;
  33. SkIRect fSrcRect;
  34. SkIPoint fDstPoint;
  35. };
  36. GrDawnGpu* fGpu;
  37. SkTArray<CopyInfo> fCopies;
  38. typedef GrGpuTextureCommandBuffer INHERITED;
  39. };
  40. class GrDawnGpuRTCommandBuffer : public GrGpuRTCommandBuffer, private GrMesh::SendToGpuImpl {
  41. public:
  42. GrDawnGpuRTCommandBuffer(GrDawnGpu*, GrRenderTarget*, GrSurfaceOrigin,
  43. const LoadAndStoreInfo&,
  44. const StencilLoadAndStoreInfo&);
  45. ~GrDawnGpuRTCommandBuffer() override;
  46. void begin() override { }
  47. void end() override;
  48. void transferFrom(const SkIRect& srcRect, GrColorType bufferColorType,
  49. GrGpuBuffer* transferBuffer, size_t offset) override;
  50. void insertEventMarker(const char*) override;
  51. void inlineUpload(GrOpFlushState* state, GrDeferredTextureUploadFn& upload) override;
  52. void copy(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) override;
  53. void submit();
  54. private:
  55. void init();
  56. GrGpu* gpu() override;
  57. // Bind vertex and index buffers
  58. void bindGeometry(const GrBuffer* indexBuffer,
  59. const GrBuffer* vertexBuffer,
  60. const GrBuffer* instanceBuffer);
  61. void onDraw(const GrPrimitiveProcessor& primProc,
  62. const GrPipeline& pipeline,
  63. const GrPipeline::FixedDynamicState* fixedDynamicState,
  64. const GrPipeline::DynamicStateArrays* dynamicStateArrays,
  65. const GrMesh mesh[],
  66. int meshCount,
  67. const SkRect& bounds) override;
  68. void sendMeshToGpu(GrPrimitiveType primType, const GrBuffer* vertexBuffer, int vertexCount,
  69. int baseVertex) final {
  70. this->sendInstancedMeshToGpu(primType, vertexBuffer, vertexCount, baseVertex,
  71. nullptr, 1, 0);
  72. }
  73. void sendIndexedMeshToGpu(GrPrimitiveType primType,
  74. const GrBuffer* indexBuffer, int indexCount, int baseIndex,
  75. uint16_t /*minIndexValue*/, uint16_t /*maxIndexValue*/,
  76. const GrBuffer* vertexBuffer, int baseVertex,
  77. GrPrimitiveRestart restart) final {
  78. this->sendIndexedInstancedMeshToGpu(primType, indexBuffer, indexCount, baseIndex,
  79. vertexBuffer, baseVertex, nullptr, 1, 0, restart);
  80. }
  81. void sendInstancedMeshToGpu(GrPrimitiveType,
  82. const GrBuffer* vertexBuffer, int vertexCount, int baseVertex,
  83. const GrBuffer* instanceBuffer, int instanceCount,
  84. int baseInstance) final;
  85. void sendIndexedInstancedMeshToGpu(GrPrimitiveType,
  86. const GrBuffer* indexBuffer, int indexCount, int baseIndex,
  87. const GrBuffer* vertexBuffer, int baseVertex,
  88. const GrBuffer* instanceBuffer, int instanceCount,
  89. int baseInstance, GrPrimitiveRestart) final;
  90. void onClear(const GrFixedClip&, const SkPMColor4f& color) override;
  91. void onClearStencilClip(const GrFixedClip&, bool insideStencilMask) override;
  92. struct InlineUploadInfo {
  93. InlineUploadInfo(GrOpFlushState* state, const GrDeferredTextureUploadFn& upload)
  94. : fFlushState(state), fUpload(upload) {}
  95. GrOpFlushState* fFlushState;
  96. GrDeferredTextureUploadFn fUpload;
  97. };
  98. struct CopyInfo {
  99. CopyInfo(GrSurface* src, GrSurfaceOrigin srcOrigin, const SkIRect& srcRect,
  100. const SkIPoint& dstPoint)
  101. : fSrc(src), fSrcOrigin(srcOrigin), fSrcRect(srcRect), fDstPoint(dstPoint) {}
  102. GrSurface* fSrc;
  103. GrSurfaceOrigin fSrcOrigin;
  104. SkIRect fSrcRect;
  105. SkIPoint fDstPoint;
  106. };
  107. dawn::CommandBuffer fCommandBuffer;
  108. GrDawnGpu* fGpu;
  109. typedef GrGpuRTCommandBuffer INHERITED;
  110. };
  111. #endif