[Android] Introduce new UMA action for when user copies Image URL from context menu
[chromium-blink-merge.git] / cc / test / test_web_graphics_context_3d.cc
blob1e69bcbb8cc98bc4c9c288bd6909289f5c2b8981
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.
5 #include "cc/test/test_web_graphics_context_3d.h"
7 #include <algorithm>
8 #include <string>
10 #include "base/bind.h"
11 #include "base/lazy_instance.h"
12 #include "base/logging.h"
13 #include "base/message_loop/message_loop.h"
14 #include "base/numerics/safe_conversions.h"
15 #include "cc/test/test_context_support.h"
16 #include "gpu/GLES2/gl2extchromium.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/khronos/GLES2/gl2ext.h"
20 namespace cc {
22 static unsigned s_context_id = 1;
24 const GLuint TestWebGraphicsContext3D::kExternalTextureId = 1337;
26 static base::LazyInstance<base::Lock>::Leaky
27 g_shared_namespace_lock = LAZY_INSTANCE_INITIALIZER;
29 TestWebGraphicsContext3D::Namespace*
30 TestWebGraphicsContext3D::shared_namespace_ = NULL;
32 TestWebGraphicsContext3D::Namespace::Namespace()
33 : next_buffer_id(1),
34 next_image_id(1),
35 next_texture_id(1),
36 next_renderbuffer_id(1) {
39 TestWebGraphicsContext3D::Namespace::~Namespace() {
40 g_shared_namespace_lock.Get().AssertAcquired();
41 if (shared_namespace_ == this)
42 shared_namespace_ = NULL;
45 // static
46 scoped_ptr<TestWebGraphicsContext3D> TestWebGraphicsContext3D::Create() {
47 return make_scoped_ptr(new TestWebGraphicsContext3D());
50 TestWebGraphicsContext3D::TestWebGraphicsContext3D()
51 : context_id_(s_context_id++),
52 times_bind_texture_succeeds_(-1),
53 times_end_query_succeeds_(-1),
54 context_lost_(false),
55 times_map_buffer_chromium_succeeds_(-1),
56 current_used_transfer_buffer_usage_bytes_(0),
57 max_used_transfer_buffer_usage_bytes_(0),
58 next_program_id_(1000),
59 next_shader_id_(2000),
60 next_framebuffer_id_(1),
61 current_framebuffer_(0),
62 max_texture_size_(2048),
63 reshape_called_(false),
64 width_(0),
65 height_(0),
66 scale_factor_(-1.f),
67 test_support_(NULL),
68 last_update_type_(NO_UPDATE),
69 next_insert_sync_point_(1),
70 last_waited_sync_point_(0),
71 unpack_alignment_(4),
72 bound_buffer_(0),
73 weak_ptr_factory_(this) {
74 CreateNamespace();
75 set_support_image(true);
78 TestWebGraphicsContext3D::~TestWebGraphicsContext3D() {
79 base::AutoLock lock(g_shared_namespace_lock.Get());
80 namespace_ = NULL;
83 void TestWebGraphicsContext3D::CreateNamespace() {
84 base::AutoLock lock(g_shared_namespace_lock.Get());
85 if (shared_namespace_) {
86 namespace_ = shared_namespace_;
87 } else {
88 namespace_ = new Namespace;
89 shared_namespace_ = namespace_.get();
93 void TestWebGraphicsContext3D::reshapeWithScaleFactor(
94 int width, int height, float scale_factor) {
95 reshape_called_ = true;
96 width_ = width;
97 height_ = height;
98 scale_factor_ = scale_factor;
101 bool TestWebGraphicsContext3D::isContextLost() {
102 return context_lost_;
105 GLenum TestWebGraphicsContext3D::checkFramebufferStatus(
106 GLenum target) {
107 if (context_lost_)
108 return GL_FRAMEBUFFER_UNDEFINED_OES;
109 return GL_FRAMEBUFFER_COMPLETE;
112 GLint TestWebGraphicsContext3D::getUniformLocation(
113 GLuint program,
114 const GLchar* name) {
115 return 0;
118 GLsizeiptr TestWebGraphicsContext3D::getVertexAttribOffset(
119 GLuint index,
120 GLenum pname) {
121 return 0;
124 GLboolean TestWebGraphicsContext3D::isBuffer(
125 GLuint buffer) {
126 return false;
129 GLboolean TestWebGraphicsContext3D::isEnabled(
130 GLenum cap) {
131 return false;
134 GLboolean TestWebGraphicsContext3D::isFramebuffer(
135 GLuint framebuffer) {
136 return false;
139 GLboolean TestWebGraphicsContext3D::isProgram(
140 GLuint program) {
141 return false;
144 GLboolean TestWebGraphicsContext3D::isRenderbuffer(
145 GLuint renderbuffer) {
146 return false;
149 GLboolean TestWebGraphicsContext3D::isShader(
150 GLuint shader) {
151 return false;
154 GLboolean TestWebGraphicsContext3D::isTexture(
155 GLuint texture) {
156 return false;
159 void TestWebGraphicsContext3D::genBuffers(GLsizei count, GLuint* ids) {
160 for (int i = 0; i < count; ++i)
161 ids[i] = NextBufferId();
164 void TestWebGraphicsContext3D::genFramebuffers(
165 GLsizei count, GLuint* ids) {
166 for (int i = 0; i < count; ++i)
167 ids[i] = NextFramebufferId();
170 void TestWebGraphicsContext3D::genRenderbuffers(
171 GLsizei count, GLuint* ids) {
172 for (int i = 0; i < count; ++i)
173 ids[i] = NextRenderbufferId();
176 void TestWebGraphicsContext3D::genTextures(GLsizei count, GLuint* ids) {
177 for (int i = 0; i < count; ++i) {
178 ids[i] = NextTextureId();
179 DCHECK_NE(ids[i], kExternalTextureId);
181 base::AutoLock lock(namespace_->lock);
182 for (int i = 0; i < count; ++i)
183 namespace_->textures.Append(ids[i], new TestTexture());
186 void TestWebGraphicsContext3D::deleteBuffers(GLsizei count, GLuint* ids) {
187 for (int i = 0; i < count; ++i)
188 RetireBufferId(ids[i]);
191 void TestWebGraphicsContext3D::deleteFramebuffers(
192 GLsizei count, GLuint* ids) {
193 for (int i = 0; i < count; ++i) {
194 if (ids[i]) {
195 RetireFramebufferId(ids[i]);
196 if (ids[i] == current_framebuffer_)
197 current_framebuffer_ = 0;
202 void TestWebGraphicsContext3D::deleteRenderbuffers(
203 GLsizei count, GLuint* ids) {
204 for (int i = 0; i < count; ++i)
205 RetireRenderbufferId(ids[i]);
208 void TestWebGraphicsContext3D::deleteTextures(GLsizei count, GLuint* ids) {
209 for (int i = 0; i < count; ++i)
210 RetireTextureId(ids[i]);
211 base::AutoLock lock(namespace_->lock);
212 for (int i = 0; i < count; ++i) {
213 namespace_->textures.Remove(ids[i]);
214 texture_targets_.UnbindTexture(ids[i]);
218 GLuint TestWebGraphicsContext3D::createBuffer() {
219 GLuint id;
220 genBuffers(1, &id);
221 return id;
224 GLuint TestWebGraphicsContext3D::createFramebuffer() {
225 GLuint id;
226 genFramebuffers(1, &id);
227 return id;
230 GLuint TestWebGraphicsContext3D::createRenderbuffer() {
231 GLuint id;
232 genRenderbuffers(1, &id);
233 return id;
236 GLuint TestWebGraphicsContext3D::createTexture() {
237 GLuint id;
238 genTextures(1, &id);
239 return id;
242 void TestWebGraphicsContext3D::deleteBuffer(GLuint id) {
243 deleteBuffers(1, &id);
246 void TestWebGraphicsContext3D::deleteFramebuffer(GLuint id) {
247 deleteFramebuffers(1, &id);
250 void TestWebGraphicsContext3D::deleteRenderbuffer(GLuint id) {
251 deleteRenderbuffers(1, &id);
254 void TestWebGraphicsContext3D::deleteTexture(GLuint id) {
255 deleteTextures(1, &id);
258 unsigned TestWebGraphicsContext3D::createProgram() {
259 unsigned program = next_program_id_++ | context_id_ << 16;
260 program_set_.insert(program);
261 return program;
264 GLuint TestWebGraphicsContext3D::createShader(GLenum) {
265 unsigned shader = next_shader_id_++ | context_id_ << 16;
266 shader_set_.insert(shader);
267 return shader;
270 GLuint TestWebGraphicsContext3D::createExternalTexture() {
271 base::AutoLock lock(namespace_->lock);
272 namespace_->textures.Append(kExternalTextureId, new TestTexture());
273 return kExternalTextureId;
276 void TestWebGraphicsContext3D::deleteProgram(GLuint id) {
277 if (!program_set_.count(id))
278 ADD_FAILURE() << "deleteProgram called on unknown program " << id;
279 program_set_.erase(id);
282 void TestWebGraphicsContext3D::deleteShader(GLuint id) {
283 if (!shader_set_.count(id))
284 ADD_FAILURE() << "deleteShader called on unknown shader " << id;
285 shader_set_.erase(id);
288 void TestWebGraphicsContext3D::attachShader(GLuint program, GLuint shader) {
289 if (!program_set_.count(program))
290 ADD_FAILURE() << "attachShader called with unknown program " << program;
291 if (!shader_set_.count(shader))
292 ADD_FAILURE() << "attachShader called with unknown shader " << shader;
295 void TestWebGraphicsContext3D::useProgram(GLuint program) {
296 if (!program)
297 return;
298 if (!program_set_.count(program))
299 ADD_FAILURE() << "useProgram called on unknown program " << program;
302 void TestWebGraphicsContext3D::bindFramebuffer(
303 GLenum target, GLuint framebuffer) {
304 base::AutoLock lock_for_framebuffer_access(namespace_->lock);
305 if (framebuffer != 0 &&
306 framebuffer_set_.find(framebuffer) == framebuffer_set_.end()) {
307 ADD_FAILURE() << "bindFramebuffer called with unknown framebuffer";
308 } else if (framebuffer != 0 && (framebuffer >> 16) != context_id_) {
309 ADD_FAILURE()
310 << "bindFramebuffer called with framebuffer from other context";
311 } else {
312 current_framebuffer_ = framebuffer;
316 void TestWebGraphicsContext3D::bindRenderbuffer(
317 GLenum target, GLuint renderbuffer) {
318 if (!renderbuffer)
319 return;
320 base::AutoLock lock_for_renderbuffer_access(namespace_->lock);
321 if (renderbuffer != 0 &&
322 namespace_->renderbuffer_set.find(renderbuffer) ==
323 namespace_->renderbuffer_set.end()) {
324 ADD_FAILURE() << "bindRenderbuffer called with unknown renderbuffer";
325 } else if ((renderbuffer >> 16) != context_id_) {
326 ADD_FAILURE()
327 << "bindRenderbuffer called with renderbuffer from other context";
331 void TestWebGraphicsContext3D::bindTexture(
332 GLenum target, GLuint texture_id) {
333 if (times_bind_texture_succeeds_ >= 0) {
334 if (!times_bind_texture_succeeds_) {
335 loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
336 GL_INNOCENT_CONTEXT_RESET_ARB);
338 --times_bind_texture_succeeds_;
341 if (!texture_id)
342 return;
343 base::AutoLock lock(namespace_->lock);
344 DCHECK(namespace_->textures.ContainsId(texture_id));
345 texture_targets_.BindTexture(target, texture_id);
346 used_textures_.insert(texture_id);
349 GLuint TestWebGraphicsContext3D::BoundTextureId(
350 GLenum target) {
351 return texture_targets_.BoundTexture(target);
354 scoped_refptr<TestTexture> TestWebGraphicsContext3D::BoundTexture(
355 GLenum target) {
356 // The caller is expected to lock the namespace for texture access.
357 namespace_->lock.AssertAcquired();
358 return namespace_->textures.TextureForId(BoundTextureId(target));
361 scoped_refptr<TestTexture> TestWebGraphicsContext3D::UnboundTexture(
362 GLuint texture) {
363 // The caller is expected to lock the namespace for texture access.
364 namespace_->lock.AssertAcquired();
365 return namespace_->textures.TextureForId(texture);
368 void TestWebGraphicsContext3D::CheckTextureIsBound(GLenum target) {
369 DCHECK(BoundTextureId(target));
372 GLuint TestWebGraphicsContext3D::createQueryEXT() { return 1u; }
374 void TestWebGraphicsContext3D::endQueryEXT(GLenum target) {
375 if (times_end_query_succeeds_ >= 0) {
376 if (!times_end_query_succeeds_) {
377 loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
378 GL_INNOCENT_CONTEXT_RESET_ARB);
380 --times_end_query_succeeds_;
384 void TestWebGraphicsContext3D::getQueryObjectuivEXT(
385 GLuint query,
386 GLenum pname,
387 GLuint* params) {
388 // If the context is lost, behave as if result is available.
389 if (pname == GL_QUERY_RESULT_AVAILABLE_EXT)
390 *params = 1;
393 void TestWebGraphicsContext3D::getIntegerv(
394 GLenum pname,
395 GLint* value) {
396 if (pname == GL_MAX_TEXTURE_SIZE)
397 *value = max_texture_size_;
398 else if (pname == GL_ACTIVE_TEXTURE)
399 *value = GL_TEXTURE0;
400 else if (pname == GL_UNPACK_ALIGNMENT)
401 *value = unpack_alignment_;
402 else if (pname == GL_FRAMEBUFFER_BINDING)
403 *value = current_framebuffer_;
406 void TestWebGraphicsContext3D::getProgramiv(GLuint program,
407 GLenum pname,
408 GLint* value) {
409 if (pname == GL_LINK_STATUS)
410 *value = 1;
413 void TestWebGraphicsContext3D::getShaderiv(GLuint shader,
414 GLenum pname,
415 GLint* value) {
416 if (pname == GL_COMPILE_STATUS)
417 *value = 1;
420 void TestWebGraphicsContext3D::getShaderPrecisionFormat(GLenum shadertype,
421 GLenum precisiontype,
422 GLint* range,
423 GLint* precision) {
424 // Return the minimum precision requirements of the GLES2
425 // specification.
426 switch (precisiontype) {
427 case GL_LOW_INT:
428 range[0] = 8;
429 range[1] = 8;
430 *precision = 0;
431 break;
432 case GL_MEDIUM_INT:
433 range[0] = 10;
434 range[1] = 10;
435 *precision = 0;
436 break;
437 case GL_HIGH_INT:
438 range[0] = 16;
439 range[1] = 16;
440 *precision = 0;
441 break;
442 case GL_LOW_FLOAT:
443 range[0] = 8;
444 range[1] = 8;
445 *precision = 8;
446 break;
447 case GL_MEDIUM_FLOAT:
448 range[0] = 14;
449 range[1] = 14;
450 *precision = 10;
451 break;
452 case GL_HIGH_FLOAT:
453 range[0] = 62;
454 range[1] = 62;
455 *precision = 16;
456 break;
457 default:
458 NOTREACHED();
459 break;
463 void TestWebGraphicsContext3D::genMailboxCHROMIUM(GLbyte* mailbox) {
464 static char mailbox_name1 = '1';
465 static char mailbox_name2 = '1';
466 mailbox[0] = mailbox_name1;
467 mailbox[1] = mailbox_name2;
468 mailbox[2] = '\0';
469 if (++mailbox_name1 == 0) {
470 mailbox_name1 = '1';
471 ++mailbox_name2;
475 GLuint TestWebGraphicsContext3D::createAndConsumeTextureCHROMIUM(
476 GLenum target,
477 const GLbyte* mailbox) {
478 GLuint texture_id = createTexture();
479 consumeTextureCHROMIUM(target, mailbox);
480 return texture_id;
483 void TestWebGraphicsContext3D::loseContextCHROMIUM(GLenum current,
484 GLenum other) {
485 if (context_lost_)
486 return;
487 context_lost_ = true;
488 if (!context_lost_callback_.is_null())
489 context_lost_callback_.Run();
491 for (size_t i = 0; i < shared_contexts_.size(); ++i)
492 shared_contexts_[i]->loseContextCHROMIUM(current, other);
493 shared_contexts_.clear();
496 void TestWebGraphicsContext3D::finish() {
497 test_support_->CallAllSyncPointCallbacks();
500 void TestWebGraphicsContext3D::flush() {
501 test_support_->CallAllSyncPointCallbacks();
504 void TestWebGraphicsContext3D::shallowFinishCHROMIUM() {
505 test_support_->CallAllSyncPointCallbacks();
508 GLint TestWebGraphicsContext3D::getAttribLocation(GLuint program,
509 const GLchar* name) {
510 return 0;
513 GLenum TestWebGraphicsContext3D::getError() { return GL_NO_ERROR; }
515 void TestWebGraphicsContext3D::bindBuffer(GLenum target,
516 GLuint buffer) {
517 bound_buffer_ = buffer;
518 if (!bound_buffer_)
519 return;
520 unsigned context_id = buffer >> 16;
521 unsigned buffer_id = buffer & 0xffff;
522 base::AutoLock lock(namespace_->lock);
523 DCHECK(buffer_id);
524 DCHECK_LT(buffer_id, namespace_->next_buffer_id);
525 DCHECK_EQ(context_id, context_id_);
527 base::ScopedPtrHashMap<unsigned, scoped_ptr<Buffer>>& buffers =
528 namespace_->buffers;
529 if (buffers.count(bound_buffer_) == 0)
530 buffers.set(bound_buffer_, make_scoped_ptr(new Buffer).Pass());
532 buffers.get(bound_buffer_)->target = target;
535 void TestWebGraphicsContext3D::bufferData(GLenum target,
536 GLsizeiptr size,
537 const void* data,
538 GLenum usage) {
539 base::AutoLock lock(namespace_->lock);
540 base::ScopedPtrHashMap<unsigned, scoped_ptr<Buffer>>& buffers =
541 namespace_->buffers;
542 DCHECK_GT(buffers.count(bound_buffer_), 0u);
543 DCHECK_EQ(target, buffers.get(bound_buffer_)->target);
544 Buffer* buffer = buffers.get(bound_buffer_);
545 if (context_lost_) {
546 buffer->pixels = nullptr;
547 return;
550 size_t old_size = buffer->size;
552 buffer->pixels.reset(new uint8[size]);
553 buffer->size = size;
554 if (data != NULL)
555 memcpy(buffer->pixels.get(), data, size);
556 if (buffer->target == GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM)
557 current_used_transfer_buffer_usage_bytes_ +=
558 base::checked_cast<int>(buffer->size) -
559 base::checked_cast<int>(old_size);
560 max_used_transfer_buffer_usage_bytes_ =
561 std::max(max_used_transfer_buffer_usage_bytes_,
562 current_used_transfer_buffer_usage_bytes_);
565 void TestWebGraphicsContext3D::pixelStorei(GLenum pname, GLint param) {
566 switch (pname) {
567 case GL_UNPACK_ALIGNMENT:
568 // Param should be a power of two <= 8.
569 EXPECT_EQ(0, param & (param - 1));
570 EXPECT_GE(8, param);
571 switch (param) {
572 case 1:
573 case 2:
574 case 4:
575 case 8:
576 unpack_alignment_ = param;
577 break;
578 default:
579 break;
581 break;
582 default:
583 break;
587 void* TestWebGraphicsContext3D::mapBufferCHROMIUM(GLenum target,
588 GLenum access) {
589 base::AutoLock lock(namespace_->lock);
590 base::ScopedPtrHashMap<unsigned, scoped_ptr<Buffer>>& buffers =
591 namespace_->buffers;
592 DCHECK_GT(buffers.count(bound_buffer_), 0u);
593 DCHECK_EQ(target, buffers.get(bound_buffer_)->target);
594 if (times_map_buffer_chromium_succeeds_ >= 0) {
595 if (!times_map_buffer_chromium_succeeds_) {
596 return NULL;
598 --times_map_buffer_chromium_succeeds_;
601 return buffers.get(bound_buffer_)->pixels.get();
604 GLboolean TestWebGraphicsContext3D::unmapBufferCHROMIUM(
605 GLenum target) {
606 base::AutoLock lock(namespace_->lock);
607 base::ScopedPtrHashMap<unsigned, scoped_ptr<Buffer>>& buffers =
608 namespace_->buffers;
609 DCHECK_GT(buffers.count(bound_buffer_), 0u);
610 DCHECK_EQ(target, buffers.get(bound_buffer_)->target);
611 buffers.get(bound_buffer_)->pixels = nullptr;
612 return true;
615 GLuint TestWebGraphicsContext3D::createImageCHROMIUM(ClientBuffer buffer,
616 GLsizei width,
617 GLsizei height,
618 GLenum internalformat) {
619 DCHECK_EQ(GL_RGBA, static_cast<int>(internalformat));
620 GLuint image_id = NextImageId();
621 base::AutoLock lock(namespace_->lock);
622 base::hash_set<unsigned>& images = namespace_->images;
623 images.insert(image_id);
624 return image_id;
627 void TestWebGraphicsContext3D::destroyImageCHROMIUM(
628 GLuint id) {
629 RetireImageId(id);
630 base::AutoLock lock(namespace_->lock);
631 base::hash_set<unsigned>& images = namespace_->images;
632 if (!images.count(id))
633 ADD_FAILURE() << "destroyImageCHROMIUM called on unknown image " << id;
634 images.erase(id);
637 GLuint TestWebGraphicsContext3D::createGpuMemoryBufferImageCHROMIUM(
638 GLsizei width,
639 GLsizei height,
640 GLenum internalformat,
641 GLenum usage) {
642 DCHECK_EQ(GL_RGBA, static_cast<int>(internalformat));
643 GLuint image_id = NextImageId();
644 base::AutoLock lock(namespace_->lock);
645 base::hash_set<unsigned>& images = namespace_->images;
646 images.insert(image_id);
647 return image_id;
650 unsigned TestWebGraphicsContext3D::insertSyncPoint() {
651 return next_insert_sync_point_++;
654 void TestWebGraphicsContext3D::waitSyncPoint(unsigned sync_point) {
655 if (sync_point)
656 last_waited_sync_point_ = sync_point;
659 size_t TestWebGraphicsContext3D::NumTextures() const {
660 base::AutoLock lock(namespace_->lock);
661 return namespace_->textures.Size();
664 GLuint TestWebGraphicsContext3D::TextureAt(int i) const {
665 base::AutoLock lock(namespace_->lock);
666 return namespace_->textures.IdAt(i);
669 GLuint TestWebGraphicsContext3D::NextTextureId() {
670 base::AutoLock lock(namespace_->lock);
671 GLuint texture_id = namespace_->next_texture_id++;
672 DCHECK(texture_id < (1 << 16));
673 texture_id |= context_id_ << 16;
674 return texture_id;
677 void TestWebGraphicsContext3D::RetireTextureId(GLuint id) {
678 base::AutoLock lock(namespace_->lock);
679 unsigned context_id = id >> 16;
680 unsigned texture_id = id & 0xffff;
681 DCHECK(texture_id);
682 DCHECK_LT(texture_id, namespace_->next_texture_id);
683 DCHECK_EQ(context_id, context_id_);
686 GLuint TestWebGraphicsContext3D::NextBufferId() {
687 base::AutoLock lock(namespace_->lock);
688 GLuint buffer_id = namespace_->next_buffer_id++;
689 DCHECK(buffer_id < (1 << 16));
690 buffer_id |= context_id_ << 16;
691 return buffer_id;
694 void TestWebGraphicsContext3D::RetireBufferId(GLuint id) {
695 base::AutoLock lock(namespace_->lock);
696 unsigned context_id = id >> 16;
697 unsigned buffer_id = id & 0xffff;
698 DCHECK(buffer_id);
699 DCHECK_LT(buffer_id, namespace_->next_buffer_id);
700 DCHECK_EQ(context_id, context_id_);
703 GLuint TestWebGraphicsContext3D::NextImageId() {
704 base::AutoLock lock(namespace_->lock);
705 GLuint image_id = namespace_->next_image_id++;
706 DCHECK(image_id < (1 << 16));
707 image_id |= context_id_ << 16;
708 return image_id;
711 void TestWebGraphicsContext3D::RetireImageId(GLuint id) {
712 base::AutoLock lock(namespace_->lock);
713 unsigned context_id = id >> 16;
714 unsigned image_id = id & 0xffff;
715 DCHECK(image_id);
716 DCHECK_LT(image_id, namespace_->next_image_id);
717 DCHECK_EQ(context_id, context_id_);
720 GLuint TestWebGraphicsContext3D::NextFramebufferId() {
721 base::AutoLock lock_for_framebuffer_access(namespace_->lock);
722 GLuint id = next_framebuffer_id_++;
723 DCHECK(id < (1 << 16));
724 id |= context_id_ << 16;
725 framebuffer_set_.insert(id);
726 return id;
729 void TestWebGraphicsContext3D::RetireFramebufferId(GLuint id) {
730 base::AutoLock lock_for_framebuffer_access(namespace_->lock);
731 DCHECK(framebuffer_set_.find(id) != framebuffer_set_.end());
732 framebuffer_set_.erase(id);
735 GLuint TestWebGraphicsContext3D::NextRenderbufferId() {
736 base::AutoLock lock_for_renderbuffer_access(namespace_->lock);
737 GLuint id = namespace_->next_renderbuffer_id++;
738 DCHECK(id < (1 << 16));
739 id |= context_id_ << 16;
740 namespace_->renderbuffer_set.insert(id);
741 return id;
744 void TestWebGraphicsContext3D::RetireRenderbufferId(GLuint id) {
745 base::AutoLock lock_for_renderbuffer_access(namespace_->lock);
746 DCHECK(namespace_->renderbuffer_set.find(id) !=
747 namespace_->renderbuffer_set.end());
748 namespace_->renderbuffer_set.erase(id);
751 void TestWebGraphicsContext3D::SetMaxTransferBufferUsageBytes(
752 size_t max_transfer_buffer_usage_bytes) {
753 test_capabilities_.max_transfer_buffer_usage_bytes =
754 max_transfer_buffer_usage_bytes;
757 void TestWebGraphicsContext3D::SetMaxSamples(int max_samples) {
758 test_capabilities_.gpu.max_samples = max_samples;
761 TestWebGraphicsContext3D::TextureTargets::TextureTargets() {
762 // Initialize default bindings.
763 bound_textures_[GL_TEXTURE_2D] = 0;
764 bound_textures_[GL_TEXTURE_EXTERNAL_OES] = 0;
765 bound_textures_[GL_TEXTURE_RECTANGLE_ARB] = 0;
768 TestWebGraphicsContext3D::TextureTargets::~TextureTargets() {}
770 void TestWebGraphicsContext3D::TextureTargets::BindTexture(
771 GLenum target,
772 GLuint id) {
773 // Make sure this is a supported target by seeing if it was bound to before.
774 DCHECK(bound_textures_.find(target) != bound_textures_.end());
775 bound_textures_[target] = id;
778 void TestWebGraphicsContext3D::texParameteri(GLenum target,
779 GLenum pname,
780 GLint param) {
781 CheckTextureIsBound(target);
782 base::AutoLock lock_for_texture_access(namespace_->lock);
783 scoped_refptr<TestTexture> texture = BoundTexture(target);
784 DCHECK(texture->IsValidParameter(pname));
785 texture->params[pname] = param;
788 void TestWebGraphicsContext3D::getTexParameteriv(GLenum target,
789 GLenum pname,
790 GLint* value) {
791 CheckTextureIsBound(target);
792 base::AutoLock lock_for_texture_access(namespace_->lock);
793 scoped_refptr<TestTexture> texture = BoundTexture(target);
794 DCHECK(texture->IsValidParameter(pname));
795 TestTexture::TextureParametersMap::iterator it = texture->params.find(pname);
796 if (it != texture->params.end())
797 *value = it->second;
800 void TestWebGraphicsContext3D::TextureTargets::UnbindTexture(
801 GLuint id) {
802 // Bind zero to any targets that the id is bound to.
803 for (TargetTextureMap::iterator it = bound_textures_.begin();
804 it != bound_textures_.end();
805 it++) {
806 if (it->second == id)
807 it->second = 0;
811 GLuint TestWebGraphicsContext3D::TextureTargets::BoundTexture(
812 GLenum target) {
813 DCHECK(bound_textures_.find(target) != bound_textures_.end());
814 return bound_textures_[target];
817 TestWebGraphicsContext3D::Buffer::Buffer() : target(0), size(0) {}
819 TestWebGraphicsContext3D::Buffer::~Buffer() {}
821 TestWebGraphicsContext3D::Image::Image() {}
823 TestWebGraphicsContext3D::Image::~Image() {}
825 } // namespace cc