summaryrefslogtreecommitdiffstats
path: root/gpu
diff options
context:
space:
mode:
authorgman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-04 22:44:26 +0000
committergman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-04 22:44:26 +0000
commit216b7fde8d9f14fa16598e24e45eb7b04d8ab4b9 (patch)
tree452ebd2443b3d7e26299657a299d6bcd0e668c51 /gpu
parent2d06180e1ad6caede0dabe26b226d62b4fd3828e (diff)
downloadchromium_src-216b7fde8d9f14fa16598e24e45eb7b04d8ab4b9.zip
chromium_src-216b7fde8d9f14fa16598e24e45eb7b04d8ab4b9.tar.gz
chromium_src-216b7fde8d9f14fa16598e24e45eb7b04d8ab4b9.tar.bz2
Revert "Revert 130737 - Make contexts actually use ShareGroup for shared contexts."
This reverts commit 429d0c2826fb423769611fc122d2fd1ad49879e9. TEST=ran gpu_unittests BUG=120297 TBR=apatrick@chromium.org Review URL: https://chromiumcodereview.appspot.com/9961022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@130754 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r--gpu/command_buffer/client/gles2_implementation.cc60
-rw-r--r--gpu/command_buffer/client/gles2_implementation.h9
-rw-r--r--gpu/command_buffer/client/gles2_implementation_unittest.cc88
-rw-r--r--gpu/command_buffer/client/program_info_manager.cc5
-rw-r--r--gpu/command_buffer/client/program_info_manager.h4
-rw-r--r--gpu/command_buffer/client/share_group.cc209
-rw-r--r--gpu/command_buffer/client/share_group.h5
7 files changed, 152 insertions, 228 deletions
diff --git a/gpu/command_buffer/client/gles2_implementation.cc b/gpu/command_buffer/client/gles2_implementation.cc
index cfd4063..b7b72a7 100644
--- a/gpu/command_buffer/client/gles2_implementation.cc
+++ b/gpu/command_buffer/client/gles2_implementation.cc
@@ -505,7 +505,8 @@ GLuint GLES2Implementation::MakeTextureId() {
}
void GLES2Implementation::FreeTextureId(GLuint id) {
- GetIdHandler(id_namespaces::kTextures)->FreeIds(this, 1, &id);
+ GetIdHandler(id_namespaces::kTextures)->FreeIds(
+ this, 1, &id, &GLES2Implementation::DeleteTexturesStub);
}
IdHandlerInterface* GLES2Implementation::GetIdHandler(int namespace_id) const {
@@ -1072,30 +1073,41 @@ void GLES2Implementation::GetVertexAttribPointerv(
bool GLES2Implementation::DeleteProgramHelper(GLuint program) {
if (!GetIdHandler(id_namespaces::kProgramsAndShaders)->FreeIds(
- this, 1, &program)) {
+ this, 1, &program, &GLES2Implementation::DeleteProgramStub)) {
SetGLError(
GL_INVALID_VALUE,
"glDeleteProgram: id not created by this context.");
return false;
}
- share_group_->program_info_manager()->DeleteInfo(program);
- helper_->DeleteProgram(program);
return true;
}
+void GLES2Implementation::DeleteProgramStub(
+ GLsizei n, const GLuint* programs) {
+ GPU_DCHECK_EQ(1, n);
+ share_group_->program_info_manager()->DeleteInfo(programs[0]);
+ helper_->DeleteProgram(programs[0]);
+}
+
bool GLES2Implementation::DeleteShaderHelper(GLuint shader) {
if (!GetIdHandler(id_namespaces::kProgramsAndShaders)->FreeIds(
- this, 1, &shader)) {
+ this, 1, &shader, &GLES2Implementation::DeleteShaderStub)) {
SetGLError(
GL_INVALID_VALUE,
"glDeleteShader: id not created by this context.");
return false;
}
- share_group_->program_info_manager()->DeleteInfo(shader);
- helper_->DeleteShader(shader);
return true;
}
+void GLES2Implementation::DeleteShaderStub(
+ GLsizei n, const GLuint* shaders) {
+ GPU_DCHECK_EQ(1, n);
+ share_group_->program_info_manager()->DeleteInfo(shaders[0]);
+ helper_->DeleteShader(shaders[0]);
+}
+
+
GLint GLES2Implementation::GetAttribLocationHelper(
GLuint program, const char* name) {
typedef GetAttribLocationBucket::Result Result;
@@ -2212,7 +2224,8 @@ bool GLES2Implementation::IsBufferReservedId(GLuint /* id */) {
void GLES2Implementation::DeleteBuffersHelper(
GLsizei n, const GLuint* buffers) {
- if (!GetIdHandler(id_namespaces::kBuffers)->FreeIds(this, n, buffers)) {
+ if (!GetIdHandler(id_namespaces::kBuffers)->FreeIds(
+ this, n, buffers, &GLES2Implementation::DeleteBuffersStub)) {
SetGLError(
GL_INVALID_VALUE,
"glDeleteBuffers: id not created by this context.");
@@ -2226,13 +2239,18 @@ void GLES2Implementation::DeleteBuffersHelper(
bound_element_array_buffer_id_ = 0;
}
}
+}
+
+void GLES2Implementation::DeleteBuffersStub(
+ GLsizei n, const GLuint* buffers) {
helper_->DeleteBuffersImmediate(n, buffers);
}
+
void GLES2Implementation::DeleteFramebuffersHelper(
GLsizei n, const GLuint* framebuffers) {
if (!GetIdHandler(id_namespaces::kFramebuffers)->FreeIds(
- this, n, framebuffers)) {
+ this, n, framebuffers, &GLES2Implementation::DeleteFramebuffersStub)) {
SetGLError(
GL_INVALID_VALUE,
"glDeleteFramebuffers: id not created by this context.");
@@ -2243,13 +2261,17 @@ void GLES2Implementation::DeleteFramebuffersHelper(
bound_framebuffer_ = 0;
}
}
+}
+
+void GLES2Implementation::DeleteFramebuffersStub(
+ GLsizei n, const GLuint* framebuffers) {
helper_->DeleteFramebuffersImmediate(n, framebuffers);
}
void GLES2Implementation::DeleteRenderbuffersHelper(
GLsizei n, const GLuint* renderbuffers) {
if (!GetIdHandler(id_namespaces::kRenderbuffers)->FreeIds(
- this, n, renderbuffers)) {
+ this, n, renderbuffers, &GLES2Implementation::DeleteRenderbuffersStub)) {
SetGLError(
GL_INVALID_VALUE,
"glDeleteRenderbuffers: id not created by this context.");
@@ -2260,13 +2282,17 @@ void GLES2Implementation::DeleteRenderbuffersHelper(
bound_renderbuffer_ = 0;
}
}
+}
+
+void GLES2Implementation::DeleteRenderbuffersStub(
+ GLsizei n, const GLuint* renderbuffers) {
helper_->DeleteRenderbuffersImmediate(n, renderbuffers);
}
void GLES2Implementation::DeleteTexturesHelper(
GLsizei n, const GLuint* textures) {
if (!GetIdHandler(id_namespaces::kTextures)->FreeIds(
- this, n, textures)) {
+ this, n, textures, &GLES2Implementation::DeleteTexturesStub)) {
SetGLError(
GL_INVALID_VALUE,
"glDeleteTextures: id not created by this context.");
@@ -2283,6 +2309,10 @@ void GLES2Implementation::DeleteTexturesHelper(
}
}
}
+}
+
+void GLES2Implementation::DeleteTexturesStub(
+ GLsizei n, const GLuint* textures) {
helper_->DeleteTexturesImmediate(n, textures);
}
@@ -2795,8 +2825,9 @@ void GLES2Implementation::PostSubBufferCHROMIUM(
void GLES2Implementation::DeleteQueriesEXTHelper(
GLsizei n, const GLuint* queries) {
+ // TODO(gman): Remove this as queries are not shared resources.
if (!GetIdHandler(id_namespaces::kQueries)->FreeIds(
- this, n, queries)) {
+ this, n, queries, &GLES2Implementation::DeleteQueriesStub)) {
SetGLError(
GL_INVALID_VALUE,
"glDeleteTextures: id not created by this context.");
@@ -2832,6 +2863,11 @@ void GLES2Implementation::DeleteQueriesEXTHelper(
helper_->DeleteQueriesEXTImmediate(n, queries);
}
+// TODO(gman): Remove this. Queries are not shared resources.
+void GLES2Implementation::DeleteQueriesStub(
+ GLsizei /* n */, const GLuint* /* queries */) {
+}
+
GLboolean GLES2Implementation::IsQueryEXT(GLuint id) {
GPU_CLIENT_SINGLE_THREAD_CHECK();
GPU_CLIENT_LOG("[" << this << "] IsQueryEXT(" << id << ")");
diff --git a/gpu/command_buffer/client/gles2_implementation.h b/gpu/command_buffer/client/gles2_implementation.h
index ba1aef8..69e875c 100644
--- a/gpu/command_buffer/client/gles2_implementation.h
+++ b/gpu/command_buffer/client/gles2_implementation.h
@@ -390,6 +390,15 @@ class GLES2_IMPL_EXPORT GLES2Implementation {
bool DeleteShaderHelper(GLuint shader);
void DeleteQueriesEXTHelper(GLsizei n, const GLuint* textures);
+ void DeleteBuffersStub(GLsizei n, const GLuint* buffers);
+ void DeleteFramebuffersStub(GLsizei n, const GLuint* framebuffers);
+ void DeleteRenderbuffersStub(GLsizei n, const GLuint* renderbuffers);
+ void DeleteTexturesStub(GLsizei n, const GLuint* textures);
+ void DeleteProgramStub(GLsizei n, const GLuint* programs);
+ void DeleteShaderStub(GLsizei n, const GLuint* shaders);
+ // TODO(gman): Remove this as queries are not shared.
+ void DeleteQueriesStub(GLsizei n, const GLuint* queries);
+
void BufferDataHelper(
GLenum target, GLsizeiptr size, const void* data, GLenum usage);
void BufferSubDataHelper(
diff --git a/gpu/command_buffer/client/gles2_implementation_unittest.cc b/gpu/command_buffer/client/gles2_implementation_unittest.cc
index e9a1aec..7c4851a 100644
--- a/gpu/command_buffer/client/gles2_implementation_unittest.cc
+++ b/gpu/command_buffer/client/gles2_implementation_unittest.cc
@@ -381,32 +381,6 @@ class GLES2ImplementationTest : public testing::Test {
.RetiresOnSaturation();
GetNextToken(); // eat the token that starting up will use.
- // Must match StrictSharedIdHandler::kNumIdsToGet.
- GLuint num_ids = 2048;
- scoped_array<GLuint> all_ids(new GLuint[num_ids]);
- if (shared_resources) {
- if (!bind_generates_resource) {
- GLuint start = kStartId;
- GLuint max_num_per = MaxTransferBufferSize() / sizeof(GLuint);
- GLuint* ids = all_ids.get();
- for (GLuint ii = 0; ii < num_ids; ++ii) {
- ids[ii] = start + ii;
- }
- while (num_ids) {
- GLuint num = std::min(num_ids, max_num_per);
- size_t size = num * sizeof(ids[0]);
- ExpectedMemoryInfo mem = GetExpectedMemory(size);
- EXPECT_CALL(*command_buffer(), OnFlush())
- .WillOnce(SetMemoryFromArray(mem.ptr, ids, size))
- .RetiresOnSaturation();
- GetNextToken();
- start += num;
- ids += num;
- num_ids -= num;
- }
- }
- }
-
gl_.reset(new GLES2Implementation(
helper_.get(),
NULL,
@@ -2091,27 +2065,10 @@ TEST_F(GLES2ImplementationTest, TexSubImage2DFlipY) {
mem2.ptr));
}
-// Test that GenBuffer does not call GenSharedIds.
-// This is because with client side arrays on we know the StrictSharedIdHandler
-// for buffers has already gotten a set of ids
-TEST_F(GLES2ImplementationStrictSharedTest, GenBuffer) {
- // Starts at + 2 because client side arrays take first 2 ids.
- GLuint ids[3] = { kStartId + 2, kStartId + 3, kStartId + 4 };
- struct Cmds {
- GenBuffersImmediate gen;
- GLuint data[3];
- };
- Cmds expected;
- expected.gen.Init(arraysize(ids), &ids[0]);
- gl_->GenBuffers(arraysize(ids), &ids[0]);
- EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
- EXPECT_NE(0u, ids[0]);
- EXPECT_NE(0u, ids[1]);
- EXPECT_NE(0u, ids[2]);
-}
-
// Binds can not be cached with bind_generates_resource = false because
-// our id might not be valid.
+// our id might not be valid. More specifically if you bind on contextA then
+// delete on contextB the resource is still bound on contextA but GetInterger
+// won't return an id.
TEST_F(GLES2ImplementationStrictSharedTest, BindsNotCached) {
struct PNameValue {
GLenum pname;
@@ -2140,45 +2097,6 @@ TEST_F(GLES2ImplementationStrictSharedTest, BindsNotCached) {
}
}
-TEST_F(GLES2ImplementationStrictSharedTest, CanNotDeleteIdsWeDidNotCreate) {
- GLuint id = 0x12345678;
-
- ExpectedMemoryInfo result1 =
- GetExpectedResultMemory(sizeof(GetError::Result));
- ExpectedMemoryInfo result2 =
- GetExpectedResultMemory(sizeof(GetError::Result));
- ExpectedMemoryInfo result3 =
- GetExpectedResultMemory(sizeof(GetError::Result));
- ExpectedMemoryInfo result4 =
- GetExpectedResultMemory(sizeof(GetError::Result));
- ExpectedMemoryInfo result5 =
- GetExpectedResultMemory(sizeof(GetError::Result));
- ExpectedMemoryInfo result6 =
- GetExpectedResultMemory(sizeof(GetError::Result));
-
- EXPECT_CALL(*command_buffer(), OnFlush())
- .WillOnce(SetMemory(result1.ptr, GLuint(GL_NO_ERROR)))
- .WillOnce(SetMemory(result2.ptr, GLuint(GL_NO_ERROR)))
- .WillOnce(SetMemory(result3.ptr, GLuint(GL_NO_ERROR)))
- .WillOnce(SetMemory(result4.ptr, GLuint(GL_NO_ERROR)))
- .WillOnce(SetMemory(result5.ptr, GLuint(GL_NO_ERROR)))
- .WillOnce(SetMemory(result6.ptr, GLuint(GL_NO_ERROR)))
- .RetiresOnSaturation();
-
- gl_->DeleteBuffers(1, &id);
- EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError());
- gl_->DeleteFramebuffers(1, &id);
- EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError());
- gl_->DeleteRenderbuffers(1, &id);
- EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError());
- gl_->DeleteTextures(1, &id);
- EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError());
- gl_->DeleteProgram(id);
- EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError());
- gl_->DeleteShader(id);
- EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError());
-}
-
TEST_F(GLES2ImplementationTest, CreateStreamTextureCHROMIUM) {
const GLuint kTextureId = 123;
const GLuint kResult = 456;
diff --git a/gpu/command_buffer/client/program_info_manager.cc b/gpu/command_buffer/client/program_info_manager.cc
index d953914..86fbd13 100644
--- a/gpu/command_buffer/client/program_info_manager.cc
+++ b/gpu/command_buffer/client/program_info_manager.cc
@@ -492,8 +492,9 @@ ProgramInfoManager::ProgramInfoManager() {
ProgramInfoManager::~ProgramInfoManager() {
}
-ProgramInfoManager* ProgramInfoManager::Create(bool shared_resources) {
- if (shared_resources) {
+ProgramInfoManager* ProgramInfoManager::Create(
+ bool shared_resources_across_processes) {
+ if (shared_resources_across_processes) {
return new NonCachedProgramInfoManager();
} else {
return new CachedProgramInfoManager();
diff --git a/gpu/command_buffer/client/program_info_manager.h b/gpu/command_buffer/client/program_info_manager.h
index 5b3e559..25108e2 100644
--- a/gpu/command_buffer/client/program_info_manager.h
+++ b/gpu/command_buffer/client/program_info_manager.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -17,7 +17,7 @@ class ProgramInfoManager {
public:
virtual ~ProgramInfoManager();
- static ProgramInfoManager* Create(bool shared_resources);
+ static ProgramInfoManager* Create(bool shared_resources_across_processes);
virtual void CreateInfo(GLuint program) = 0;
diff --git a/gpu/command_buffer/client/share_group.cc b/gpu/command_buffer/client/share_group.cc
index e195e19..23e5456 100644
--- a/gpu/command_buffer/client/share_group.cc
+++ b/gpu/command_buffer/client/share_group.cc
@@ -15,11 +15,11 @@ namespace gles2 {
COMPILE_ASSERT(gpu::kInvalidResource == 0,
INVALID_RESOURCE_NOT_0_AS_GL_EXPECTS);
-// An id handler for non-shared ids.
-class NonSharedIdHandler : public IdHandlerInterface {
+// The standard id handler.
+class IdHandler : public IdHandlerInterface {
public:
- NonSharedIdHandler() { }
- virtual ~NonSharedIdHandler() { }
+ IdHandler() { }
+ virtual ~IdHandler() { }
// Overridden from IdHandlerInterface.
virtual void Destroy(GLES2Implementation* /* gl_impl */) {
@@ -43,11 +43,15 @@ class NonSharedIdHandler : public IdHandlerInterface {
// Overridden from IdHandlerInterface.
virtual bool FreeIds(
- GLES2Implementation* /* gl_impl */,
- GLsizei n, const GLuint* ids) {
+ GLES2Implementation* gl_impl,
+ GLsizei n, const GLuint* ids, DeleteFn delete_fn) {
for (GLsizei ii = 0; ii < n; ++ii) {
id_allocator_.FreeID(ids[ii]);
}
+ (gl_impl->*delete_fn)(n, ids);
+ // We need to ensure that the delete call is evaluated on the service side
+ // before any other contexts issue commands using these client ids.
+ gl_impl->helper()->CommandBufferHelper::Flush();
return true;
}
@@ -59,11 +63,11 @@ class NonSharedIdHandler : public IdHandlerInterface {
IdAllocator id_allocator_;
};
-// An id handler for non-shared ids that are never reused.
-class NonSharedNonReusedIdHandler : public IdHandlerInterface {
+// An id handler that require Gen before Bind.
+class StrictIdHandler : public IdHandlerInterface {
public:
- NonSharedNonReusedIdHandler() : last_id_(0) { }
- virtual ~NonSharedNonReusedIdHandler() { }
+ StrictIdHandler() { }
+ virtual ~StrictIdHandler() { }
// Overridden from IdHandlerInterface.
virtual void Destroy(GLES2Implementation* /* gl_impl */) {
@@ -73,128 +77,107 @@ class NonSharedNonReusedIdHandler : public IdHandlerInterface {
virtual void MakeIds(
GLES2Implementation* /* gl_impl */,
GLuint id_offset, GLsizei n, GLuint* ids) {
- for (GLsizei ii = 0; ii < n; ++ii) {
- ids[ii] = ++last_id_ + id_offset;
+ if (id_offset == 0) {
+ for (GLsizei ii = 0; ii < n; ++ii) {
+ ids[ii] = id_allocator_.AllocateID();
+ }
+ } else {
+ for (GLsizei ii = 0; ii < n; ++ii) {
+ ids[ii] = id_allocator_.AllocateIDAtOrAbove(id_offset);
+ id_offset = ids[ii] + 1;
+ }
}
}
// Overridden from IdHandlerInterface.
virtual bool FreeIds(
- GLES2Implementation* /* gl_impl */,
- GLsizei /* n */, const GLuint* /* ids */) {
- // Ids are never freed.
+ GLES2Implementation* gl_impl,
+ GLsizei n, const GLuint* ids, DeleteFn delete_fn) {
+ for (GLsizei ii = 0; ii < n; ++ii) {
+ id_allocator_.FreeID(ids[ii]);
+ }
+ (gl_impl->*delete_fn)(n, ids);
+ // We need to ensure that the delete call is evaluated on the service side
+ // before any other contexts issue commands using these client ids.
+ gl_impl->helper()->CommandBufferHelper::Flush();
return true;
}
// Overridden from IdHandlerInterface.
- virtual bool MarkAsUsedForBind(GLuint /* id */) {
- // This is only used for Shaders and Programs which have no bind.
- return false;
+ virtual bool MarkAsUsedForBind(GLuint id) {
+ GPU_DCHECK(id == 0 || id_allocator_.InUse(id));
+ return true;
}
-
private:
- GLuint last_id_;
+ IdAllocator id_allocator_;
};
-// An id handler for shared ids.
-class SharedIdHandler : public IdHandlerInterface {
+// An id handler for ids that are never reused.
+class NonReusedIdHandler : public IdHandlerInterface {
public:
- SharedIdHandler(
- id_namespaces::IdNamespaces id_namespace)
- : id_namespace_(id_namespace) {
- }
-
- virtual ~SharedIdHandler() { }
+ NonReusedIdHandler() : last_id_(0) { }
+ virtual ~NonReusedIdHandler() { }
// Overridden from IdHandlerInterface.
virtual void Destroy(GLES2Implementation* /* gl_impl */) {
}
+ // Overridden from IdHandlerInterface.
virtual void MakeIds(
- GLES2Implementation* gl_impl,
+ GLES2Implementation* /* gl_impl */,
GLuint id_offset, GLsizei n, GLuint* ids) {
- gl_impl->GenSharedIdsCHROMIUM(id_namespace_, id_offset, n, ids);
+ for (GLsizei ii = 0; ii < n; ++ii) {
+ ids[ii] = ++last_id_ + id_offset;
+ }
}
+ // Overridden from IdHandlerInterface.
virtual bool FreeIds(
GLES2Implementation* gl_impl,
- GLsizei n, const GLuint* ids) {
- gl_impl->DeleteSharedIdsCHROMIUM(id_namespace_, n, ids);
- // We need to ensure that the delete call is evaluated on the service side
- // before any other contexts issue commands using these client ids.
- gl_impl->helper()->CommandBufferHelper::Flush();
+ GLsizei n, const GLuint* ids, DeleteFn delete_fn) {
+ // Ids are never freed.
+ (gl_impl->*delete_fn)(n, ids);
return true;
}
+ // Overridden from IdHandlerInterface.
virtual bool MarkAsUsedForBind(GLuint /* id */) {
- // This has no meaning for shared resources.
- return true;
+ // This is only used for Shaders and Programs which have no bind.
+ return false;
}
private:
- id_namespaces::IdNamespaces id_namespace_;
+ GLuint last_id_;
};
-// An id handler for shared ids that requires ids are made before using and
-// that only the context that created the id can delete it.
-// Assumes the service will enforce that non made ids generate an error.
-class StrictSharedIdHandler : public IdHandlerInterface {
+// An id handler for shared ids.
+class SharedIdHandler : public IdHandlerInterface {
public:
- StrictSharedIdHandler(
+ SharedIdHandler(
id_namespaces::IdNamespaces id_namespace)
: id_namespace_(id_namespace) {
}
- virtual ~StrictSharedIdHandler() {
- }
+ virtual ~SharedIdHandler() { }
// Overridden from IdHandlerInterface.
- virtual void Destroy(GLES2Implementation* gl_impl) {
- GPU_DCHECK(gl_impl);
- // Free all the ids not being used.
- while (!free_ids_.empty()) {
- GLuint ids[kNumIdsToGet];
- int count = 0;
- while (count < kNumIdsToGet && !free_ids_.empty()) {
- ids[count++] = free_ids_.front();
- free_ids_.pop();
- }
- gl_impl->DeleteSharedIdsCHROMIUM(id_namespace_, count, ids);
- }
+ virtual void Destroy(GLES2Implementation* /* gl_impl */) {
}
virtual void MakeIds(
GLES2Implementation* gl_impl,
GLuint id_offset, GLsizei n, GLuint* ids) {
- GPU_DCHECK(gl_impl);
- for (GLsizei ii = 0; ii < n; ++ii) {
- ids[ii] = GetId(gl_impl, id_offset);
- }
+ gl_impl->GenSharedIdsCHROMIUM(id_namespace_, id_offset, n, ids);
}
virtual bool FreeIds(
- GLES2Implementation* /* gl_impl */,
- GLsizei n, const GLuint* ids) {
- // OpenGL sematics. If any id is bad none of them get freed.
- for (GLsizei ii = 0; ii < n; ++ii) {
- GLuint id = ids[ii];
- if (id != 0) {
- ResourceIdSet::iterator it = used_ids_.find(id);
- if (it == used_ids_.end()) {
- return false;
- }
- }
- }
- for (GLsizei ii = 0; ii < n; ++ii) {
- GLuint id = ids[ii];
- if (id != 0) {
- ResourceIdSet::iterator it = used_ids_.find(id);
- if (it != used_ids_.end()) {
- used_ids_.erase(it);
- free_ids_.push(id);
- }
- }
- }
+ GLES2Implementation* gl_impl,
+ GLsizei n, const GLuint* ids, DeleteFn delete_fn) {
+ gl_impl->DeleteSharedIdsCHROMIUM(id_namespace_, n, ids);
+ (gl_impl->*delete_fn)(n, ids);
+ // We need to ensure that the delete call is evaluated on the service side
+ // before any other contexts issue commands using these client ids.
+ gl_impl->helper()->CommandBufferHelper::Flush();
return true;
}
@@ -204,35 +187,9 @@ class StrictSharedIdHandler : public IdHandlerInterface {
}
private:
- static const GLsizei kNumIdsToGet = 2048;
- typedef std::queue<GLuint> ResourceIdQueue;
- typedef std::set<GLuint> ResourceIdSet;
-
- GLuint GetId(GLES2Implementation* gl_impl, GLuint id_offset) {
- GPU_DCHECK(gl_impl);
- if (free_ids_.empty()) {
- GLuint ids[kNumIdsToGet];
- gl_impl->GenSharedIdsCHROMIUM(
- id_namespace_, id_offset, kNumIdsToGet, ids);
- for (GLsizei ii = 0; ii < kNumIdsToGet; ++ii) {
- free_ids_.push(ids[ii]);
- }
- }
- GLuint id = free_ids_.front();
- free_ids_.pop();
- used_ids_.insert(id);
- return id;
- }
-
id_namespaces::IdNamespaces id_namespace_;
- ResourceIdSet used_ids_;
- ResourceIdQueue free_ids_;
};
-#ifndef _MSC_VER
-const GLsizei StrictSharedIdHandler::kNumIdsToGet;
-#endif
-
class ThreadSafeIdHandlerWrapper : public IdHandlerInterface {
public:
ThreadSafeIdHandlerWrapper(IdHandlerInterface* id_handler)
@@ -255,9 +212,10 @@ class ThreadSafeIdHandlerWrapper : public IdHandlerInterface {
// Overridden from IdHandlerInterface.
virtual bool FreeIds(
- GLES2Implementation* gl_impl, GLsizei n, const GLuint* ids) {
+ GLES2Implementation* gl_impl, GLsizei n, const GLuint* ids,
+ DeleteFn delete_fn) {
AutoLock auto_lock(lock_);
- return id_handler_->FreeIds(gl_impl, n, ids);
+ return id_handler_->FreeIds(gl_impl, n, ids, delete_fn);
}
// Overridden from IdHandlerInterface.
@@ -277,29 +235,28 @@ ShareGroup::ShareGroup(bool share_resources, bool bind_generates_resource)
gles2_(NULL) {
GPU_CHECK(ShareGroup::ImplementsThreadSafeReferenceCounting());
- if (sharing_resources_) {
- if (!bind_generates_resource_) {
- for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) {
+ if (bind_generates_resource) {
+ for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) {
+ if (i == id_namespaces::kProgramsAndShaders) {
id_handlers_[i].reset(new ThreadSafeIdHandlerWrapper(
- new StrictSharedIdHandler(
- static_cast<id_namespaces::IdNamespaces>(i))));
- }
- } else {
- for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) {
+ new NonReusedIdHandler()));
+ } else {
id_handlers_[i].reset(new ThreadSafeIdHandlerWrapper(
- new SharedIdHandler(
- static_cast<id_namespaces::IdNamespaces>(i))));
+ new IdHandler()));
}
}
} else {
for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) {
- if (i == id_namespaces::kProgramsAndShaders)
- id_handlers_[i].reset(new NonSharedNonReusedIdHandler);
- else
- id_handlers_[i].reset(new NonSharedIdHandler);
+ if (i == id_namespaces::kProgramsAndShaders) {
+ id_handlers_[i].reset(new ThreadSafeIdHandlerWrapper(
+ new NonReusedIdHandler()));
+ } else {
+ id_handlers_[i].reset(new ThreadSafeIdHandlerWrapper(
+ new StrictIdHandler()));
+ }
}
}
- program_info_manager_.reset(ProgramInfoManager::Create(sharing_resources_));
+ program_info_manager_.reset(ProgramInfoManager::Create(false));
}
ShareGroup::~ShareGroup() {
diff --git a/gpu/command_buffer/client/share_group.h b/gpu/command_buffer/client/share_group.h
index cf3c44b..3a0df32 100644
--- a/gpu/command_buffer/client/share_group.h
+++ b/gpu/command_buffer/client/share_group.h
@@ -17,6 +17,8 @@ namespace gles2 {
class GLES2Implementation;
class ProgramInfoManager;
+typedef void (GLES2Implementation::*DeleteFn)(GLsizei n, const GLuint* ids);
+
// Base class for IdHandlers
class IdHandlerInterface {
public:
@@ -33,7 +35,8 @@ class IdHandlerInterface {
// Frees some ids.
virtual bool FreeIds(
- GLES2Implementation* gl_impl, GLsizei n, const GLuint* ids) = 0;
+ GLES2Implementation* gl_impl, GLsizei n, const GLuint* ids,
+ DeleteFn delete_fn) = 0;
// Marks an id as used for glBind functions. id = 0 does nothing.
virtual bool MarkAsUsedForBind(GLuint id) = 0;