test_raster_interface.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_VIZ_TEST_TEST_RASTER_INTERFACE_H_
  5. #define COMPONENTS_VIZ_TEST_TEST_RASTER_INTERFACE_H_
  6. #include <utility>
  7. #include "base/callback.h"
  8. #include "components/viz/test/test_context_support.h"
  9. #include "gpu/command_buffer/client/raster_interface.h"
  10. #include "gpu/command_buffer/common/capabilities.h"
  11. #include "gpu/command_buffer/common/sync_token.h"
  12. namespace viz {
  13. // A fake implementation of RasterInterface for use in unit tests that don't
  14. // draw anything.
  15. class TestRasterInterface : public gpu::raster::RasterInterface {
  16. public:
  17. TestRasterInterface();
  18. ~TestRasterInterface() override;
  19. const gpu::Capabilities& capabilities() const { return caps_; }
  20. gpu::SyncToken last_waited_sync_token() const {
  21. return last_waited_sync_token_;
  22. }
  23. void set_context_lost_callback(base::OnceClosure callback) {
  24. context_lost_callback_ = std::move(callback);
  25. }
  26. void set_test_support(TestContextSupport* test_support) {
  27. test_support_ = test_support;
  28. }
  29. void set_context_lost(bool context_lost) { context_lost_ = context_lost; }
  30. // Capability setters below here.
  31. void set_gpu_rasterization(bool gpu_rasterization) {
  32. caps_.gpu_rasterization = gpu_rasterization;
  33. caps_.supports_oop_raster = gpu_rasterization;
  34. }
  35. void set_msaa_is_slow(bool msaa_is_slow) {
  36. caps_.msaa_is_slow = msaa_is_slow;
  37. }
  38. void set_avoid_stencil_buffers(bool avoid_stencil_buffers) {
  39. caps_.avoid_stencil_buffers = avoid_stencil_buffers;
  40. }
  41. void set_multisample_compatibility(bool multisample_compatibility) {
  42. caps_.multisample_compatibility = multisample_compatibility;
  43. }
  44. // gpu::raster::RasterInterface implementation.
  45. void Finish() override;
  46. void Flush() override;
  47. void OrderingBarrierCHROMIUM() override {}
  48. GLenum GetError() override;
  49. GLenum GetGraphicsResetStatusKHR() override;
  50. void LoseContextCHROMIUM(GLenum current, GLenum other) override;
  51. void GenQueriesEXT(GLsizei n, GLuint* queries) override;
  52. void DeleteQueriesEXT(GLsizei n, const GLuint* queries) override;
  53. void BeginQueryEXT(GLenum target, GLuint id) override;
  54. void EndQueryEXT(GLenum target) override;
  55. void QueryCounterEXT(GLuint id, GLenum target) override;
  56. void GetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint* params) override;
  57. void GetQueryObjectui64vEXT(GLuint id,
  58. GLenum pname,
  59. GLuint64* params) override;
  60. void CopySubTexture(const gpu::Mailbox& source_mailbox,
  61. const gpu::Mailbox& dest_mailbox,
  62. GLenum dest_target,
  63. GLint xoffset,
  64. GLint yoffset,
  65. GLint x,
  66. GLint y,
  67. GLsizei width,
  68. GLsizei height,
  69. GLboolean unpack_flip_y,
  70. GLboolean unpack_premultiply_alpha) override {}
  71. void WritePixels(const gpu::Mailbox& dest_mailbox,
  72. int dst_x_offset,
  73. int dst_y_offset,
  74. GLenum texture_target,
  75. GLuint row_bytes,
  76. const SkImageInfo& src_info,
  77. const void* src_pixels) override {}
  78. void ConvertYUVAMailboxesToRGB(
  79. const gpu::Mailbox& dest_mailbox,
  80. SkYUVColorSpace planes_yuv_color_space,
  81. const SkColorSpace* planes_rgb_color_space,
  82. SkYUVAInfo::PlaneConfig plane_config,
  83. SkYUVAInfo::Subsampling subsampling,
  84. const gpu::Mailbox yuva_plane_mailboxes[]) override {}
  85. void ConvertRGBAToYUVAMailboxes(SkYUVColorSpace planes_yuv_color_space,
  86. SkYUVAInfo::PlaneConfig plane_config,
  87. SkYUVAInfo::Subsampling subsampling,
  88. const gpu::Mailbox yuva_plane_mailboxes[],
  89. const gpu::Mailbox& source_mailbox) override {
  90. }
  91. void BeginRasterCHROMIUM(SkColor4f sk_color_4f,
  92. GLboolean needs_clear,
  93. GLuint msaa_sample_count,
  94. gpu::raster::MsaaMode msaa_mode,
  95. GLboolean can_use_lcd_text,
  96. GLboolean visible,
  97. const gfx::ColorSpace& color_space,
  98. const GLbyte* mailbox) override {}
  99. void RasterCHROMIUM(const cc::DisplayItemList* list,
  100. cc::ImageProvider* provider,
  101. const gfx::Size& content_size,
  102. const gfx::Rect& full_raster_rect,
  103. const gfx::Rect& playback_rect,
  104. const gfx::Vector2dF& post_translate,
  105. const gfx::Vector2dF& post_scale,
  106. bool requires_clear,
  107. size_t* max_op_size_hint,
  108. bool preserve_recording = true) override {}
  109. void EndRasterCHROMIUM() override {}
  110. gpu::SyncToken ScheduleImageDecode(base::span<const uint8_t> encoded_data,
  111. const gfx::Size& output_size,
  112. uint32_t transfer_cache_entry_id,
  113. const gfx::ColorSpace& target_color_space,
  114. bool needs_mips) override;
  115. void ReadbackARGBPixelsAsync(
  116. const gpu::Mailbox& source_mailbox,
  117. GLenum source_target,
  118. GrSurfaceOrigin source_origin,
  119. const SkImageInfo& dst_info,
  120. GLuint dst_row_bytes,
  121. unsigned char* out,
  122. base::OnceCallback<void(GrSurfaceOrigin, bool)> readback_done) override {}
  123. void ReadbackYUVPixelsAsync(
  124. const gpu::Mailbox& source_mailbox,
  125. GLenum source_target,
  126. const gfx::Size& source_size,
  127. const gfx::Rect& output_rect,
  128. bool vertically_flip_texture,
  129. int y_plane_row_stride_bytes,
  130. unsigned char* y_plane_data,
  131. int u_plane_row_stride_bytes,
  132. unsigned char* u_plane_data,
  133. int v_plane_row_stride_bytes,
  134. unsigned char* v_plane_data,
  135. const gfx::Point& paste_location,
  136. base::OnceCallback<void()> release_mailbox,
  137. base::OnceCallback<void(bool)> readback_done) override {}
  138. void ReadbackImagePixels(const gpu::Mailbox& source_mailbox,
  139. const SkImageInfo& dst_info,
  140. GLuint dst_row_bytes,
  141. int src_x,
  142. int src_y,
  143. void* dst_pixels) override {}
  144. GLuint CreateAndConsumeForGpuRaster(const gpu::Mailbox& mailbox) override;
  145. void DeleteGpuRasterTexture(GLuint texture) override;
  146. void BeginGpuRaster() override;
  147. void EndGpuRaster() override;
  148. void BeginSharedImageAccessDirectCHROMIUM(GLuint texture,
  149. GLenum mode) override;
  150. void EndSharedImageAccessDirectCHROMIUM(GLuint texture) override;
  151. void InitializeDiscardableTextureCHROMIUM(GLuint texture) override;
  152. void UnlockDiscardableTextureCHROMIUM(GLuint texture) override;
  153. bool LockDiscardableTextureCHROMIUM(GLuint texture) override;
  154. void TraceBeginCHROMIUM(const char* category_name,
  155. const char* trace_name) override {}
  156. void TraceEndCHROMIUM() override {}
  157. void SetActiveURLCHROMIUM(const char* url) override {}
  158. // InterfaceBase implementation.
  159. void GenSyncTokenCHROMIUM(GLbyte* sync_token) override;
  160. void GenUnverifiedSyncTokenCHROMIUM(GLbyte* sync_token) override;
  161. void VerifySyncTokensCHROMIUM(GLbyte** sync_tokens, GLsizei count) override;
  162. void WaitSyncTokenCHROMIUM(const GLbyte* sync_token) override;
  163. void ShallowFlushCHROMIUM() override;
  164. private:
  165. gpu::Capabilities caps_;
  166. base::OnceClosure context_lost_callback_;
  167. raw_ptr<TestContextSupport> test_support_ = nullptr;
  168. bool context_lost_ = false;
  169. uint64_t next_insert_fence_sync_ = 1;
  170. gpu::SyncToken last_waited_sync_token_;
  171. };
  172. } // namespace viz
  173. #endif // COMPONENTS_VIZ_TEST_TEST_RASTER_INTERFACE_H_