GrVkSecondaryCBDrawContext.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 GrVkSecondaryCBDrawContext_DEFINED
  8. #define GrVkSecondaryCBDrawContext_DEFINED
  9. #include "include/core/SkRefCnt.h"
  10. #include "include/core/SkSurfaceProps.h"
  11. #include "include/core/SkTypes.h"
  12. class GrBackendSemaphore;
  13. class GrContext;
  14. struct GrVkDrawableInfo;
  15. class SkCanvas;
  16. class SkDeferredDisplayList;
  17. class SkGpuDevice;
  18. struct SkImageInfo;
  19. class SkSurfaceCharacterization;
  20. class SkSurfaceProps;
  21. /**
  22. * This class is a private header that is intended to only be used inside of Chromium. This requires
  23. * Chromium to burrow in and include this specifically since it is not part of skia's public include
  24. * directory.
  25. */
  26. /**
  27. * This class is used to draw into an external Vulkan secondary command buffer that is imported
  28. * by the client. The secondary command buffer that gets imported must already have had begin called
  29. * on it with VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT. Thus any draws to the imported
  30. * command buffer cannot require changing the render pass. This requirement means that certain types
  31. * of draws will not be supported when using a GrVkSecondaryCBDrawContext. This includes:
  32. * Draws that require a dst copy for blending will be dropped
  33. * Text draws will be dropped (these may require intermediate uploads of text data)
  34. * Read and Write pixels will not work
  35. * Any other draw that requires a copy will fail (this includes using backdrop filter with save
  36. * layer).
  37. * Stenciling is also disabled, but that should not restrict any actual draws from working.
  38. *
  39. * While using a GrVkSecondaryCBDrawContext, the client can also draw into normal SkSurfaces and
  40. * then draw those SkSufaces (as SkImages) into the GrVkSecondaryCBDrawContext. If any of the
  41. * previously mentioned unsupported draws are needed by the client, they can draw them into an
  42. * offscreen surface, and then draw that into the GrVkSecondaryCBDrawContext.
  43. *
  44. * After all drawing to the GrVkSecondaryCBDrawContext has been done, the client must call flush()
  45. * on the GrVkSecondaryCBDrawContext to actually fill in the secondary VkCommandBuffer with the
  46. * draws.
  47. *
  48. * Additionally, the client must keep the GrVkSecondaryCBDrawContext alive until the secondary
  49. * VkCommandBuffer has been submitted and all work finished on the GPU. Before deleting the
  50. * GrVkSecondaryCBDrawContext, the client must call releaseResources() so that Skia can cleanup
  51. * any internal objects that were created for the draws into the secondary command buffer.
  52. */
  53. class SK_API GrVkSecondaryCBDrawContext : public SkRefCnt {
  54. public:
  55. static sk_sp<GrVkSecondaryCBDrawContext> Make(GrContext*, const SkImageInfo&,
  56. const GrVkDrawableInfo&,
  57. const SkSurfaceProps* props);
  58. ~GrVkSecondaryCBDrawContext() override;
  59. SkCanvas* getCanvas();
  60. // Records all the draws to the imported secondary command buffer and sets any dependent
  61. // offscreen draws to the GPU.
  62. void flush();
  63. /** Inserts a list of GPU semaphores that Skia will have the driver wait on before executing
  64. commands for this secondary CB. The wait semaphores will get added to the VkCommandBuffer
  65. owned by this GrContext when flush() is called, and not the command buffer which the
  66. Secondary CB is from. This will guarantee that the driver waits on the semaphores before
  67. the secondary command buffer gets executed. Skia will take ownership of the underlying
  68. semaphores and delete them once they have been signaled and waited on. If this call returns
  69. false, then the GPU back-end will not wait on any passed in semaphores, and the client will
  70. still own the semaphores.
  71. @param numSemaphores size of waitSemaphores array
  72. @param waitSemaphores array of semaphore containers
  73. @return true if GPU is waiting on semaphores
  74. */
  75. bool wait(int numSemaphores, const GrBackendSemaphore waitSemaphores[]);
  76. // This call will release all resources held by the draw context. The client must call
  77. // releaseResources() before deleting the drawing context. However, the resources also include
  78. // any Vulkan resources that were created and used for draws. Therefore the client must only
  79. // call releaseResources() after submitting the secondary command buffer, and waiting for it to
  80. // finish on the GPU. If it is called earlier then some vulkan objects may be deleted while they
  81. // are still in use by the GPU.
  82. void releaseResources();
  83. const SkSurfaceProps& props() const { return fProps; }
  84. // TODO: Fill out these calls to support DDL
  85. bool characterize(SkSurfaceCharacterization* characterization) const;
  86. bool draw(SkDeferredDisplayList* deferredDisplayList);
  87. private:
  88. explicit GrVkSecondaryCBDrawContext(sk_sp<SkGpuDevice>, const SkSurfaceProps*);
  89. bool isCompatible(const SkSurfaceCharacterization& characterization) const;
  90. sk_sp<SkGpuDevice> fDevice;
  91. std::unique_ptr<SkCanvas> fCachedCanvas;
  92. const SkSurfaceProps fProps;
  93. typedef SkRefCnt INHERITED;
  94. };
  95. #endif