Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1278)

Unified Diff: cc/test/test_web_graphics_context_3d.cc

Issue 18796008: Implement shareResources==true in TestWebGraphicsContext3D (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix destruction race Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/test/test_web_graphics_context_3d.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/test/test_web_graphics_context_3d.cc
diff --git a/cc/test/test_web_graphics_context_3d.cc b/cc/test/test_web_graphics_context_3d.cc
index f5ebb6b65c4b0d7b769c75fe69206463593e8951..423e1f044ae9792a2ffd3e9acde92846d7b4e882 100644
--- a/cc/test/test_web_graphics_context_3d.cc
+++ b/cc/test/test_web_graphics_context_3d.cc
@@ -8,6 +8,7 @@
#include <string>
#include "base/bind.h"
+#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "gpu/GLES2/gl2extchromium.h"
@@ -35,12 +36,27 @@ 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;
+}
+
TestWebGraphicsContext3D::TestWebGraphicsContext3D()
: FakeWebGraphicsContext3D(),
context_id_(s_context_id++),
- next_buffer_id_(1),
- next_image_id_(1),
- next_texture_id_(1),
support_swapbuffers_complete_callback_(true),
have_extension_io_surface_(false),
have_extension_egl_image_(false),
@@ -58,15 +74,13 @@ TestWebGraphicsContext3D::TestWebGraphicsContext3D()
height_(0),
bound_buffer_(0),
weak_ptr_factory_(this) {
+ CreateNamespace();
}
TestWebGraphicsContext3D::TestWebGraphicsContext3D(
const WebGraphicsContext3D::Attributes& attributes)
: FakeWebGraphicsContext3D(),
context_id_(s_context_id++),
- next_buffer_id_(1),
- next_image_id_(1),
- next_texture_id_(1),
attributes_(attributes),
support_swapbuffers_complete_callback_(true),
have_extension_io_surface_(false),
@@ -85,6 +99,21 @@ TestWebGraphicsContext3D::TestWebGraphicsContext3D(
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() {
@@ -92,6 +121,8 @@ TestWebGraphicsContext3D::~TestWebGraphicsContext3D() {
if (sync_point_callbacks_[i] != NULL)
delete sync_point_callbacks_[i];
}
+ base::AutoLock lock(g_shared_namespace_lock.Get());
+ namespace_ = NULL;
}
bool TestWebGraphicsContext3D::makeContextCurrent() {
@@ -207,9 +238,10 @@ WebGLId TestWebGraphicsContext3D::createBuffer() {
}
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 < next_buffer_id_);
+ DCHECK(buffer_id && buffer_id < namespace_->next_buffer_id);
DCHECK_EQ(context_id, context_id_);
}
@@ -248,14 +280,17 @@ void TestWebGraphicsContext3D::deleteShader(WebGLId id) {
WebGLId TestWebGraphicsContext3D::createTexture() {
WebGLId texture_id = NextTextureId();
DCHECK_NE(texture_id, kExternalTextureId);
- textures_.push_back(texture_id);
+ base::AutoLock lock(namespace_->lock);
+ namespace_->textures.push_back(texture_id);
return texture_id;
}
void TestWebGraphicsContext3D::deleteTexture(WebGLId texture_id) {
- DCHECK(std::find(textures_.begin(), textures_.end(), texture_id) !=
- textures_.end());
- textures_.erase(std::find(textures_.begin(), textures_.end(), 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) {
@@ -297,8 +332,10 @@ void TestWebGraphicsContext3D::bindTexture(
return;
if (texture_id == kExternalTextureId)
return;
- DCHECK(std::find(textures_.begin(), textures_.end(), texture_id) !=
- textures_.end());
+ 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);
}
@@ -422,55 +459,64 @@ void TestWebGraphicsContext3D::bindBuffer(WebKit::WGC3Denum target,
return;
unsigned context_id = buffer >> 17;
unsigned buffer_id = buffer & 0x1ffff;
- DCHECK(buffer_id && buffer_id < next_buffer_id_);
+ base::AutoLock lock(namespace_->lock);
+ DCHECK(buffer_id && buffer_id < namespace_->next_buffer_id);
DCHECK_EQ(context_id, context_id_);
- if (buffers_.count(bound_buffer_) == 0)
- buffers_.set(bound_buffer_, make_scoped_ptr(new Buffer).Pass());
+ 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;
+ buffers.get(bound_buffer_)->target = target;
}
void TestWebGraphicsContext3D::bufferData(WebKit::WGC3Denum target,
WebKit::WGC3Dsizeiptr size,
const void* data,
WebKit::WGC3Denum usage) {
- DCHECK_GT(buffers_.count(bound_buffer_), 0u);
- DCHECK_EQ(target, buffers_.get(bound_buffer_)->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);
if (context_lost_) {
- buffers_.get(bound_buffer_)->pixels.reset();
+ buffers.get(bound_buffer_)->pixels.reset();
return;
}
- buffers_.get(bound_buffer_)->pixels.reset(new uint8[size]);
+ buffers.get(bound_buffer_)->pixels.reset(new uint8[size]);
if (data != NULL)
- memcpy(buffers_.get(bound_buffer_)->pixels.get(), data, size);
+ memcpy(buffers.get(bound_buffer_)->pixels.get(), data, size);
}
void* TestWebGraphicsContext3D::mapBufferCHROMIUM(WebKit::WGC3Denum target,
WebKit::WGC3Denum access) {
- DCHECK_GT(buffers_.count(bound_buffer_), 0u);
- DCHECK_EQ(target, buffers_.get(bound_buffer_)->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);
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();
+ return buffers.get(bound_buffer_)->pixels.get();
}
WebKit::WGC3Dboolean TestWebGraphicsContext3D::unmapBufferCHROMIUM(
WebKit::WGC3Denum target) {
- DCHECK_GT(buffers_.count(bound_buffer_), 0u);
- DCHECK_EQ(target, buffers_.get(bound_buffer_)->target);
- buffers_.get(bound_buffer_)->pixels.reset();
+ 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) {
- DCHECK_GT(images_.count(image_id), 0u);
+ base::AutoLock lock(namespace_->lock);
+ DCHECK_GT(namespace_->images.count(image_id), 0u);
}
WebKit::WGC3Duint TestWebGraphicsContext3D::createImageCHROMIUM(
@@ -478,16 +524,19 @@ WebKit::WGC3Duint TestWebGraphicsContext3D::createImageCHROMIUM(
WebKit::WGC3Denum internalformat) {
DCHECK_EQ(GL_RGBA8_OES, static_cast<int>(internalformat));
WebKit::WGC3Duint image_id = NextImageId();
- images_.set(image_id, make_scoped_ptr(new Image).Pass());
- images_.get(image_id)->pixels.reset(new uint8[width * height * 4]);
+ 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 < next_image_id_);
+ DCHECK(image_id && image_id < namespace_->next_image_id);
DCHECK_EQ(context_id, context_id_);
}
@@ -495,44 +544,61 @@ void TestWebGraphicsContext3D::getImageParameterivCHROMIUM(
WebKit::WGC3Duint image_id,
WebKit::WGC3Denum pname,
WebKit::WGC3Dint* params) {
- DCHECK_GT(images_.count(image_id), 0u);
+ 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) {
- DCHECK_GT(images_.count(image_id), 0u);
+ 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();
+ return images.get(image_id)->pixels.get();
}
void TestWebGraphicsContext3D::unmapImageCHROMIUM(
WebKit::WGC3Duint image_id) {
- DCHECK_GT(images_.count(image_id), 0u);
+ 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() {
- WebGLId texture_id = next_texture_id_++;
+ 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() {
- WebGLId buffer_id = next_buffer_id_++;
+ 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() {
- WebKit::WGC3Duint image_id = next_image_id_++;
+ 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;
« no previous file with comments | « cc/test/test_web_graphics_context_3d.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698