diff options
author | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-13 19:31:05 +0000 |
---|---|---|
committer | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-13 19:31:05 +0000 |
commit | 95fc42145e5a8cdb0c7624060bf5bfd298838e19 (patch) | |
tree | 2b9a293e6581a60afbe69fe32177cf2b73704b9e /cc/test | |
parent | 14ac682365925234f1f7bc3572f185b69f798814 (diff) | |
download | chromium_src-95fc42145e5a8cdb0c7624060bf5bfd298838e19.zip chromium_src-95fc42145e5a8cdb0c7624060bf5bfd298838e19.tar.gz chromium_src-95fc42145e5a8cdb0c7624060bf5bfd298838e19.tar.bz2 |
aura,cc: Make TestContextProvider usable outside cc.
This makes the TestWebGraphicsContext3D available outside
of cc, and replaces ui::TestWGC3D with the class from cc.
R=jbauman, piman
BUG=258625
Review URL: https://chromiumcodereview.appspot.com/22293007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@217308 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/test')
-rw-r--r-- | cc/test/fake_layer_tree_host_client.cc | 2 | ||||
-rw-r--r-- | cc/test/fake_output_surface.h | 2 | ||||
-rw-r--r-- | cc/test/fake_web_graphics_context_3d_unittest.cc | 2 | ||||
-rw-r--r-- | cc/test/test_web_graphics_context_3d.cc | 666 | ||||
-rw-r--r-- | cc/test/test_web_graphics_context_3d.h | 297 |
5 files changed, 3 insertions, 966 deletions
diff --git a/cc/test/fake_layer_tree_host_client.cc b/cc/test/fake_layer_tree_host_client.cc index d0a1954..5e2caab 100644 --- a/cc/test/fake_layer_tree_host_client.cc +++ b/cc/test/fake_layer_tree_host_client.cc @@ -4,9 +4,9 @@ #include "cc/test/fake_layer_tree_host_client.h" +#include "cc/debug/test_web_graphics_context_3d.h" #include "cc/output/context_provider.h" #include "cc/test/fake_output_surface.h" -#include "cc/test/test_web_graphics_context_3d.h" namespace cc { diff --git a/cc/test/fake_output_surface.h b/cc/test/fake_output_surface.h index 5091dff..12fdcfc 100644 --- a/cc/test/fake_output_surface.h +++ b/cc/test/fake_output_surface.h @@ -7,11 +7,11 @@ #include "base/callback.h" #include "base/time/time.h" +#include "cc/debug/test_web_graphics_context_3d.h" #include "cc/output/begin_frame_args.h" #include "cc/output/compositor_frame.h" #include "cc/output/output_surface.h" #include "cc/output/software_output_device.h" -#include "cc/test/test_web_graphics_context_3d.h" #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" namespace cc { diff --git a/cc/test/fake_web_graphics_context_3d_unittest.cc b/cc/test/fake_web_graphics_context_3d_unittest.cc index 3d119ee..ef0f143f 100644 --- a/cc/test/fake_web_graphics_context_3d_unittest.cc +++ b/cc/test/fake_web_graphics_context_3d_unittest.cc @@ -4,7 +4,7 @@ #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" -#include "cc/test/test_web_graphics_context_3d.h" +#include "cc/debug/test_web_graphics_context_3d.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/cc/test/test_web_graphics_context_3d.cc b/cc/test/test_web_graphics_context_3d.cc deleted file mode 100644 index e68f938..0000000 --- a/cc/test/test_web_graphics_context_3d.cc +++ /dev/null @@ -1,666 +0,0 @@ -// Copyright 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "cc/test/test_web_graphics_context_3d.h" - -#include <algorithm> -#include <string> - -#include "base/bind.h" -#include "base/lazy_instance.h" -#include "base/logging.h" -#include "base/message_loop/message_loop.h" -#include "gpu/GLES2/gl2extchromium.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "third_party/khronos/GLES2/gl2ext.h" - -using WebKit::WGC3Dboolean; -using WebKit::WGC3Dchar; -using WebKit::WGC3Denum; -using WebKit::WGC3Dint; -using WebKit::WGC3Dsizei; -using WebKit::WGC3Dsizeiptr; -using WebKit::WGC3Duint; -using WebKit::WebGLId; -using WebKit::WebGraphicsContext3D; - -namespace cc { - -static const WebGLId kFramebufferId = 1; -static const WebGLId kProgramId = 2; -static const WebGLId kRenderbufferId = 3; -static const WebGLId kShaderId = 4; - -static unsigned s_context_id = 1; - -const WebGLId TestWebGraphicsContext3D::kExternalTextureId = 1337; - -static base::LazyInstance<base::Lock>::Leaky - g_shared_namespace_lock = LAZY_INSTANCE_INITIALIZER; - -TestWebGraphicsContext3D::Namespace* - TestWebGraphicsContext3D::shared_namespace_ = NULL; - -TestWebGraphicsContext3D::Namespace::Namespace() - : next_buffer_id(1), - next_image_id(1), - next_texture_id(1) { -} - -TestWebGraphicsContext3D::Namespace::~Namespace() { - g_shared_namespace_lock.Get().AssertAcquired(); - if (shared_namespace_ == this) - shared_namespace_ = NULL; -} - -// static -scoped_ptr<TestWebGraphicsContext3D> TestWebGraphicsContext3D::Create() { - return make_scoped_ptr(new TestWebGraphicsContext3D()); -} - -// static -base::Callback<scoped_ptr<TestWebGraphicsContext3D>()> -TestWebGraphicsContext3D::CreateFactory() { - return base::Bind(&TestWebGraphicsContext3D::Create); -} - -static scoped_ptr<WebKit::WebGraphicsContext3D> CreateBaseFactory() { - return scoped_ptr<WebKit::WebGraphicsContext3D>( - TestWebGraphicsContext3D::Create()); -} - -// static -base::Callback<scoped_ptr<WebKit::WebGraphicsContext3D>()> -TestWebGraphicsContext3D::CreateBaseFactory() { - return base::Bind(&cc::CreateBaseFactory); -} - -TestWebGraphicsContext3D::TestWebGraphicsContext3D() - : FakeWebGraphicsContext3D(), - context_id_(s_context_id++), - support_swapbuffers_complete_callback_(true), - have_extension_io_surface_(false), - have_extension_egl_image_(false), - times_make_current_succeeds_(-1), - times_bind_texture_succeeds_(-1), - times_end_query_succeeds_(-1), - times_gen_mailbox_succeeds_(-1), - context_lost_(false), - times_map_image_chromium_succeeds_(-1), - times_map_buffer_chromium_succeeds_(-1), - context_lost_callback_(NULL), - swap_buffers_callback_(NULL), - memory_allocation_changed_callback_(NULL), - max_texture_size_(1024), - width_(0), - height_(0), - bound_buffer_(0), - weak_ptr_factory_(this) { - CreateNamespace(); -} - -TestWebGraphicsContext3D::TestWebGraphicsContext3D( - const WebGraphicsContext3D::Attributes& attributes) - : FakeWebGraphicsContext3D(), - context_id_(s_context_id++), - attributes_(attributes), - support_swapbuffers_complete_callback_(true), - have_extension_io_surface_(false), - have_extension_egl_image_(false), - times_make_current_succeeds_(-1), - times_bind_texture_succeeds_(-1), - times_end_query_succeeds_(-1), - times_gen_mailbox_succeeds_(-1), - context_lost_(false), - times_map_image_chromium_succeeds_(-1), - times_map_buffer_chromium_succeeds_(-1), - context_lost_callback_(NULL), - swap_buffers_callback_(NULL), - memory_allocation_changed_callback_(NULL), - max_texture_size_(1024), - width_(0), - height_(0), - bound_buffer_(0), - weak_ptr_factory_(this) { - CreateNamespace(); -} - -void TestWebGraphicsContext3D::CreateNamespace() { - if (attributes_.shareResources) { - base::AutoLock lock(g_shared_namespace_lock.Get()); - if (shared_namespace_) { - namespace_ = shared_namespace_; - } else { - namespace_ = new Namespace; - shared_namespace_ = namespace_.get(); - } - } else { - namespace_ = new Namespace; - } -} - -TestWebGraphicsContext3D::~TestWebGraphicsContext3D() { - for (size_t i = 0; i < sync_point_callbacks_.size(); ++i) { - if (sync_point_callbacks_[i] != NULL) - delete sync_point_callbacks_[i]; - } - base::AutoLock lock(g_shared_namespace_lock.Get()); - namespace_ = NULL; -} - -bool TestWebGraphicsContext3D::makeContextCurrent() { - if (times_make_current_succeeds_ >= 0) { - if (!times_make_current_succeeds_) { - loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, - GL_INNOCENT_CONTEXT_RESET_ARB); - } - --times_make_current_succeeds_; - } - return !context_lost_; -} - -int TestWebGraphicsContext3D::width() { - return width_; -} - -int TestWebGraphicsContext3D::height() { - return height_; -} - -void TestWebGraphicsContext3D::reshapeWithScaleFactor( - int width, int height, float scale_factor) { - width_ = width; - height_ = height; -} - -bool TestWebGraphicsContext3D::isContextLost() { - return context_lost_; -} - -WGC3Denum TestWebGraphicsContext3D::getGraphicsResetStatusARB() { - return context_lost_ ? GL_UNKNOWN_CONTEXT_RESET_ARB : GL_NO_ERROR; -} - -WGC3Denum TestWebGraphicsContext3D::checkFramebufferStatus( - WGC3Denum target) { - if (context_lost_) - return GL_FRAMEBUFFER_UNDEFINED_OES; - return GL_FRAMEBUFFER_COMPLETE; -} - -WebGraphicsContext3D::Attributes - TestWebGraphicsContext3D::getContextAttributes() { - return attributes_; -} - -WebKit::WebString TestWebGraphicsContext3D::getString(WGC3Denum name) { - std::string string; - - if (support_swapbuffers_complete_callback_) - string += "GL_CHROMIUM_swapbuffers_complete_callback"; - - if (name == GL_EXTENSIONS) { - if (have_extension_io_surface_) - string += " GL_CHROMIUM_iosurface GL_ARB_texture_rectangle"; - if (have_extension_egl_image_) - string += " GL_OES_EGL_image_external"; - } - - return WebKit::WebString::fromUTF8(string.c_str()); -} - -WGC3Dint TestWebGraphicsContext3D::getUniformLocation( - WebGLId program, - const WGC3Dchar* name) { - return 0; -} - -WGC3Dsizeiptr TestWebGraphicsContext3D::getVertexAttribOffset( - WGC3Duint index, - WGC3Denum pname) { - return 0; -} - -WGC3Dboolean TestWebGraphicsContext3D::isBuffer( - WebGLId buffer) { - return false; -} - -WGC3Dboolean TestWebGraphicsContext3D::isEnabled( - WGC3Denum cap) { - return false; -} - -WGC3Dboolean TestWebGraphicsContext3D::isFramebuffer( - WebGLId framebuffer) { - return false; -} - -WGC3Dboolean TestWebGraphicsContext3D::isProgram( - WebGLId program) { - return false; -} - -WGC3Dboolean TestWebGraphicsContext3D::isRenderbuffer( - WebGLId renderbuffer) { - return false; -} - -WGC3Dboolean TestWebGraphicsContext3D::isShader( - WebGLId shader) { - return false; -} - -WGC3Dboolean TestWebGraphicsContext3D::isTexture( - WebGLId texture) { - return false; -} - -WebGLId TestWebGraphicsContext3D::createBuffer() { - return NextBufferId(); -} - -void TestWebGraphicsContext3D::deleteBuffer(WebGLId id) { - base::AutoLock lock(namespace_->lock); - unsigned context_id = id >> 17; - unsigned buffer_id = id & 0x1ffff; - DCHECK(buffer_id && buffer_id < namespace_->next_buffer_id); - DCHECK_EQ(context_id, context_id_); -} - -WebGLId TestWebGraphicsContext3D::createFramebuffer() { - return kFramebufferId | context_id_ << 16; -} - -void TestWebGraphicsContext3D::deleteFramebuffer(WebGLId id) { - EXPECT_EQ(kFramebufferId | context_id_ << 16, id); -} - -WebGLId TestWebGraphicsContext3D::createProgram() { - return kProgramId | context_id_ << 16; -} - -void TestWebGraphicsContext3D::deleteProgram(WebGLId id) { - EXPECT_EQ(kProgramId | context_id_ << 16, id); -} - -WebGLId TestWebGraphicsContext3D::createRenderbuffer() { - return kRenderbufferId | context_id_ << 16; -} - -void TestWebGraphicsContext3D::deleteRenderbuffer(WebGLId id) { - EXPECT_EQ(kRenderbufferId | context_id_ << 16, id); -} - -WebGLId TestWebGraphicsContext3D::createShader(WGC3Denum) { - return kShaderId | context_id_ << 16; -} - -void TestWebGraphicsContext3D::deleteShader(WebGLId id) { - EXPECT_EQ(kShaderId | context_id_ << 16, id); -} - -WebGLId TestWebGraphicsContext3D::createTexture() { - WebGLId texture_id = NextTextureId(); - DCHECK_NE(texture_id, kExternalTextureId); - base::AutoLock lock(namespace_->lock); - namespace_->textures.push_back(texture_id); - return texture_id; -} - -void TestWebGraphicsContext3D::deleteTexture(WebGLId texture_id) { - base::AutoLock lock(namespace_->lock); - std::vector<WebKit::WebGLId>& textures = namespace_->textures; - DCHECK(std::find(textures.begin(), textures.end(), texture_id) != - textures.end()); - textures.erase(std::find(textures.begin(), textures.end(), texture_id)); -} - -void TestWebGraphicsContext3D::attachShader(WebGLId program, WebGLId shader) { - EXPECT_EQ(kProgramId | context_id_ << 16, program); - EXPECT_EQ(kShaderId | context_id_ << 16, shader); -} - -void TestWebGraphicsContext3D::useProgram(WebGLId program) { - if (!program) - return; - EXPECT_EQ(kProgramId | context_id_ << 16, program); -} - -void TestWebGraphicsContext3D::bindFramebuffer( - WGC3Denum target, WebGLId framebuffer) { - if (!framebuffer) - return; - EXPECT_EQ(kFramebufferId | context_id_ << 16, framebuffer); -} - -void TestWebGraphicsContext3D::bindRenderbuffer( - WGC3Denum target, WebGLId renderbuffer) { - if (!renderbuffer) - return; - EXPECT_EQ(kRenderbufferId | context_id_ << 16, renderbuffer); -} - -void TestWebGraphicsContext3D::bindTexture( - WGC3Denum target, WebGLId texture_id) { - if (times_bind_texture_succeeds_ >= 0) { - if (!times_bind_texture_succeeds_) { - loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, - GL_INNOCENT_CONTEXT_RESET_ARB); - } - --times_bind_texture_succeeds_; - } - - if (!texture_id) - return; - if (texture_id == kExternalTextureId) - return; - base::AutoLock lock(namespace_->lock); - std::vector<WebKit::WebGLId>& textures = namespace_->textures; - DCHECK(std::find(textures.begin(), textures.end(), texture_id) != - textures.end()); - used_textures_.insert(texture_id); -} - -void TestWebGraphicsContext3D::endQueryEXT(WGC3Denum target) { - if (times_end_query_succeeds_ >= 0) { - if (!times_end_query_succeeds_) { - loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, - GL_INNOCENT_CONTEXT_RESET_ARB); - } - --times_end_query_succeeds_; - } -} - -void TestWebGraphicsContext3D::getQueryObjectuivEXT( - WebGLId query, - WGC3Denum pname, - WGC3Duint* params) { - // If the context is lost, behave as if result is available. - if (pname == GL_QUERY_RESULT_AVAILABLE_EXT) - *params = 1; -} - -void TestWebGraphicsContext3D::getIntegerv( - WGC3Denum pname, - WebKit::WGC3Dint* value) { - if (pname == GL_MAX_TEXTURE_SIZE) - *value = max_texture_size_; - else if (pname == GL_ACTIVE_TEXTURE) - *value = GL_TEXTURE0; -} - -void TestWebGraphicsContext3D::genMailboxCHROMIUM(WebKit::WGC3Dbyte* mailbox) { - if (times_gen_mailbox_succeeds_ >= 0) { - if (!times_gen_mailbox_succeeds_) { - loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, - GL_INNOCENT_CONTEXT_RESET_ARB); - } - --times_gen_mailbox_succeeds_; - } - if (context_lost_) { - memset(mailbox, 0, 64); - return; - } - - static char mailbox_name1 = '1'; - static char mailbox_name2 = '1'; - mailbox[0] = mailbox_name1; - mailbox[1] = mailbox_name2; - mailbox[2] = '\0'; - if (++mailbox_name1 == 0) { - mailbox_name1 = '1'; - ++mailbox_name2; - } -} - -void TestWebGraphicsContext3D::setContextLostCallback( - WebGraphicsContextLostCallback* callback) { - context_lost_callback_ = callback; -} - -void TestWebGraphicsContext3D::loseContextCHROMIUM(WGC3Denum current, - WGC3Denum other) { - if (context_lost_) - return; - context_lost_ = true; - if (context_lost_callback_) - context_lost_callback_->onContextLost(); - - for (size_t i = 0; i < shared_contexts_.size(); ++i) - shared_contexts_[i]->loseContextCHROMIUM(current, other); - shared_contexts_.clear(); -} - -void TestWebGraphicsContext3D::signalSyncPoint( - unsigned sync_point, - WebGraphicsSyncPointCallback* callback) { - sync_point_callbacks_.push_back(callback); -} - -void TestWebGraphicsContext3D::signalQuery( - WebKit::WebGLId query, - WebGraphicsSyncPointCallback* callback) { - sync_point_callbacks_.push_back(callback); -} - -void TestWebGraphicsContext3D::setSwapBuffersCompleteCallbackCHROMIUM( - WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* callback) { - if (support_swapbuffers_complete_callback_) - swap_buffers_callback_ = callback; -} - -void TestWebGraphicsContext3D::setMemoryAllocationChangedCallbackCHROMIUM( - WebGraphicsMemoryAllocationChangedCallbackCHROMIUM* callback) { - memory_allocation_changed_callback_ = callback; -} - -void TestWebGraphicsContext3D::prepareTexture() { - if (swap_buffers_callback_) { - base::MessageLoop::current()->PostTask( - FROM_HERE, base::Bind(&TestWebGraphicsContext3D::SwapBuffersComplete, - weak_ptr_factory_.GetWeakPtr())); - } - CallAllSyncPointCallbacks(); -} - -void TestWebGraphicsContext3D::finish() { - CallAllSyncPointCallbacks(); -} - -void TestWebGraphicsContext3D::flush() { - CallAllSyncPointCallbacks(); -} - -static void CallAndDestroy( - WebKit::WebGraphicsContext3D::WebGraphicsSyncPointCallback* callback) { - if (!callback) - return; - callback->onSyncPointReached(); - delete callback; -} - -void TestWebGraphicsContext3D::CallAllSyncPointCallbacks() { - for (size_t i = 0; i < sync_point_callbacks_.size(); ++i) { - base::MessageLoop::current()->PostTask( - FROM_HERE, - base::Bind(&CallAndDestroy, - sync_point_callbacks_[i])); - } - sync_point_callbacks_.clear(); -} - -void TestWebGraphicsContext3D::SwapBuffersComplete() { - if (swap_buffers_callback_) - swap_buffers_callback_->onSwapBuffersComplete(); -} - -void TestWebGraphicsContext3D::bindBuffer(WebKit::WGC3Denum target, - WebKit::WebGLId buffer) { - bound_buffer_ = buffer; - if (!bound_buffer_) - return; - unsigned context_id = buffer >> 17; - unsigned buffer_id = buffer & 0x1ffff; - base::AutoLock lock(namespace_->lock); - DCHECK(buffer_id && buffer_id < namespace_->next_buffer_id); - DCHECK_EQ(context_id, context_id_); - - ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers; - if (buffers.count(bound_buffer_) == 0) - buffers.set(bound_buffer_, make_scoped_ptr(new Buffer).Pass()); - - buffers.get(bound_buffer_)->target = target; -} - -void TestWebGraphicsContext3D::bufferData(WebKit::WGC3Denum target, - WebKit::WGC3Dsizeiptr size, - const void* data, - WebKit::WGC3Denum usage) { - base::AutoLock lock(namespace_->lock); - ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers; - DCHECK_GT(buffers.count(bound_buffer_), 0u); - DCHECK_EQ(target, buffers.get(bound_buffer_)->target); - if (context_lost_) { - buffers.get(bound_buffer_)->pixels.reset(); - return; - } - buffers.get(bound_buffer_)->pixels.reset(new uint8[size]); - if (data != NULL) - memcpy(buffers.get(bound_buffer_)->pixels.get(), data, size); -} - -void* TestWebGraphicsContext3D::mapBufferCHROMIUM(WebKit::WGC3Denum target, - WebKit::WGC3Denum access) { - base::AutoLock lock(namespace_->lock); - ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers; - DCHECK_GT(buffers.count(bound_buffer_), 0u); - DCHECK_EQ(target, buffers.get(bound_buffer_)->target); - if (times_map_buffer_chromium_succeeds_ >= 0) { - if (!times_map_buffer_chromium_succeeds_) { - return NULL; - } - --times_map_buffer_chromium_succeeds_; - } - return buffers.get(bound_buffer_)->pixels.get(); -} - -WebKit::WGC3Dboolean TestWebGraphicsContext3D::unmapBufferCHROMIUM( - WebKit::WGC3Denum target) { - base::AutoLock lock(namespace_->lock); - ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers; - DCHECK_GT(buffers.count(bound_buffer_), 0u); - DCHECK_EQ(target, buffers.get(bound_buffer_)->target); - buffers.get(bound_buffer_)->pixels.reset(); - return true; -} - -void TestWebGraphicsContext3D::bindTexImage2DCHROMIUM( - WebKit::WGC3Denum target, - WebKit::WGC3Dint image_id) { - base::AutoLock lock(namespace_->lock); - DCHECK_GT(namespace_->images.count(image_id), 0u); -} - -WebKit::WGC3Duint TestWebGraphicsContext3D::createImageCHROMIUM( - WebKit::WGC3Dsizei width, WebKit::WGC3Dsizei height, - WebKit::WGC3Denum internalformat) { - DCHECK_EQ(GL_RGBA8_OES, static_cast<int>(internalformat)); - WebKit::WGC3Duint image_id = NextImageId(); - base::AutoLock lock(namespace_->lock); - ScopedPtrHashMap<unsigned, Image>& images = namespace_->images; - images.set(image_id, make_scoped_ptr(new Image).Pass()); - images.get(image_id)->pixels.reset(new uint8[width * height * 4]); - return image_id; -} - -void TestWebGraphicsContext3D::destroyImageCHROMIUM( - WebKit::WGC3Duint id) { - base::AutoLock lock(namespace_->lock); - unsigned context_id = id >> 17; - unsigned image_id = id & 0x1ffff; - DCHECK(image_id && image_id < namespace_->next_image_id); - DCHECK_EQ(context_id, context_id_); -} - -void TestWebGraphicsContext3D::getImageParameterivCHROMIUM( - WebKit::WGC3Duint image_id, - WebKit::WGC3Denum pname, - WebKit::WGC3Dint* params) { - base::AutoLock lock(namespace_->lock); - DCHECK_GT(namespace_->images.count(image_id), 0u); - DCHECK_EQ(GL_IMAGE_ROWBYTES_CHROMIUM, static_cast<int>(pname)); - *params = 0; -} - -void* TestWebGraphicsContext3D::mapImageCHROMIUM(WebKit::WGC3Duint image_id, - WebKit::WGC3Denum access) { - base::AutoLock lock(namespace_->lock); - ScopedPtrHashMap<unsigned, Image>& images = namespace_->images; - DCHECK_GT(images.count(image_id), 0u); - if (times_map_image_chromium_succeeds_ >= 0) { - if (!times_map_image_chromium_succeeds_) { - return NULL; - } - --times_map_image_chromium_succeeds_; - } - return images.get(image_id)->pixels.get(); -} - -void TestWebGraphicsContext3D::unmapImageCHROMIUM( - WebKit::WGC3Duint image_id) { - base::AutoLock lock(namespace_->lock); - DCHECK_GT(namespace_->images.count(image_id), 0u); -} - -size_t TestWebGraphicsContext3D::NumTextures() const { - base::AutoLock lock(namespace_->lock); - return namespace_->textures.size(); -} - -WebKit::WebGLId TestWebGraphicsContext3D::TextureAt(int i) const { - base::AutoLock lock(namespace_->lock); - return namespace_->textures[i]; -} - -WebGLId TestWebGraphicsContext3D::NextTextureId() { - base::AutoLock lock(namespace_->lock); - WebGLId texture_id = namespace_->next_texture_id++; - DCHECK(texture_id < (1 << 16)); - texture_id |= context_id_ << 16; - return texture_id; -} - -WebGLId TestWebGraphicsContext3D::NextBufferId() { - base::AutoLock lock(namespace_->lock); - WebGLId buffer_id = namespace_->next_buffer_id++; - DCHECK(buffer_id < (1 << 17)); - buffer_id |= context_id_ << 17; - return buffer_id; -} - -WebKit::WGC3Duint TestWebGraphicsContext3D::NextImageId() { - base::AutoLock lock(namespace_->lock); - WGC3Duint image_id = namespace_->next_image_id++; - DCHECK(image_id < (1 << 17)); - image_id |= context_id_ << 17; - return image_id; -} - -void TestWebGraphicsContext3D::SetMemoryAllocation( - WebKit::WebGraphicsMemoryAllocation allocation) { - if (!memory_allocation_changed_callback_) - return; - memory_allocation_changed_callback_->onMemoryAllocationChanged(allocation); -} - -TestWebGraphicsContext3D::Buffer::Buffer() : target(0) {} - -TestWebGraphicsContext3D::Buffer::~Buffer() {} - -TestWebGraphicsContext3D::Image::Image() {} - -TestWebGraphicsContext3D::Image::~Image() {} - -} // namespace cc diff --git a/cc/test/test_web_graphics_context_3d.h b/cc/test/test_web_graphics_context_3d.h deleted file mode 100644 index fb278ef..0000000 --- a/cc/test/test_web_graphics_context_3d.h +++ /dev/null @@ -1,297 +0,0 @@ -// Copyright 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CC_TEST_TEST_WEB_GRAPHICS_CONTEXT_3D_H_ -#define CC_TEST_TEST_WEB_GRAPHICS_CONTEXT_3D_H_ - -#include <vector> - -#include "base/callback.h" -#include "base/compiler_specific.h" -#include "base/containers/hash_tables.h" -#include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" -#include "base/memory/weak_ptr.h" -#include "base/stl_util.h" -#include "base/synchronization/lock.h" -#include "cc/base/scoped_ptr_hash_map.h" -#include "cc/debug/fake_web_graphics_context_3d.h" -#include "third_party/khronos/GLES2/gl2.h" - -namespace WebKit { -class WebGraphicsContext3D; -struct WebGraphicsMemoryAllocation; -} - -namespace cc { - -class TestWebGraphicsContext3D : public FakeWebGraphicsContext3D { - public: - static scoped_ptr<TestWebGraphicsContext3D> Create(); - static base::Callback< - scoped_ptr<TestWebGraphicsContext3D>()> CreateFactory(); - static base::Callback< - scoped_ptr<WebKit::WebGraphicsContext3D>()> CreateBaseFactory(); - - virtual ~TestWebGraphicsContext3D(); - - virtual bool makeContextCurrent(); - - virtual int width(); - virtual int height(); - - virtual void reshapeWithScaleFactor( - int width, int height, float scale_factor); - - virtual bool isContextLost(); - virtual WebKit::WGC3Denum getGraphicsResetStatusARB(); - - virtual void attachShader(WebKit::WebGLId program, WebKit::WebGLId shader); - virtual void bindFramebuffer( - WebKit::WGC3Denum target, WebKit::WebGLId framebuffer); - virtual void bindRenderbuffer( - WebKit::WGC3Denum target, WebKit::WebGLId renderbuffer); - virtual void bindTexture( - WebKit::WGC3Denum target, - WebKit::WebGLId texture_id); - - virtual WebKit::WGC3Denum checkFramebufferStatus(WebKit::WGC3Denum target); - - virtual Attributes getContextAttributes(); - - virtual WebKit::WebString getString(WebKit::WGC3Denum name); - virtual WebKit::WGC3Dint getUniformLocation( - WebKit::WebGLId program, - const WebKit::WGC3Dchar* name); - virtual WebKit::WGC3Dsizeiptr getVertexAttribOffset( - WebKit::WGC3Duint index, - WebKit::WGC3Denum pname); - - virtual WebKit::WGC3Dboolean isBuffer(WebKit::WebGLId buffer); - virtual WebKit::WGC3Dboolean isEnabled(WebKit::WGC3Denum cap); - virtual WebKit::WGC3Dboolean isFramebuffer(WebKit::WebGLId framebuffer); - virtual WebKit::WGC3Dboolean isProgram(WebKit::WebGLId program); - virtual WebKit::WGC3Dboolean isRenderbuffer(WebKit::WebGLId renderbuffer); - virtual WebKit::WGC3Dboolean isShader(WebKit::WebGLId shader); - virtual WebKit::WGC3Dboolean isTexture(WebKit::WebGLId texture); - - virtual void useProgram(WebKit::WebGLId program); - - virtual WebKit::WebGLId createBuffer(); - virtual WebKit::WebGLId createFramebuffer(); - virtual WebKit::WebGLId createProgram(); - virtual WebKit::WebGLId createRenderbuffer(); - virtual WebKit::WebGLId createShader(WebKit::WGC3Denum); - virtual WebKit::WebGLId createTexture(); - - virtual void deleteBuffer(WebKit::WebGLId id); - virtual void deleteFramebuffer(WebKit::WebGLId id); - virtual void deleteProgram(WebKit::WebGLId id); - virtual void deleteRenderbuffer(WebKit::WebGLId id); - virtual void deleteShader(WebKit::WebGLId id); - virtual void deleteTexture(WebKit::WebGLId texture_id); - - virtual void endQueryEXT(WebKit::WGC3Denum target); - virtual void getQueryObjectuivEXT( - WebKit::WebGLId query, - WebKit::WGC3Denum pname, - WebKit::WGC3Duint* params); - - virtual void getIntegerv( - WebKit::WGC3Denum pname, - WebKit::WGC3Dint* value); - - virtual void genMailboxCHROMIUM(WebKit::WGC3Dbyte* mailbox); - virtual void produceTextureCHROMIUM(WebKit::WGC3Denum target, - const WebKit::WGC3Dbyte* mailbox) { } - virtual void consumeTextureCHROMIUM(WebKit::WGC3Denum target, - const WebKit::WGC3Dbyte* mailbox) { } - - virtual void setContextLostCallback( - WebGraphicsContextLostCallback* callback); - - virtual void loseContextCHROMIUM(WebKit::WGC3Denum current, - WebKit::WGC3Denum other); - - // Takes ownership of the |callback|. - virtual void signalSyncPoint(unsigned sync_point, - WebGraphicsSyncPointCallback* callback); - virtual void signalQuery(WebKit::WebGLId query, - WebGraphicsSyncPointCallback* callback); - - virtual void setSwapBuffersCompleteCallbackCHROMIUM( - WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* callback); - - virtual void setMemoryAllocationChangedCallbackCHROMIUM( - WebGraphicsMemoryAllocationChangedCallbackCHROMIUM* callback); - - virtual void prepareTexture(); - virtual void finish(); - virtual void flush(); - - virtual void bindBuffer(WebKit::WGC3Denum target, WebKit::WebGLId buffer); - virtual void bufferData(WebKit::WGC3Denum target, - WebKit::WGC3Dsizeiptr size, - const void* data, - WebKit::WGC3Denum usage); - virtual void* mapBufferCHROMIUM(WebKit::WGC3Denum target, - WebKit::WGC3Denum access); - virtual WebKit::WGC3Dboolean unmapBufferCHROMIUM(WebKit::WGC3Denum target); - - virtual void bindTexImage2DCHROMIUM(WebKit::WGC3Denum target, - WebKit::WGC3Dint image_id); - virtual WebKit::WGC3Duint createImageCHROMIUM( - WebKit::WGC3Dsizei width, - WebKit::WGC3Dsizei height, - WebKit::WGC3Denum internalformat); - virtual void destroyImageCHROMIUM(WebKit::WGC3Duint image_id); - virtual void getImageParameterivCHROMIUM( - WebKit::WGC3Duint image_id, - WebKit::WGC3Denum pname, - WebKit::WGC3Dint* params); - virtual void* mapImageCHROMIUM( - WebKit::WGC3Duint image_id, - WebKit::WGC3Denum access); - virtual void unmapImageCHROMIUM(WebKit::WGC3Duint image_id); - - // When set, MakeCurrent() will fail after this many times. - void set_times_make_current_succeeds(int times) { - times_make_current_succeeds_ = times; - } - void set_times_bind_texture_succeeds(int times) { - times_bind_texture_succeeds_ = times; - } - void set_times_end_query_succeeds(int times) { - times_end_query_succeeds_ = times; - } - void set_times_gen_mailbox_succeeds(int times) { - times_gen_mailbox_succeeds_ = times; - } - - // When set, mapImageCHROMIUM and mapBufferCHROMIUM will return NULL after - // this many times. - void set_times_map_image_chromium_succeeds(int times) { - times_map_image_chromium_succeeds_ = times; - } - void set_times_map_buffer_chromium_succeeds(int times) { - times_map_buffer_chromium_succeeds_ = times; - } - - size_t NumTextures() const; - WebKit::WebGLId TextureAt(int i) const; - - size_t NumUsedTextures() const { return used_textures_.size(); } - bool UsedTexture(int texture) const { - return ContainsKey(used_textures_, texture); - } - void ResetUsedTextures() { used_textures_.clear(); } - - void set_support_swapbuffers_complete_callback(bool support) { - support_swapbuffers_complete_callback_ = support; - } - void set_have_extension_io_surface(bool have) { - have_extension_io_surface_ = have; - } - void set_have_extension_egl_image(bool have) { - have_extension_egl_image_ = have; - } - - // When this context is lost, all contexts in its share group are also lost. - void add_share_group_context(WebKit::WebGraphicsContext3D* context3d) { - shared_contexts_.push_back(context3d); - } - - void set_max_texture_size(int size) { max_texture_size_ = size; } - - static const WebKit::WebGLId kExternalTextureId; - virtual WebKit::WebGLId NextTextureId(); - - virtual WebKit::WebGLId NextBufferId(); - - virtual WebKit::WebGLId NextImageId(); - - void SetMemoryAllocation(WebKit::WebGraphicsMemoryAllocation allocation); - - protected: - struct Buffer { - Buffer(); - ~Buffer(); - - WebKit::WGC3Denum target; - scoped_ptr<uint8[]> pixels; - - private: - DISALLOW_COPY_AND_ASSIGN(Buffer); - }; - - struct Image { - Image(); - ~Image(); - - scoped_ptr<uint8[]> pixels; - - private: - DISALLOW_COPY_AND_ASSIGN(Image); - }; - - struct Namespace : public base::RefCountedThreadSafe<Namespace> { - Namespace(); - - // Protects all fields. - base::Lock lock; - unsigned next_buffer_id; - unsigned next_image_id; - unsigned next_texture_id; - std::vector<WebKit::WebGLId> textures; - ScopedPtrHashMap<unsigned, Buffer> buffers; - ScopedPtrHashMap<unsigned, Image> images; - - private: - friend class base::RefCountedThreadSafe<Namespace>; - ~Namespace(); - DISALLOW_COPY_AND_ASSIGN(Namespace); - }; - - TestWebGraphicsContext3D(); - TestWebGraphicsContext3D( - const WebKit::WebGraphicsContext3D::Attributes& attributes); - - void CallAllSyncPointCallbacks(); - void SwapBuffersComplete(); - void CreateNamespace(); - - unsigned context_id_; - Attributes attributes_; - bool support_swapbuffers_complete_callback_; - bool have_extension_io_surface_; - bool have_extension_egl_image_; - int times_make_current_succeeds_; - int times_bind_texture_succeeds_; - int times_end_query_succeeds_; - int times_gen_mailbox_succeeds_; - bool context_lost_; - int times_map_image_chromium_succeeds_; - int times_map_buffer_chromium_succeeds_; - WebGraphicsContextLostCallback* context_lost_callback_; - WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* swap_buffers_callback_; - WebGraphicsMemoryAllocationChangedCallbackCHROMIUM* - memory_allocation_changed_callback_; - std::vector<WebGraphicsSyncPointCallback*> sync_point_callbacks_; - base::hash_set<WebKit::WebGLId> used_textures_; - std::vector<WebKit::WebGraphicsContext3D*> shared_contexts_; - int max_texture_size_; - int width_; - int height_; - - unsigned bound_buffer_; - - scoped_refptr<Namespace> namespace_; - static Namespace* shared_namespace_; - - base::WeakPtrFactory<TestWebGraphicsContext3D> weak_ptr_factory_; -}; - -} // namespace cc - -#endif // CC_TEST_TEST_WEB_GRAPHICS_CONTEXT_3D_H_ |