test_gles2_interface.cc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. // Copyright 2013 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_gles2_interface.h"
  5. #include "base/bind.h"
  6. #include "base/containers/contains.h"
  7. #include "base/lazy_instance.h"
  8. #include "base/logging.h"
  9. #include "base/memory/ptr_util.h"
  10. #include "base/memory/scoped_refptr.h"
  11. #include "components/viz/test/test_context_support.h"
  12. #include "gpu/GLES2/gl2extchromium.h"
  13. #include "gpu/command_buffer/common/mailbox.h"
  14. #include "testing/gtest/include/gtest/gtest.h"
  15. namespace viz {
  16. static unsigned NextContextId() {
  17. static uint16_t s_context_id = 1;
  18. // We need to ensure that the context_id fits in 16 bits since it is placed on
  19. // the top 16 bits of the 32 bit identifiers (program_id, framebuffer_id,
  20. // shader_id, etc.) generated by the context.
  21. if (s_context_id == std::numeric_limits<uint16_t>::max()) {
  22. LOG(ERROR) << "Exceeded max context id count; wrapping around";
  23. s_context_id = 1;
  24. }
  25. return s_context_id++;
  26. }
  27. TestGLES2Interface::TestGLES2Interface() : context_id_(NextContextId()) {
  28. // For stream textures.
  29. set_have_extension_egl_image(true);
  30. set_max_texture_size(2048);
  31. }
  32. TestGLES2Interface::~TestGLES2Interface() = default;
  33. void TestGLES2Interface::GenTextures(GLsizei n, GLuint* textures) {
  34. for (int i = 0; i < n; ++i) {
  35. textures[i] = NextTextureId();
  36. textures_.insert(textures[i]);
  37. }
  38. }
  39. void TestGLES2Interface::GenBuffers(GLsizei n, GLuint* buffers) {
  40. for (int i = 0; i < n; ++i)
  41. buffers[i] = NextBufferId();
  42. }
  43. void TestGLES2Interface::GenFramebuffers(GLsizei n, GLuint* framebuffers) {
  44. for (int i = 0; i < n; ++i)
  45. framebuffers[i] = NextFramebufferId();
  46. }
  47. void TestGLES2Interface::GenRenderbuffers(GLsizei n, GLuint* renderbuffers) {
  48. for (int i = 0; i < n; ++i)
  49. renderbuffers[i] = NextRenderbufferId();
  50. }
  51. void TestGLES2Interface::GenQueriesEXT(GLsizei n, GLuint* queries) {
  52. for (GLsizei i = 0; i < n; ++i) {
  53. queries[i] = 1u;
  54. }
  55. }
  56. void TestGLES2Interface::DeleteTextures(GLsizei n, const GLuint* textures) {
  57. for (int i = 0; i < n; ++i) {
  58. RetireTextureId(textures[i]);
  59. textures_.erase(textures[i]);
  60. }
  61. }
  62. void TestGLES2Interface::DeleteBuffers(GLsizei n, const GLuint* buffers) {
  63. for (int i = 0; i < n; ++i)
  64. RetireBufferId(buffers[i]);
  65. }
  66. void TestGLES2Interface::DeleteFramebuffers(GLsizei n,
  67. const GLuint* framebuffers) {
  68. for (int i = 0; i < n; ++i) {
  69. if (framebuffers[i]) {
  70. RetireFramebufferId(framebuffers[i]);
  71. if (framebuffers[i] == current_framebuffer_)
  72. current_framebuffer_ = 0;
  73. }
  74. }
  75. }
  76. void TestGLES2Interface::DeleteQueriesEXT(GLsizei n, const GLuint* queries) {
  77. }
  78. GLuint TestGLES2Interface::CreateShader(GLenum type) {
  79. unsigned shader = next_shader_id_++ | context_id_ << 16;
  80. shader_set_.insert(shader);
  81. return shader;
  82. }
  83. GLuint TestGLES2Interface::CreateProgram() {
  84. unsigned program = next_program_id_++ | context_id_ << 16;
  85. program_set_.insert(program);
  86. return program;
  87. }
  88. void TestGLES2Interface::BindTexture(GLenum target, GLuint texture) {
  89. if (times_bind_texture_succeeds_ >= 0) {
  90. if (!times_bind_texture_succeeds_) {
  91. LoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
  92. GL_INNOCENT_CONTEXT_RESET_ARB);
  93. }
  94. --times_bind_texture_succeeds_;
  95. }
  96. if (!texture)
  97. return;
  98. DCHECK(base::Contains(textures_, texture));
  99. used_textures_.insert(texture);
  100. }
  101. void TestGLES2Interface::GetIntegerv(GLenum pname, GLint* params) {
  102. if (pname == GL_MAX_TEXTURE_SIZE)
  103. *params = test_capabilities_.max_texture_size;
  104. else if (pname == GL_ACTIVE_TEXTURE)
  105. *params = GL_TEXTURE0;
  106. else if (pname == GL_UNPACK_ALIGNMENT)
  107. *params = unpack_alignment_;
  108. else if (pname == GL_FRAMEBUFFER_BINDING)
  109. *params = current_framebuffer_;
  110. else if (pname == GL_MAX_SAMPLES)
  111. *params = test_capabilities_.max_samples;
  112. }
  113. void TestGLES2Interface::GetShaderiv(GLuint shader,
  114. GLenum pname,
  115. GLint* params) {
  116. if (pname == GL_COMPILE_STATUS)
  117. *params = 1;
  118. }
  119. void TestGLES2Interface::GetProgramiv(GLuint program,
  120. GLenum pname,
  121. GLint* params) {
  122. if (pname == GL_LINK_STATUS)
  123. *params = 1;
  124. }
  125. void TestGLES2Interface::GetShaderPrecisionFormat(GLenum shadertype,
  126. GLenum precisiontype,
  127. GLint* range,
  128. GLint* precision) {
  129. // Return the minimum precision requirements of the GLES2
  130. // specification.
  131. switch (precisiontype) {
  132. case GL_LOW_INT:
  133. range[0] = 8;
  134. range[1] = 8;
  135. *precision = 0;
  136. break;
  137. case GL_MEDIUM_INT:
  138. range[0] = 10;
  139. range[1] = 10;
  140. *precision = 0;
  141. break;
  142. case GL_HIGH_INT:
  143. range[0] = 16;
  144. range[1] = 16;
  145. *precision = 0;
  146. break;
  147. case GL_LOW_FLOAT:
  148. range[0] = 8;
  149. range[1] = 8;
  150. *precision = 8;
  151. break;
  152. case GL_MEDIUM_FLOAT:
  153. range[0] = 14;
  154. range[1] = 14;
  155. *precision = 10;
  156. break;
  157. case GL_HIGH_FLOAT:
  158. range[0] = 62;
  159. range[1] = 62;
  160. *precision = 16;
  161. break;
  162. default:
  163. NOTREACHED();
  164. break;
  165. }
  166. }
  167. void TestGLES2Interface::UseProgram(GLuint program) {
  168. if (!program)
  169. return;
  170. if (!program_set_.count(program))
  171. ADD_FAILURE() << "useProgram called on unknown program " << program;
  172. }
  173. GLenum TestGLES2Interface::CheckFramebufferStatus(GLenum target) {
  174. if (context_lost_)
  175. return GL_FRAMEBUFFER_UNDEFINED_OES;
  176. return GL_FRAMEBUFFER_COMPLETE;
  177. }
  178. void TestGLES2Interface::Flush() {
  179. test_support_->CallAllSyncPointCallbacks();
  180. }
  181. void TestGLES2Interface::Finish() {
  182. test_support_->CallAllSyncPointCallbacks();
  183. }
  184. void TestGLES2Interface::ShallowFinishCHROMIUM() {
  185. test_support_->CallAllSyncPointCallbacks();
  186. }
  187. void TestGLES2Interface::BindRenderbuffer(GLenum target, GLuint renderbuffer) {
  188. if (!renderbuffer)
  189. return;
  190. if (renderbuffer != 0 &&
  191. renderbuffer_set_.find(renderbuffer) == renderbuffer_set_.end()) {
  192. ADD_FAILURE() << "bindRenderbuffer called with unknown renderbuffer";
  193. } else if ((renderbuffer >> 16) != context_id_) {
  194. ADD_FAILURE()
  195. << "bindRenderbuffer called with renderbuffer from other context";
  196. }
  197. }
  198. void TestGLES2Interface::BindFramebuffer(GLenum target, GLuint framebuffer) {
  199. if (framebuffer != 0 &&
  200. framebuffer_set_.find(framebuffer) == framebuffer_set_.end()) {
  201. ADD_FAILURE() << "bindFramebuffer called with unknown framebuffer";
  202. } else if (framebuffer != 0 && (framebuffer >> 16) != context_id_) {
  203. ADD_FAILURE()
  204. << "bindFramebuffer called with framebuffer from other context";
  205. } else {
  206. current_framebuffer_ = framebuffer;
  207. }
  208. }
  209. void TestGLES2Interface::BindBuffer(GLenum target, GLuint buffer) {
  210. bound_buffer_[target] = buffer;
  211. if (!buffer)
  212. return;
  213. unsigned context_id = buffer >> 16;
  214. unsigned buffer_id = buffer & 0xffff;
  215. DCHECK(buffer_id);
  216. DCHECK_LT(buffer_id, next_buffer_id_);
  217. DCHECK_EQ(context_id, context_id_);
  218. if (buffers_.count(bound_buffer_[target]) == 0)
  219. buffers_[bound_buffer_[target]] = std::make_unique<Buffer>();
  220. buffers_[bound_buffer_[target]]->target = target;
  221. }
  222. void TestGLES2Interface::PixelStorei(GLenum pname, GLint param) {
  223. switch (pname) {
  224. case GL_UNPACK_ALIGNMENT:
  225. // Param should be a power of two <= 8.
  226. EXPECT_EQ(0, param & (param - 1));
  227. EXPECT_GE(8, param);
  228. switch (param) {
  229. case 1:
  230. case 2:
  231. case 4:
  232. case 8:
  233. unpack_alignment_ = param;
  234. break;
  235. default:
  236. break;
  237. }
  238. break;
  239. default:
  240. break;
  241. }
  242. }
  243. void* TestGLES2Interface::MapBufferCHROMIUM(GLuint target, GLenum access) {
  244. DCHECK_GT(bound_buffer_.count(target), 0u);
  245. DCHECK_GT(buffers_.count(bound_buffer_[target]), 0u);
  246. DCHECK_EQ(target, buffers_[bound_buffer_[target]]->target);
  247. if (times_map_buffer_chromium_succeeds_ >= 0) {
  248. if (!times_map_buffer_chromium_succeeds_) {
  249. return nullptr;
  250. }
  251. --times_map_buffer_chromium_succeeds_;
  252. }
  253. return buffers_[bound_buffer_[target]]->pixels.get();
  254. }
  255. GLboolean TestGLES2Interface::UnmapBufferCHROMIUM(GLuint target) {
  256. DCHECK_GT(bound_buffer_.count(target), 0u);
  257. DCHECK_GT(buffers_.count(bound_buffer_[target]), 0u);
  258. DCHECK_EQ(target, buffers_[bound_buffer_[target]]->target);
  259. buffers_[bound_buffer_[target]]->pixels = nullptr;
  260. return true;
  261. }
  262. void TestGLES2Interface::BufferData(GLenum target,
  263. GLsizeiptr size,
  264. const void* data,
  265. GLenum usage) {
  266. DCHECK_GT(bound_buffer_.count(target), 0u);
  267. DCHECK_GT(buffers_.count(bound_buffer_[target]), 0u);
  268. DCHECK_EQ(target, buffers_[bound_buffer_[target]]->target);
  269. Buffer* buffer = buffers_[bound_buffer_[target]].get();
  270. if (context_lost_) {
  271. buffer->pixels = nullptr;
  272. return;
  273. }
  274. buffer->pixels.reset(new uint8_t[size]);
  275. buffer->size = size;
  276. if (data != nullptr)
  277. memcpy(buffer->pixels.get(), data, size);
  278. }
  279. void TestGLES2Interface::GenSyncTokenCHROMIUM(GLbyte* sync_token) {
  280. // Don't return a valid sync token if context is lost. This matches behavior
  281. // of CommandBufferProxyImpl.
  282. if (context_lost_)
  283. return;
  284. gpu::SyncToken sync_token_data(gpu::CommandBufferNamespace::GPU_IO,
  285. gpu::CommandBufferId(),
  286. next_insert_fence_sync_++);
  287. sync_token_data.SetVerifyFlush();
  288. memcpy(sync_token, &sync_token_data, sizeof(sync_token_data));
  289. }
  290. void TestGLES2Interface::GenUnverifiedSyncTokenCHROMIUM(GLbyte* sync_token) {
  291. // Don't return a valid sync token if context is lost. This matches behavior
  292. // of CommandBufferProxyImpl.
  293. if (context_lost_)
  294. return;
  295. gpu::SyncToken sync_token_data(gpu::CommandBufferNamespace::GPU_IO,
  296. gpu::CommandBufferId(),
  297. next_insert_fence_sync_++);
  298. memcpy(sync_token, &sync_token_data, sizeof(sync_token_data));
  299. }
  300. void TestGLES2Interface::VerifySyncTokensCHROMIUM(GLbyte** sync_tokens,
  301. GLsizei count) {
  302. for (GLsizei i = 0; i < count; ++i) {
  303. gpu::SyncToken sync_token_data;
  304. memcpy(sync_token_data.GetData(), sync_tokens[i], sizeof(sync_token_data));
  305. sync_token_data.SetVerifyFlush();
  306. memcpy(sync_tokens[i], &sync_token_data, sizeof(sync_token_data));
  307. }
  308. }
  309. void TestGLES2Interface::WaitSyncTokenCHROMIUM(const GLbyte* sync_token) {
  310. gpu::SyncToken sync_token_data;
  311. if (sync_token)
  312. memcpy(&sync_token_data, sync_token, sizeof(sync_token_data));
  313. if (sync_token_data.release_count() >
  314. last_waited_sync_token_.release_count()) {
  315. last_waited_sync_token_ = sync_token_data;
  316. }
  317. }
  318. void TestGLES2Interface::BeginQueryEXT(GLenum target, GLuint id) {}
  319. void TestGLES2Interface::EndQueryEXT(GLenum target) {
  320. if (times_end_query_succeeds_ >= 0) {
  321. if (!times_end_query_succeeds_) {
  322. LoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
  323. GL_INNOCENT_CONTEXT_RESET_ARB);
  324. }
  325. --times_end_query_succeeds_;
  326. }
  327. }
  328. void TestGLES2Interface::GetQueryObjectuivEXT(GLuint id,
  329. GLenum pname,
  330. GLuint* params) {
  331. // If the context is lost, behave as if result is available.
  332. if (pname == GL_QUERY_RESULT_AVAILABLE_EXT ||
  333. pname == GL_QUERY_RESULT_AVAILABLE_NO_FLUSH_CHROMIUM_EXT) {
  334. *params = 1;
  335. }
  336. }
  337. void TestGLES2Interface::ProduceTextureDirectCHROMIUM(GLuint texture,
  338. GLbyte* mailbox) {
  339. gpu::Mailbox gpu_mailbox = gpu::Mailbox::Generate();
  340. memcpy(mailbox, gpu_mailbox.name, sizeof(gpu_mailbox.name));
  341. }
  342. GLuint TestGLES2Interface::CreateAndConsumeTextureCHROMIUM(
  343. const GLbyte* mailbox) {
  344. GLuint texture_id;
  345. GenTextures(1, &texture_id);
  346. return texture_id;
  347. }
  348. GLuint TestGLES2Interface::CreateAndTexStorage2DSharedImageCHROMIUM(
  349. const GLbyte* mailbox) {
  350. GLuint texture_id;
  351. GenTextures(1, &texture_id);
  352. return texture_id;
  353. }
  354. void TestGLES2Interface::ResizeCHROMIUM(GLuint width,
  355. GLuint height,
  356. float device_scale,
  357. GLcolorSpace color_space,
  358. GLboolean has_alpha) {
  359. reshape_called_ = true;
  360. width_ = width;
  361. height_ = height;
  362. scale_factor_ = device_scale;
  363. }
  364. void TestGLES2Interface::LoseContextCHROMIUM(GLenum current, GLenum other) {
  365. if (context_lost_)
  366. return;
  367. context_lost_ = true;
  368. if (!context_lost_callback_.is_null())
  369. std::move(context_lost_callback_).Run();
  370. for (size_t i = 0; i < shared_contexts_.size(); ++i)
  371. shared_contexts_[i]->LoseContextCHROMIUM(current, other);
  372. shared_contexts_.clear();
  373. }
  374. GLenum TestGLES2Interface::GetGraphicsResetStatusKHR() {
  375. if (IsContextLost())
  376. return GL_UNKNOWN_CONTEXT_RESET_KHR;
  377. return GL_NO_ERROR;
  378. }
  379. void TestGLES2Interface::set_times_bind_texture_succeeds(int times) {
  380. times_bind_texture_succeeds_ = times;
  381. }
  382. void TestGLES2Interface::set_have_extension_io_surface(bool have) {
  383. test_capabilities_.iosurface = have;
  384. test_capabilities_.texture_rectangle = have;
  385. }
  386. void TestGLES2Interface::set_have_extension_egl_image(bool have) {
  387. test_capabilities_.egl_image_external = have;
  388. }
  389. void TestGLES2Interface::set_have_post_sub_buffer(bool have) {
  390. test_capabilities_.post_sub_buffer = have;
  391. }
  392. void TestGLES2Interface::set_have_swap_buffers_with_bounds(bool have) {
  393. test_capabilities_.swap_buffers_with_bounds = have;
  394. }
  395. void TestGLES2Interface::set_have_commit_overlay_planes(bool have) {
  396. test_capabilities_.commit_overlay_planes = have;
  397. }
  398. void TestGLES2Interface::set_have_discard_framebuffer(bool have) {
  399. test_capabilities_.discard_framebuffer = have;
  400. }
  401. void TestGLES2Interface::set_support_compressed_texture_etc1(bool support) {
  402. test_capabilities_.texture_format_etc1 = support;
  403. }
  404. void TestGLES2Interface::set_support_texture_format_bgra8888(bool support) {
  405. test_capabilities_.texture_format_bgra8888 = support;
  406. }
  407. void TestGLES2Interface::set_support_texture_storage(bool support) {
  408. test_capabilities_.texture_storage = support;
  409. }
  410. void TestGLES2Interface::set_support_texture_usage(bool support) {
  411. test_capabilities_.texture_usage = support;
  412. }
  413. void TestGLES2Interface::set_support_sync_query(bool support) {
  414. test_capabilities_.sync_query = support;
  415. }
  416. void TestGLES2Interface::set_support_texture_rectangle(bool support) {
  417. test_capabilities_.texture_rectangle = support;
  418. }
  419. void TestGLES2Interface::set_support_texture_half_float_linear(bool support) {
  420. test_capabilities_.texture_half_float_linear = support;
  421. }
  422. void TestGLES2Interface::set_support_texture_norm16(bool support) {
  423. test_capabilities_.texture_norm16 = support;
  424. }
  425. void TestGLES2Interface::set_msaa_is_slow(bool msaa_is_slow) {
  426. test_capabilities_.msaa_is_slow = msaa_is_slow;
  427. }
  428. void TestGLES2Interface::set_gpu_rasterization(bool gpu_rasterization) {
  429. test_capabilities_.gpu_rasterization = gpu_rasterization;
  430. }
  431. void TestGLES2Interface::set_avoid_stencil_buffers(bool avoid_stencil_buffers) {
  432. test_capabilities_.avoid_stencil_buffers = avoid_stencil_buffers;
  433. }
  434. void TestGLES2Interface::set_support_multisample_compatibility(bool support) {
  435. test_capabilities_.multisample_compatibility = support;
  436. }
  437. void TestGLES2Interface::set_support_texture_storage_image(bool support) {
  438. test_capabilities_.texture_storage_image = support;
  439. }
  440. void TestGLES2Interface::set_support_texture_npot(bool support) {
  441. test_capabilities_.texture_npot = support;
  442. }
  443. void TestGLES2Interface::set_max_texture_size(int size) {
  444. test_capabilities_.max_texture_size = size;
  445. }
  446. void TestGLES2Interface::set_supports_oop_raster(bool support) {
  447. test_capabilities_.supports_oop_raster = support;
  448. }
  449. void TestGLES2Interface::set_supports_shared_image_swap_chain(bool support) {
  450. test_capabilities_.shared_image_swap_chain = support;
  451. }
  452. void TestGLES2Interface::set_supports_gpu_memory_buffer_format(
  453. gfx::BufferFormat format,
  454. bool support) {
  455. if (support) {
  456. test_capabilities_.gpu_memory_buffer_formats.Add(format);
  457. } else {
  458. test_capabilities_.gpu_memory_buffer_formats.Remove(format);
  459. }
  460. }
  461. size_t TestGLES2Interface::NumTextures() const {
  462. return textures_.size();
  463. }
  464. GLuint TestGLES2Interface::NextTextureId() {
  465. GLuint texture_id = next_texture_id_++;
  466. DCHECK(texture_id < (1 << 16));
  467. texture_id |= context_id_ << 16;
  468. return texture_id;
  469. }
  470. void TestGLES2Interface::RetireTextureId(GLuint id) {
  471. unsigned context_id = id >> 16;
  472. unsigned texture_id = id & 0xffff;
  473. DCHECK(texture_id);
  474. DCHECK_LT(texture_id, next_texture_id_);
  475. DCHECK_EQ(context_id, context_id_);
  476. }
  477. GLuint TestGLES2Interface::NextBufferId() {
  478. GLuint buffer_id = next_buffer_id_++;
  479. DCHECK(buffer_id < (1 << 16));
  480. buffer_id |= context_id_ << 16;
  481. return buffer_id;
  482. }
  483. void TestGLES2Interface::RetireBufferId(GLuint id) {
  484. unsigned context_id = id >> 16;
  485. unsigned buffer_id = id & 0xffff;
  486. DCHECK(buffer_id);
  487. DCHECK_LT(buffer_id, next_buffer_id_);
  488. DCHECK_EQ(context_id, context_id_);
  489. }
  490. GLuint TestGLES2Interface::NextImageId() {
  491. GLuint image_id = next_image_id_++;
  492. DCHECK(image_id < (1 << 16));
  493. image_id |= context_id_ << 16;
  494. return image_id;
  495. }
  496. void TestGLES2Interface::RetireImageId(GLuint id) {
  497. unsigned context_id = id >> 16;
  498. unsigned image_id = id & 0xffff;
  499. DCHECK(image_id);
  500. DCHECK_LT(image_id, next_image_id_);
  501. DCHECK_EQ(context_id, context_id_);
  502. }
  503. GLuint TestGLES2Interface::NextFramebufferId() {
  504. GLuint id = next_framebuffer_id_++;
  505. DCHECK(id < (1 << 16));
  506. id |= context_id_ << 16;
  507. framebuffer_set_.insert(id);
  508. return id;
  509. }
  510. void TestGLES2Interface::RetireFramebufferId(GLuint id) {
  511. DCHECK(base::Contains(framebuffer_set_, id));
  512. framebuffer_set_.erase(id);
  513. }
  514. GLuint TestGLES2Interface::NextRenderbufferId() {
  515. GLuint id = next_renderbuffer_id_++;
  516. DCHECK(id < (1 << 16));
  517. id |= context_id_ << 16;
  518. renderbuffer_set_.insert(id);
  519. return id;
  520. }
  521. void TestGLES2Interface::RetireRenderbufferId(GLuint id) {
  522. DCHECK(base::Contains(renderbuffer_set_, id));
  523. renderbuffer_set_.erase(id);
  524. }
  525. size_t TestGLES2Interface::NumFramebuffers() const {
  526. return framebuffer_set_.size();
  527. }
  528. size_t TestGLES2Interface::NumRenderbuffers() const {
  529. return renderbuffer_set_.size();
  530. }
  531. TestGLES2Interface::Buffer::Buffer() : target(0), size(0) {}
  532. TestGLES2Interface::Buffer::~Buffer() = default;
  533. } // namespace viz