test_raster_interface.cc 5.6 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. #include "components/viz/test/test_raster_interface.h"
  5. #include <limits>
  6. #include <utility>
  7. #include "base/notreached.h"
  8. #include "base/time/time.h"
  9. #include "gpu/GLES2/gl2extchromium.h"
  10. #include "gpu/command_buffer/common/constants.h"
  11. namespace viz {
  12. TestRasterInterface::TestRasterInterface() {
  13. caps_.max_texture_size = 2048;
  14. }
  15. TestRasterInterface::~TestRasterInterface() = default;
  16. void TestRasterInterface::Finish() {
  17. if (test_support_)
  18. test_support_->CallAllSyncPointCallbacks();
  19. }
  20. void TestRasterInterface::Flush() {
  21. if (test_support_)
  22. test_support_->CallAllSyncPointCallbacks();
  23. }
  24. GLenum TestRasterInterface::GetError() {
  25. return 0;
  26. }
  27. GLenum TestRasterInterface::GetGraphicsResetStatusKHR() {
  28. if (context_lost_)
  29. return GL_UNKNOWN_CONTEXT_RESET_KHR;
  30. return GL_NO_ERROR;
  31. }
  32. void TestRasterInterface::LoseContextCHROMIUM(GLenum current, GLenum other) {
  33. if (context_lost_)
  34. return;
  35. context_lost_ = true;
  36. if (context_lost_callback_)
  37. std::move(context_lost_callback_).Run();
  38. }
  39. void TestRasterInterface::GenQueriesEXT(GLsizei n, GLuint* queries) {
  40. for (GLsizei i = 0; i < n; ++i) {
  41. queries[i] = 1u;
  42. }
  43. }
  44. void TestRasterInterface::DeleteQueriesEXT(GLsizei n, const GLuint* queries) {}
  45. void TestRasterInterface::BeginQueryEXT(GLenum target, GLuint id) {}
  46. void TestRasterInterface::EndQueryEXT(GLenum target) {}
  47. void TestRasterInterface::QueryCounterEXT(GLuint id, GLenum target) {}
  48. void TestRasterInterface::GetQueryObjectuivEXT(GLuint id,
  49. GLenum pname,
  50. GLuint* params) {
  51. // If the context is lost, behave as if result is available.
  52. if (pname == GL_QUERY_RESULT_AVAILABLE_EXT ||
  53. pname == GL_QUERY_RESULT_AVAILABLE_NO_FLUSH_CHROMIUM_EXT) {
  54. *params = 1;
  55. }
  56. }
  57. void TestRasterInterface::GetQueryObjectui64vEXT(GLuint id,
  58. GLenum pname,
  59. GLuint64* params) {
  60. // This is used for testing GL_COMMANDS_ISSUED_TIMESTAMP_QUERY, so we return
  61. // the maximum that base::TimeDelta()::InMicroseconds() could return.
  62. if (pname == GL_QUERY_RESULT_EXT) {
  63. static_assert(std::is_same<decltype(base::TimeDelta().InMicroseconds()),
  64. int64_t>::value,
  65. "Expected the return type of "
  66. "base::TimeDelta()::InMicroseconds() to be int64_t");
  67. *params = std::numeric_limits<int64_t>::max();
  68. } else {
  69. NOTREACHED();
  70. }
  71. }
  72. gpu::SyncToken TestRasterInterface::ScheduleImageDecode(
  73. base::span<const uint8_t> encoded_data,
  74. const gfx::Size& output_size,
  75. uint32_t transfer_cache_entry_id,
  76. const gfx::ColorSpace& target_color_space,
  77. bool needs_mips) {
  78. return gpu::SyncToken();
  79. }
  80. GLuint TestRasterInterface::CreateAndConsumeForGpuRaster(
  81. const gpu::Mailbox& mailbox) {
  82. NOTREACHED();
  83. return 0;
  84. }
  85. void TestRasterInterface::DeleteGpuRasterTexture(GLuint texture) {
  86. NOTREACHED();
  87. }
  88. void TestRasterInterface::BeginGpuRaster() {
  89. NOTREACHED();
  90. }
  91. void TestRasterInterface::EndGpuRaster() {
  92. NOTREACHED();
  93. }
  94. void TestRasterInterface::BeginSharedImageAccessDirectCHROMIUM(GLuint texture,
  95. GLenum mode) {
  96. NOTREACHED();
  97. }
  98. void TestRasterInterface::EndSharedImageAccessDirectCHROMIUM(GLuint texture) {
  99. NOTREACHED();
  100. }
  101. void TestRasterInterface::InitializeDiscardableTextureCHROMIUM(GLuint texture) {
  102. NOTREACHED();
  103. }
  104. void TestRasterInterface::UnlockDiscardableTextureCHROMIUM(GLuint texture) {
  105. NOTREACHED();
  106. }
  107. bool TestRasterInterface::LockDiscardableTextureCHROMIUM(GLuint texture) {
  108. NOTREACHED();
  109. return false;
  110. }
  111. void TestRasterInterface::GenSyncTokenCHROMIUM(GLbyte* sync_token) {
  112. // Don't return a valid sync token if context is lost. This matches behavior
  113. // of CommandBufferProxyImpl.
  114. if (context_lost_)
  115. return;
  116. gpu::SyncToken sync_token_data(gpu::CommandBufferNamespace::GPU_IO,
  117. gpu::CommandBufferId(),
  118. next_insert_fence_sync_++);
  119. sync_token_data.SetVerifyFlush();
  120. memcpy(sync_token, &sync_token_data, sizeof(sync_token_data));
  121. }
  122. void TestRasterInterface::GenUnverifiedSyncTokenCHROMIUM(GLbyte* sync_token) {
  123. // Don't return a valid sync token if context is lost. This matches behavior
  124. // of CommandBufferProxyImpl.
  125. if (context_lost_)
  126. return;
  127. gpu::SyncToken sync_token_data(gpu::CommandBufferNamespace::GPU_IO,
  128. gpu::CommandBufferId(),
  129. next_insert_fence_sync_++);
  130. memcpy(sync_token, &sync_token_data, sizeof(sync_token_data));
  131. }
  132. void TestRasterInterface::VerifySyncTokensCHROMIUM(GLbyte** sync_tokens,
  133. GLsizei count) {
  134. for (GLsizei i = 0; i < count; ++i) {
  135. gpu::SyncToken sync_token_data;
  136. memcpy(sync_token_data.GetData(), sync_tokens[i], sizeof(sync_token_data));
  137. sync_token_data.SetVerifyFlush();
  138. memcpy(sync_tokens[i], &sync_token_data, sizeof(sync_token_data));
  139. }
  140. }
  141. void TestRasterInterface::WaitSyncTokenCHROMIUM(const GLbyte* sync_token) {
  142. gpu::SyncToken sync_token_data;
  143. if (sync_token)
  144. memcpy(&sync_token_data, sync_token, sizeof(sync_token_data));
  145. if (sync_token_data.release_count() >
  146. last_waited_sync_token_.release_count()) {
  147. last_waited_sync_token_ = sync_token_data;
  148. }
  149. }
  150. void TestRasterInterface::ShallowFlushCHROMIUM() {
  151. if (test_support_)
  152. test_support_->CallAllSyncPointCallbacks();
  153. }
  154. } // namespace viz