summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-12 20:09:57 +0000
committerjbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-12 20:09:57 +0000
commitce9eea60c922efff7c680a7a127480a799e06e94 (patch)
tree6e34093d78d48fe4d1132c4d8eef2817d32e2203
parent8c3bd1d8c71d8432beb624ce1434ca962665de90 (diff)
downloadchromium_src-ce9eea60c922efff7c680a7a127480a799e06e94.zip
chromium_src-ce9eea60c922efff7c680a7a127480a799e06e94.tar.gz
chromium_src-ce9eea60c922efff7c680a7a127480a799e06e94.tar.bz2
implemented latch support in renderer process. this corresponds with a webkit patch.
https://bugs.webkit.org/show_bug.cgi?id=58003 BUG=72671 TEST=see attachment in bug for test. only green should be seen. Review URL: http://codereview.chromium.org/6810009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81295 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/common/gpu/gpu_command_buffer_stub.cc10
-rw-r--r--content/common/gpu/gpu_command_buffer_stub.h3
-rw-r--r--content/common/gpu_messages.h6
-rw-r--r--content/renderer/command_buffer_proxy.cc9
-rw-r--r--content/renderer/command_buffer_proxy.h5
-rw-r--r--content/renderer/renderer_gl_context.cc171
-rw-r--r--content/renderer/renderer_gl_context.h18
-rw-r--r--content/renderer/webgraphicscontext3d_command_buffer_impl.cc35
-rw-r--r--content/renderer/webgraphicscontext3d_command_buffer_impl.h5
-rw-r--r--gpu/GLES2/gl2ext.h8
-rwxr-xr-xgpu/command_buffer/build_gles2_cmd_buffer.py4
-rw-r--r--gpu/command_buffer/client/gles2_c_lib_autogen.h14
-rw-r--r--gpu/command_buffer/client/gles2_cmd_helper_autogen.h8
-rw-r--r--gpu/command_buffer/client/gles2_demo.cc2
-rw-r--r--gpu/command_buffer/client/gles2_implementation_autogen.h8
-rw-r--r--gpu/command_buffer/client/gles2_implementation_unittest.cc9
-rw-r--r--gpu/command_buffer/client/mapped_memory.cc4
-rw-r--r--gpu/command_buffer/common/command_buffer.h17
-rw-r--r--gpu/command_buffer/common/command_buffer_mock.h7
-rw-r--r--gpu/command_buffer/common/constants.h6
-rw-r--r--gpu/command_buffer/common/gles2_cmd_format_autogen.h36
-rw-r--r--gpu/command_buffer/common/gles2_cmd_format_test_autogen.h12
-rw-r--r--gpu/command_buffer/service/command_buffer_service.cc30
-rw-r--r--gpu/command_buffer/service/command_buffer_service.h5
-rw-r--r--gpu/command_buffer/service/common_decoder_unittest.cc5
-rw-r--r--gpu/command_buffer/service/feature_info.cc1
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder.cc10
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc26
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h3
-rw-r--r--gpu/demos/framework/window.cc4
-rw-r--r--gpu/pgl/command_buffer_pepper.cc7
-rw-r--r--gpu/pgl/command_buffer_pepper.h7
-rw-r--r--gpu/pgl/pgl.cc4
-rw-r--r--ppapi/proxy/ppb_context_3d_proxy.cc12
-rw-r--r--webkit/gpu/webgraphicscontext3d_in_process_impl.cc20
-rw-r--r--webkit/gpu/webgraphicscontext3d_in_process_impl.h5
-rw-r--r--webkit/plugins/ppapi/ppb_context_3d_impl.cc6
37 files changed, 419 insertions, 123 deletions
diff --git a/content/common/gpu/gpu_command_buffer_stub.cc b/content/common/gpu/gpu_command_buffer_stub.cc
index e237dd1..b55dac2 100644
--- a/content/common/gpu/gpu_command_buffer_stub.cc
+++ b/content/common/gpu/gpu_command_buffer_stub.cc
@@ -309,13 +309,16 @@ void GpuCommandBufferStub::OnAsyncFlush(int32 put_offset) {
Send(new GpuCommandBufferMsg_UpdateState(route_id_, state));
}
-void GpuCommandBufferStub::OnCreateTransferBuffer(int32 size, int32* id) {
- *id = command_buffer_->CreateTransferBuffer(size);
+void GpuCommandBufferStub::OnCreateTransferBuffer(int32 size,
+ int32 id_request,
+ int32* id) {
+ *id = command_buffer_->CreateTransferBuffer(size, id_request);
}
void GpuCommandBufferStub::OnRegisterTransferBuffer(
base::SharedMemoryHandle transfer_buffer,
size_t size,
+ int32 id_request,
int32* id) {
#if defined(OS_WIN)
// Windows dups the shared memory handle it receives into the current process
@@ -329,7 +332,8 @@ void GpuCommandBufferStub::OnRegisterTransferBuffer(
base::SharedMemory shared_memory(transfer_buffer, false);
#endif
- *id = command_buffer_->RegisterTransferBuffer(&shared_memory, size);
+ *id = command_buffer_->RegisterTransferBuffer(&shared_memory, size,
+ id_request);
}
void GpuCommandBufferStub::OnDestroyTransferBuffer(int32 id) {
diff --git a/content/common/gpu/gpu_command_buffer_stub.h b/content/common/gpu/gpu_command_buffer_stub.h
index 0010b17..e515caf 100644
--- a/content/common/gpu/gpu_command_buffer_stub.h
+++ b/content/common/gpu/gpu_command_buffer_stub.h
@@ -82,9 +82,10 @@ class GpuCommandBufferStub
void OnAsyncGetState();
void OnFlush(int32 put_offset, gpu::CommandBuffer::State* state);
void OnAsyncFlush(int32 put_offset);
- void OnCreateTransferBuffer(int32 size, int32* id);
+ void OnCreateTransferBuffer(int32 size, int32 id_request, int32* id);
void OnRegisterTransferBuffer(base::SharedMemoryHandle transfer_buffer,
size_t size,
+ int32 id_request,
int32* id);
void OnDestroyTransferBuffer(int32 id);
void OnGetTransferBuffer(int32 id,
diff --git a/content/common/gpu_messages.h b/content/common/gpu_messages.h
index 6a8dc4f..4e4d5c7 100644
--- a/content/common/gpu_messages.h
+++ b/content/common/gpu_messages.h
@@ -363,15 +363,17 @@ IPC_MESSAGE_ROUTED0(GpuCommandBufferMsg_SwapBuffers)
// Create a shared memory transfer buffer. Returns an id that can be used to
// identify the transfer buffer from a comment.
-IPC_SYNC_MESSAGE_ROUTED1_1(GpuCommandBufferMsg_CreateTransferBuffer,
+IPC_SYNC_MESSAGE_ROUTED2_1(GpuCommandBufferMsg_CreateTransferBuffer,
int32 /* size */,
+ int32 /* id_request (-1 means any) */,
int32 /* id */)
// Register an existing shared memory transfer buffer. Returns an id that can be
// used to identify the transfer buffer from a command buffer.
-IPC_SYNC_MESSAGE_ROUTED2_1(GpuCommandBufferMsg_RegisterTransferBuffer,
+IPC_SYNC_MESSAGE_ROUTED3_1(GpuCommandBufferMsg_RegisterTransferBuffer,
base::SharedMemoryHandle /* transfer_buffer */,
size_t /* size */,
+ int32 /* id_request (-1 means any) */,
int32 /* id */)
// Destroy a previously created transfer buffer.
diff --git a/content/renderer/command_buffer_proxy.cc b/content/renderer/command_buffer_proxy.cc
index 865f90f..e374386 100644
--- a/content/renderer/command_buffer_proxy.cc
+++ b/content/renderer/command_buffer_proxy.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 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.
@@ -165,7 +165,7 @@ void CommandBufferProxy::SetGetOffset(int32 get_offset) {
NOTREACHED();
}
-int32 CommandBufferProxy::CreateTransferBuffer(size_t size) {
+int32 CommandBufferProxy::CreateTransferBuffer(size_t size, int32 id_request) {
if (last_state_.error != gpu::error::kNoError)
return -1;
@@ -198,6 +198,7 @@ int32 CommandBufferProxy::CreateTransferBuffer(size_t size) {
if (!Send(new GpuCommandBufferMsg_RegisterTransferBuffer(route_id_,
handle,
size,
+ id_request,
&id))) {
return -1;
}
@@ -207,7 +208,8 @@ int32 CommandBufferProxy::CreateTransferBuffer(size_t size) {
int32 CommandBufferProxy::RegisterTransferBuffer(
base::SharedMemory* shared_memory,
- size_t size) {
+ size_t size,
+ int32 id_request) {
if (last_state_.error != gpu::error::kNoError)
return -1;
@@ -216,6 +218,7 @@ int32 CommandBufferProxy::RegisterTransferBuffer(
route_id_,
shared_memory->handle(), // Returns FileDescriptor with auto_close off.
size,
+ id_request,
&id))) {
return -1;
}
diff --git a/content/renderer/command_buffer_proxy.h b/content/renderer/command_buffer_proxy.h
index 77914d0..e63150c 100644
--- a/content/renderer/command_buffer_proxy.h
+++ b/content/renderer/command_buffer_proxy.h
@@ -51,9 +51,10 @@ class CommandBufferProxy : public gpu::CommandBuffer,
virtual void Flush(int32 put_offset);
virtual State FlushSync(int32 put_offset);
virtual void SetGetOffset(int32 get_offset);
- virtual int32 CreateTransferBuffer(size_t size);
+ virtual int32 CreateTransferBuffer(size_t size, int32 id_request);
virtual int32 RegisterTransferBuffer(base::SharedMemory* shared_memory,
- size_t size);
+ size_t size,
+ int32 id_request);
virtual void DestroyTransferBuffer(int32 id);
virtual gpu::Buffer GetTransferBuffer(int32 handle);
virtual void SetToken(int32 token);
diff --git a/content/renderer/renderer_gl_context.cc b/content/renderer/renderer_gl_context.cc
index 235a0a5..e55357d 100644
--- a/content/renderer/renderer_gl_context.cc
+++ b/content/renderer/renderer_gl_context.cc
@@ -6,7 +6,12 @@
#include "base/lazy_instance.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/singleton.h"
#include "base/memory/weak_ptr.h"
+#include "base/shared_memory.h"
+#include "chrome/renderer/render_thread.h"
+#include "content/common/view_messages.h"
#include "content/renderer/command_buffer_proxy.h"
#include "content/renderer/gpu_channel_host.h"
#include "content/renderer/gpu_video_service_host.h"
@@ -33,6 +38,9 @@ const int32 kCommandBufferSize = 1024 * 1024;
// creation attributes.
const int32 kTransferBufferSize = 1024 * 1024;
+const uint32 kMaxLatchesPerRenderer = 2048;
+const uint32 kInvalidLatchId = 0xffffffffu;
+
// Singleton used to initialize and terminate the gles2 library.
class GLES2Initializer {
public:
@@ -48,6 +56,95 @@ class GLES2Initializer {
DISALLOW_COPY_AND_ASSIGN(GLES2Initializer);
};
+// Shared memory allocator for latches. Creates a block of shared memory for
+// each renderer process.
+class LatchAllocator {
+ public:
+ static LatchAllocator* GetInstance();
+ static uint32 size() { return kMaxLatchesPerRenderer*sizeof(uint32); }
+ static const uint32_t kFreeLatch = 0xffffffffu;
+
+ LatchAllocator();
+ ~LatchAllocator();
+
+ base::SharedMemoryHandle handle() const { return shm_->handle(); }
+ base::SharedMemory* shared_memory() { return shm_.get(); }
+
+ bool AllocateLatch(uint32* latch_id);
+ bool FreeLatch(uint32 latch_id);
+
+ private:
+ friend struct DefaultSingletonTraits<LatchAllocator>;
+
+ scoped_ptr<base::SharedMemory> shm_;
+ // Pointer to mapped shared memory.
+ volatile uint32* latches_;
+
+ DISALLOW_COPY_AND_ASSIGN(LatchAllocator);
+};
+
+////////////////////////////////////////////////////////////////////////////////
+/// LatchAllocator implementation
+
+LatchAllocator* LatchAllocator::GetInstance() {
+ return Singleton<LatchAllocator>::get();
+}
+
+LatchAllocator::LatchAllocator() {
+ base::SharedMemoryHandle handle;
+ RenderThread* render_thread = RenderThread::current();
+ if (!render_thread->Send(
+ new ViewHostMsg_AllocateSharedMemoryBuffer(size(), &handle))) {
+ NOTREACHED() << "failed to send sync IPC";
+ }
+
+ if (!base::SharedMemory::IsHandleValid(handle)) {
+ NOTREACHED() << "failed to create shared memory";
+ }
+
+ // Handle is closed by the SharedMemory object below. This stops
+ // base::FileDescriptor from closing it as well.
+#if defined(OS_POSIX)
+ handle.auto_close = false;
+#endif
+
+ shm_.reset(new base::SharedMemory(handle, false));
+ if (!shm_->Map(size())) {
+ NOTREACHED() << "failed to map shared memory";
+ }
+
+ latches_ = static_cast<uint32*>(shm_->memory());
+ // Mark all latches as unallocated.
+ for (uint32 i = 0; i < kMaxLatchesPerRenderer; ++i)
+ latches_[i] = kFreeLatch;
+}
+
+LatchAllocator::~LatchAllocator() {
+}
+
+bool LatchAllocator::AllocateLatch(uint32* latch_id) {
+ for (uint32 i = 0; i < kMaxLatchesPerRenderer; ++i) {
+ if (latches_[i] == kFreeLatch) {
+ // mark latch as taken and blocked.
+ // 0 means waiter will block, 1 means waiter will pass.
+ latches_[i] = 0;
+ *latch_id = i;
+ return true;
+ }
+ }
+ return false;
+}
+
+bool LatchAllocator::FreeLatch(uint32 latch_id) {
+ if (latch_id < kMaxLatchesPerRenderer && latches_[latch_id] != kFreeLatch) {
+ latches_[latch_id] = kFreeLatch;
+ return true;
+ }
+ return false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
static base::LazyInstance<GLES2Initializer> g_gles2_initializer(
base::LINKER_INITIALIZED);
@@ -257,9 +354,12 @@ RendererGLContext::RendererGLContext(GpuChannelHost* channel,
parent_(parent ?
parent->AsWeakPtr() : base::WeakPtr<RendererGLContext>()),
parent_texture_id_(0),
+ child_to_parent_latch_(kInvalidLatchId),
+ parent_to_child_latch_(kInvalidLatchId),
+ latch_transfer_buffer_id_(-1),
command_buffer_(NULL),
gles2_helper_(NULL),
- transfer_buffer_id_(0),
+ transfer_buffer_id_(-1),
gles2_implementation_(NULL),
last_error_(SUCCESS) {
DCHECK(channel);
@@ -361,7 +461,8 @@ bool RendererGLContext::Initialize(bool onscreen,
// Create a transfer buffer used to copy resources between the renderer
// process and the GPU process.
transfer_buffer_id_ =
- command_buffer_->CreateTransferBuffer(kTransferBufferSize);
+ command_buffer_->CreateTransferBuffer(kTransferBufferSize,
+ gpu::kCommandBufferSharedMemoryId);
if (transfer_buffer_id_ < 0) {
Destroy();
return false;
@@ -375,6 +476,26 @@ bool RendererGLContext::Initialize(bool onscreen,
return false;
}
+ // Register transfer buffer so that the context can access latches.
+ LatchAllocator* latch_shm = LatchAllocator::GetInstance();
+ latch_transfer_buffer_id_ = command_buffer_->RegisterTransferBuffer(
+ latch_shm->shared_memory(), LatchAllocator::size(),
+ gpu::kLatchSharedMemoryId);
+ if (latch_transfer_buffer_id_ != gpu::kLatchSharedMemoryId) {
+ Destroy();
+ return false;
+ }
+
+ // If this is a child context, setup latches for synchronization between child
+ // and parent.
+ if (parent_.get()) {
+ if (!CreateLatch(&child_to_parent_latch_) ||
+ !CreateLatch(&parent_to_child_latch_)) {
+ Destroy();
+ return false;
+ }
+ }
+
// Create the object exposing the OpenGL API.
gles2_implementation_ = new gpu::gles2::GLES2Implementation(
gles2_helper_,
@@ -389,15 +510,30 @@ bool RendererGLContext::Initialize(bool onscreen,
}
void RendererGLContext::Destroy() {
- if (parent_.get() && parent_texture_id_ != 0)
+ if (parent_.get() && parent_texture_id_ != 0) {
parent_->gles2_implementation_->FreeTextureId(parent_texture_id_);
+ parent_texture_id_ = 0;
+ }
delete gles2_implementation_;
gles2_implementation_ = NULL;
- if (command_buffer_ && transfer_buffer_id_ != 0) {
+ if (child_to_parent_latch_ != kInvalidLatchId) {
+ DestroyLatch(child_to_parent_latch_);
+ child_to_parent_latch_ = kInvalidLatchId;
+ }
+ if (parent_to_child_latch_ != kInvalidLatchId) {
+ DestroyLatch(parent_to_child_latch_);
+ parent_to_child_latch_ = kInvalidLatchId;
+ }
+ if (command_buffer_ && latch_transfer_buffer_id_ != -1) {
+ command_buffer_->DestroyTransferBuffer(latch_transfer_buffer_id_);
+ latch_transfer_buffer_id_ = -1;
+ }
+
+ if (command_buffer_ && transfer_buffer_id_ != -1) {
command_buffer_->DestroyTransferBuffer(transfer_buffer_id_);
- transfer_buffer_id_ = 0;
+ transfer_buffer_id_ = -1;
}
delete gles2_helper_;
@@ -420,3 +556,28 @@ void RendererGLContext::OnContextLost() {
if (context_lost_callback_.get())
context_lost_callback_->Run();
}
+
+bool RendererGLContext::CreateLatch(uint32* ret_latch) {
+ return LatchAllocator::GetInstance()->AllocateLatch(ret_latch);
+}
+
+bool RendererGLContext::DestroyLatch(uint32 latch) {
+ return LatchAllocator::GetInstance()->FreeLatch(latch);
+}
+
+bool RendererGLContext::GetParentToChildLatch(uint32* parent_to_child_latch) {
+ if (parent_.get()) {
+ *parent_to_child_latch = parent_to_child_latch_;
+ return true;
+ }
+ return false;
+}
+
+bool RendererGLContext::GetChildToParentLatch(uint32* child_to_parent_latch) {
+ if (parent_.get()) {
+ *child_to_parent_latch = child_to_parent_latch_;
+ return true;
+ }
+ return false;
+}
+
diff --git a/content/renderer/renderer_gl_context.h b/content/renderer/renderer_gl_context.h
index f03fa40..a40f5e1 100644
--- a/content/renderer/renderer_gl_context.h
+++ b/content/renderer/renderer_gl_context.h
@@ -185,6 +185,21 @@ class RendererGLContext : public base::SupportsWeakPtr<RendererGLContext> {
CommandBufferProxy* GetCommandBufferProxy();
+ // Create a latch for synchronization between contexts using glSetLatch and
+ // glWaitLatch.
+ // CreateLatch will only fail if there is a generally unrecoverable
+ // error, in which case 0 is returned. Returns latch_id on success.
+ bool CreateLatch(uint32* ret_latch);
+
+ // Destroy a latch.
+ bool DestroyLatch(uint32 latch);
+
+ // All child contexts get a latch pair automatically. These latches are used
+ // for synchronization with parent context. If *this* context does not have a
+ // parent context, these methods will return false.
+ bool GetParentToChildLatch(uint32* parent_to_child_latch);
+ bool GetChildToParentLatch(uint32* child_to_parent_latch);
+
private:
RendererGLContext(GpuChannelHost* channel,
RendererGLContext* parent);
@@ -205,6 +220,9 @@ class RendererGLContext : public base::SupportsWeakPtr<RendererGLContext> {
scoped_ptr<Callback0::Type> swap_buffers_callback_;
scoped_ptr<Callback0::Type> context_lost_callback_;
uint32 parent_texture_id_;
+ uint32 child_to_parent_latch_;
+ uint32 parent_to_child_latch_;
+ int32 latch_transfer_buffer_id_;
CommandBufferProxy* command_buffer_;
gpu::gles2::GLES2CmdHelper* gles2_helper_;
int32 transfer_buffer_id_;
diff --git a/content/renderer/webgraphicscontext3d_command_buffer_impl.cc b/content/renderer/webgraphicscontext3d_command_buffer_impl.cc
index ad4cec0..6f23d2da 100644
--- a/content/renderer/webgraphicscontext3d_command_buffer_impl.cc
+++ b/content/renderer/webgraphicscontext3d_command_buffer_impl.cc
@@ -340,6 +340,41 @@ void WebGraphicsContext3DCommandBufferImpl::copyTextureToParentTextureCHROMIUM(
copyTextureToCompositor(texture, parentTexture);
}
+void WebGraphicsContext3DCommandBufferImpl::getParentToChildLatchCHROMIUM(
+ WGC3Duint* latch_id)
+{
+ if (!context_->GetParentToChildLatch(latch_id)) {
+ LOG(ERROR) << "getLatch must only be called on child context";
+ synthesizeGLError(GL_INVALID_OPERATION);
+ *latch_id = 0xffffffffu;
+ }
+}
+
+void WebGraphicsContext3DCommandBufferImpl::getChildToParentLatchCHROMIUM(
+ WGC3Duint* latch_id)
+{
+ if (!context_->GetChildToParentLatch(latch_id)) {
+ LOG(ERROR) << "getLatch must only be called on child context";
+ synthesizeGLError(GL_INVALID_OPERATION);
+ *latch_id = 0xffffffffu;
+ }
+}
+
+void WebGraphicsContext3DCommandBufferImpl::waitLatchCHROMIUM(
+ WGC3Duint latch_id)
+{
+ makeContextCurrent();
+ glWaitLatchCHROMIUM(latch_id);
+}
+
+void WebGraphicsContext3DCommandBufferImpl::setLatchCHROMIUM(
+ WGC3Duint latch_id)
+{
+ makeContextCurrent();
+ glSetLatchCHROMIUM(latch_id);
+ glFlush(); // required to ensure set command is sent to GPU process
+}
+
WebKit::WebString WebGraphicsContext3DCommandBufferImpl::
getRequestableExtensionsCHROMIUM() {
return WebKit::WebString::fromUTF8(glGetRequestableExtensionsCHROMIUM());
diff --git a/content/renderer/webgraphicscontext3d_command_buffer_impl.h b/content/renderer/webgraphicscontext3d_command_buffer_impl.h
index f1cdc00..93c70ca 100644
--- a/content/renderer/webgraphicscontext3d_command_buffer_impl.h
+++ b/content/renderer/webgraphicscontext3d_command_buffer_impl.h
@@ -403,6 +403,11 @@ class WebGraphicsContext3DCommandBufferImpl
virtual void copyTextureToParentTextureCHROMIUM(
WebGLId texture, WebGLId parentTexture);
+ virtual void getParentToChildLatchCHROMIUM(WGC3Duint* latch_id);
+ virtual void getChildToParentLatchCHROMIUM(WGC3Duint* latch_id);
+ virtual void waitLatchCHROMIUM(WGC3Duint latch_id);
+ virtual void setLatchCHROMIUM(WGC3Duint latch_id);
+
virtual WebKit::WebString getRequestableExtensionsCHROMIUM();
virtual void requestExtensionCHROMIUM(const char*);
diff --git a/gpu/GLES2/gl2ext.h b/gpu/GLES2/gl2ext.h
index 02da1ea..d9d64e0 100644
--- a/gpu/GLES2/gl2ext.h
+++ b/gpu/GLES2/gl2ext.h
@@ -962,12 +962,12 @@ typedef void (GL_APIENTRYP PFNGLREQUESTEXTENSIONCHROMIUM) (const GLchar *extensi
#define glSetLatchCHROMIUM GLES2_GET_FUN(SetLatchCHROMIUM)
#define glWaitLatchCHROMIUM GLES2_GET_FUN(WaitLatchCHROMIUM)
#if !defined(GLES2_USE_CPP_BINDINGS)
-GL_APICALL void GL_APIENTRY glSetLatchCHROMIUM (GLint shm_id, GLuint latch_id);
-GL_APICALL void GL_APIENTRY glWaitLatchCHROMIUM (GLint shm_id, GLuint latch_id);
+GL_APICALL void GL_APIENTRY glSetLatchCHROMIUM (GLuint latch_id);
+GL_APICALL void GL_APIENTRY glWaitLatchCHROMIUM (GLuint latch_id);
#endif
#else
-typedef void (GL_APIENTRYP PFNGLSETLATCHCHROMIUM) (GLint shm_id, GLuint latch_id);
-typedef void (GL_APIENTRYP PFNGLWaitLATCHCHROMIUM) (GLint shm_id, GLuint latch_id);
+typedef void (GL_APIENTRYP PFNGLSETLATCHCHROMIUM) (GLuint latch_id);
+typedef void (GL_APIENTRYP PFNGLWaitLATCHCHROMIUM) (GLuint latch_id);
#endif
#endif
diff --git a/gpu/command_buffer/build_gles2_cmd_buffer.py b/gpu/command_buffer/build_gles2_cmd_buffer.py
index bd5bef7..dd9bfab 100755
--- a/gpu/command_buffer/build_gles2_cmd_buffer.py
+++ b/gpu/command_buffer/build_gles2_cmd_buffer.py
@@ -211,8 +211,8 @@ GL_APICALL void GL_APIENTRY glCopyTextureToParentTextureCHROMIUM (GLidBi
GL_APICALL void GL_APIENTRY glResizeCHROMIUM (GLuint width, GLuint height);
GL_APICALL const GLchar* GL_APIENTRY glGetRequestableExtensionsCHROMIUM (void);
GL_APICALL void GL_APIENTRY glRequestExtensionCHROMIUM (const char* extension);
-GL_APICALL void GL_APIENTRY glSetLatchCHROMIUM (GLint shm_id, GLuint latch_id);
-GL_APICALL void GL_APIENTRY glWaitLatchCHROMIUM (GLint shm_id, GLuint latch_id);
+GL_APICALL void GL_APIENTRY glSetLatchCHROMIUM (GLuint latch_id);
+GL_APICALL void GL_APIENTRY glWaitLatchCHROMIUM (GLuint latch_id);
"""
# This is the list of all commmands that will be generated and their Id.
diff --git a/gpu/command_buffer/client/gles2_c_lib_autogen.h b/gpu/command_buffer/client/gles2_c_lib_autogen.h
index bbc0faa..9a75761 100644
--- a/gpu/command_buffer/client/gles2_c_lib_autogen.h
+++ b/gpu/command_buffer/client/gles2_c_lib_autogen.h
@@ -877,15 +877,13 @@ void GLES2RequestExtensionCHROMIUM(const char* extension) {
GPU_CLIENT_LOG("RequestExtensionCHROMIUM" << "(" << extension << ")");
gles2::GetGLContext()->RequestExtensionCHROMIUM(extension);
}
-void GLES2SetLatchCHROMIUM(GLint shm_id, GLuint latch_id) {
- GPU_CLIENT_LOG(
- "SetLatchCHROMIUM" << "(" << shm_id << ", " << latch_id << ")");
- gles2::GetGLContext()->SetLatchCHROMIUM(shm_id, latch_id);
+void GLES2SetLatchCHROMIUM(GLuint latch_id) {
+ GPU_CLIENT_LOG("SetLatchCHROMIUM" << "(" << latch_id << ")");
+ gles2::GetGLContext()->SetLatchCHROMIUM(latch_id);
}
-void GLES2WaitLatchCHROMIUM(GLint shm_id, GLuint latch_id) {
- GPU_CLIENT_LOG(
- "WaitLatchCHROMIUM" << "(" << shm_id << ", " << latch_id << ")");
- gles2::GetGLContext()->WaitLatchCHROMIUM(shm_id, latch_id);
+void GLES2WaitLatchCHROMIUM(GLuint latch_id) {
+ GPU_CLIENT_LOG("WaitLatchCHROMIUM" << "(" << latch_id << ")");
+ gles2::GetGLContext()->WaitLatchCHROMIUM(latch_id);
}
#endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_C_LIB_AUTOGEN_H_
diff --git a/gpu/command_buffer/client/gles2_cmd_helper_autogen.h b/gpu/command_buffer/client/gles2_cmd_helper_autogen.h
index dc50582..c0adf24 100644
--- a/gpu/command_buffer/client/gles2_cmd_helper_autogen.h
+++ b/gpu/command_buffer/client/gles2_cmd_helper_autogen.h
@@ -1215,14 +1215,14 @@
c.Init(bucket_id);
}
- void SetLatchCHROMIUM(GLint shm_id, GLuint latch_id) {
+ void SetLatchCHROMIUM(GLuint latch_id) {
gles2::SetLatchCHROMIUM& c = GetCmdSpace<gles2::SetLatchCHROMIUM>();
- c.Init(shm_id, latch_id);
+ c.Init(latch_id);
}
- void WaitLatchCHROMIUM(GLint shm_id, GLuint latch_id) {
+ void WaitLatchCHROMIUM(GLuint latch_id) {
gles2::WaitLatchCHROMIUM& c = GetCmdSpace<gles2::WaitLatchCHROMIUM>();
- c.Init(shm_id, latch_id);
+ c.Init(latch_id);
}
#endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_CMD_HELPER_AUTOGEN_H_
diff --git a/gpu/command_buffer/client/gles2_demo.cc b/gpu/command_buffer/client/gles2_demo.cc
index daa51d2..91ef9bf2 100644
--- a/gpu/command_buffer/client/gles2_demo.cc
+++ b/gpu/command_buffer/client/gles2_demo.cc
@@ -78,7 +78,7 @@ bool GLES2Demo::Setup(void* hwnd, int32 size) {
size_t transfer_buffer_size = 512 * 1024;
int32 transfer_buffer_id =
- command_buffer->CreateTransferBuffer(transfer_buffer_size);
+ command_buffer->CreateTransferBuffer(transfer_buffer_size, -1);
Buffer transfer_buffer =
command_buffer->GetTransferBuffer(transfer_buffer_id);
if (!transfer_buffer.ptr)
diff --git a/gpu/command_buffer/client/gles2_implementation_autogen.h b/gpu/command_buffer/client/gles2_implementation_autogen.h
index 5e05132..bb392b0 100644
--- a/gpu/command_buffer/client/gles2_implementation_autogen.h
+++ b/gpu/command_buffer/client/gles2_implementation_autogen.h
@@ -889,12 +889,12 @@ const GLchar* GetRequestableExtensionsCHROMIUM();
void RequestExtensionCHROMIUM(const char* extension);
-void SetLatchCHROMIUM(GLint shm_id, GLuint latch_id) {
- helper_->SetLatchCHROMIUM(shm_id, latch_id);
+void SetLatchCHROMIUM(GLuint latch_id) {
+ helper_->SetLatchCHROMIUM(latch_id);
}
-void WaitLatchCHROMIUM(GLint shm_id, GLuint latch_id) {
- helper_->WaitLatchCHROMIUM(shm_id, latch_id);
+void WaitLatchCHROMIUM(GLuint latch_id) {
+ helper_->WaitLatchCHROMIUM(latch_id);
}
#endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_AUTOGEN_H_
diff --git a/gpu/command_buffer/client/gles2_implementation_unittest.cc b/gpu/command_buffer/client/gles2_implementation_unittest.cc
index c18c34a..d7ca276 100644
--- a/gpu/command_buffer/client/gles2_implementation_unittest.cc
+++ b/gpu/command_buffer/client/gles2_implementation_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 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.
@@ -62,7 +62,7 @@ class GLES2MockCommandBufferHelper : public CommandBuffer {
state_.get_offset = get_offset;
}
- virtual int32 CreateTransferBuffer(size_t size) {
+ virtual int32 CreateTransferBuffer(size_t size, int32 id_request) {
transfer_buffer_.reset(new int8[size]);
transfer_buffer_buffer_.ptr = transfer_buffer_.get();
transfer_buffer_buffer_.size = size;
@@ -79,7 +79,8 @@ class GLES2MockCommandBufferHelper : public CommandBuffer {
}
virtual int32 RegisterTransferBuffer(base::SharedMemory* shared_memory,
- size_t size) {
+ size_t size,
+ int32 id_request) {
GPU_NOTREACHED();
return -1;
}
@@ -189,7 +190,7 @@ class GLES2ImplementationTest : public testing::Test {
command_buffer_->Initialize(kCommandBufferSizeBytes);
EXPECT_EQ(kTransferBufferId,
- command_buffer_->CreateTransferBuffer(kTransferBufferSize));
+ command_buffer_->CreateTransferBuffer(kTransferBufferSize, -1));
transfer_buffer_ = command_buffer_->GetTransferBuffer(kTransferBufferId);
ClearTransferBuffer();
diff --git a/gpu/command_buffer/client/mapped_memory.cc b/gpu/command_buffer/client/mapped_memory.cc
index 1a63c6f..689b576b 100644
--- a/gpu/command_buffer/client/mapped_memory.cc
+++ b/gpu/command_buffer/client/mapped_memory.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 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.
@@ -52,7 +52,7 @@ void* MappedMemoryManager::Alloc(
// Make a new chunk to satisfy the request.
CommandBuffer* cmd_buf = helper_->command_buffer();
- int32 id = cmd_buf->CreateTransferBuffer(size);
+ int32 id = cmd_buf->CreateTransferBuffer(size, -1);
if (id == -1) {
return NULL;
}
diff --git a/gpu/command_buffer/common/command_buffer.h b/gpu/command_buffer/common/command_buffer.h
index bcc39ea..4cbcef1 100644
--- a/gpu/command_buffer/common/command_buffer.h
+++ b/gpu/command_buffer/common/command_buffer.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 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.
@@ -84,14 +84,21 @@ class CommandBuffer {
virtual void SetGetOffset(int32 get_offset) = 0;
// Create a transfer buffer and return a handle that uniquely
- // identifies it or -1 on error.
- virtual int32 CreateTransferBuffer(size_t size) = 0;
+ // identifies it or -1 on error. id_request lets the caller request a
+ // specific id for the transfer buffer, or -1 if the caller does not care.
+ // If the requested id can not be fulfilled, a different id will be returned.
+ // id_request must be either -1 or between 0 and 100.
+ virtual int32 CreateTransferBuffer(size_t size, int32 id_request) = 0;
// Register an existing shared memory object and get an ID that can be used
// to identify it in the command buffer. Callee dups the handle until
- // DestroyTransferBuffer is called.
+ // DestroyTransferBuffer is called. id_request lets the caller request a
+ // specific id for the transfer buffer, or -1 if the caller does not care.
+ // If the requested id can not be fulfilled, a different id will be returned.
+ // id_request must be either -1 or between 0 and 100.
virtual int32 RegisterTransferBuffer(base::SharedMemory* shared_memory,
- size_t size) = 0;
+ size_t size,
+ int32 id_request) = 0;
// Destroy a transfer buffer and recycle the handle.
virtual void DestroyTransferBuffer(int32 id) = 0;
diff --git a/gpu/command_buffer/common/command_buffer_mock.h b/gpu/command_buffer/common/command_buffer_mock.h
index 2966801..8281f7f 100644
--- a/gpu/command_buffer/common/command_buffer_mock.h
+++ b/gpu/command_buffer/common/command_buffer_mock.h
@@ -28,11 +28,12 @@ class MockCommandBuffer : public CommandBuffer {
MOCK_METHOD1(Flush, void(int32 put_offset));
MOCK_METHOD1(FlushSync, State(int32 put_offset));
MOCK_METHOD1(SetGetOffset, void(int32 get_offset));
- MOCK_METHOD1(CreateTransferBuffer, int32(size_t size));
+ MOCK_METHOD2(CreateTransferBuffer, int32(size_t size, int32 id_request));
MOCK_METHOD1(DestroyTransferBuffer, void(int32 handle));
MOCK_METHOD1(GetTransferBuffer, Buffer(int32 handle));
- MOCK_METHOD2(RegisterTransferBuffer, int32(base::SharedMemory* shared_memory,
- size_t size));
+ MOCK_METHOD3(RegisterTransferBuffer, int32(base::SharedMemory* shared_memory,
+ size_t size,
+ int32 id_request));
MOCK_METHOD1(SetToken, void(int32 token));
MOCK_METHOD1(SetParseError, void(error::Error error));
diff --git a/gpu/command_buffer/common/constants.h b/gpu/command_buffer/common/constants.h
index c028fc9..521a8b6 100644
--- a/gpu/command_buffer/common/constants.h
+++ b/gpu/command_buffer/common/constants.h
@@ -40,6 +40,12 @@ namespace error {
// failure.
const int32 kInvalidSharedMemoryId = -1;
+// Common Command Buffer shared memory transfer buffer ID.
+const int32 kCommandBufferSharedMemoryId = 4;
+
+// Common Latch shared memory transfer buffer ID.
+const int32 kLatchSharedMemoryId = 5;
+
} // namespace gpu
#endif // GPU_COMMAND_BUFFER_COMMON_CONSTANTS_H_
diff --git a/gpu/command_buffer/common/gles2_cmd_format_autogen.h b/gpu/command_buffer/common/gles2_cmd_format_autogen.h
index 4e97bc5..340273a 100644
--- a/gpu/command_buffer/common/gles2_cmd_format_autogen.h
+++ b/gpu/command_buffer/common/gles2_cmd_format_autogen.h
@@ -8914,30 +8914,26 @@ struct SetLatchCHROMIUM {
header.SetCmd<ValueType>();
}
- void Init(GLint _shm_id, GLuint _latch_id) {
+ void Init(GLuint _latch_id) {
SetHeader();
- shm_id = _shm_id;
latch_id = _latch_id;
}
- void* Set(void* cmd, GLint _shm_id, GLuint _latch_id) {
- static_cast<ValueType*>(cmd)->Init(_shm_id, _latch_id);
+ void* Set(void* cmd, GLuint _latch_id) {
+ static_cast<ValueType*>(cmd)->Init(_latch_id);
return NextCmdAddress<ValueType>(cmd);
}
gpu::CommandHeader header;
- int32 shm_id;
uint32 latch_id;
};
-COMPILE_ASSERT(sizeof(SetLatchCHROMIUM) == 12,
- Sizeof_SetLatchCHROMIUM_is_not_12);
+COMPILE_ASSERT(sizeof(SetLatchCHROMIUM) == 8,
+ Sizeof_SetLatchCHROMIUM_is_not_8);
COMPILE_ASSERT(offsetof(SetLatchCHROMIUM, header) == 0,
OffsetOf_SetLatchCHROMIUM_header_not_0);
-COMPILE_ASSERT(offsetof(SetLatchCHROMIUM, shm_id) == 4,
- OffsetOf_SetLatchCHROMIUM_shm_id_not_4);
-COMPILE_ASSERT(offsetof(SetLatchCHROMIUM, latch_id) == 8,
- OffsetOf_SetLatchCHROMIUM_latch_id_not_8);
+COMPILE_ASSERT(offsetof(SetLatchCHROMIUM, latch_id) == 4,
+ OffsetOf_SetLatchCHROMIUM_latch_id_not_4);
struct WaitLatchCHROMIUM {
typedef WaitLatchCHROMIUM ValueType;
@@ -8952,30 +8948,26 @@ struct WaitLatchCHROMIUM {
header.SetCmd<ValueType>();
}
- void Init(GLint _shm_id, GLuint _latch_id) {
+ void Init(GLuint _latch_id) {
SetHeader();
- shm_id = _shm_id;
latch_id = _latch_id;
}
- void* Set(void* cmd, GLint _shm_id, GLuint _latch_id) {
- static_cast<ValueType*>(cmd)->Init(_shm_id, _latch_id);
+ void* Set(void* cmd, GLuint _latch_id) {
+ static_cast<ValueType*>(cmd)->Init(_latch_id);
return NextCmdAddress<ValueType>(cmd);
}
gpu::CommandHeader header;
- int32 shm_id;
uint32 latch_id;
};
-COMPILE_ASSERT(sizeof(WaitLatchCHROMIUM) == 12,
- Sizeof_WaitLatchCHROMIUM_is_not_12);
+COMPILE_ASSERT(sizeof(WaitLatchCHROMIUM) == 8,
+ Sizeof_WaitLatchCHROMIUM_is_not_8);
COMPILE_ASSERT(offsetof(WaitLatchCHROMIUM, header) == 0,
OffsetOf_WaitLatchCHROMIUM_header_not_0);
-COMPILE_ASSERT(offsetof(WaitLatchCHROMIUM, shm_id) == 4,
- OffsetOf_WaitLatchCHROMIUM_shm_id_not_4);
-COMPILE_ASSERT(offsetof(WaitLatchCHROMIUM, latch_id) == 8,
- OffsetOf_WaitLatchCHROMIUM_latch_id_not_8);
+COMPILE_ASSERT(offsetof(WaitLatchCHROMIUM, latch_id) == 4,
+ OffsetOf_WaitLatchCHROMIUM_latch_id_not_4);
#endif // GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_FORMAT_AUTOGEN_H_
diff --git a/gpu/command_buffer/common/gles2_cmd_format_test_autogen.h b/gpu/command_buffer/common/gles2_cmd_format_test_autogen.h
index 603b71e..a69078a 100644
--- a/gpu/command_buffer/common/gles2_cmd_format_test_autogen.h
+++ b/gpu/command_buffer/common/gles2_cmd_format_test_autogen.h
@@ -3510,30 +3510,26 @@ TEST(GLES2FormatTest, SetLatchCHROMIUM) {
SetLatchCHROMIUM cmd = { { 0 } };
void* next_cmd = cmd.Set(
&cmd,
- static_cast<GLint>(11),
- static_cast<GLuint>(12));
+ static_cast<GLuint>(11));
EXPECT_EQ(static_cast<uint32>(SetLatchCHROMIUM::kCmdId),
cmd.header.command);
EXPECT_EQ(sizeof(cmd), cmd.header.size * 4u);
EXPECT_EQ(static_cast<char*>(next_cmd),
reinterpret_cast<char*>(&cmd) + sizeof(cmd));
- EXPECT_EQ(static_cast<GLint>(11), cmd.shm_id);
- EXPECT_EQ(static_cast<GLuint>(12), cmd.latch_id);
+ EXPECT_EQ(static_cast<GLuint>(11), cmd.latch_id);
}
TEST(GLES2FormatTest, WaitLatchCHROMIUM) {
WaitLatchCHROMIUM cmd = { { 0 } };
void* next_cmd = cmd.Set(
&cmd,
- static_cast<GLint>(11),
- static_cast<GLuint>(12));
+ static_cast<GLuint>(11));
EXPECT_EQ(static_cast<uint32>(WaitLatchCHROMIUM::kCmdId),
cmd.header.command);
EXPECT_EQ(sizeof(cmd), cmd.header.size * 4u);
EXPECT_EQ(static_cast<char*>(next_cmd),
reinterpret_cast<char*>(&cmd) + sizeof(cmd));
- EXPECT_EQ(static_cast<GLint>(11), cmd.shm_id);
- EXPECT_EQ(static_cast<GLuint>(12), cmd.latch_id);
+ EXPECT_EQ(static_cast<GLuint>(11), cmd.latch_id);
}
#endif // GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_FORMAT_TEST_AUTOGEN_H_
diff --git a/gpu/command_buffer/service/command_buffer_service.cc b/gpu/command_buffer/service/command_buffer_service.cc
index ab59473..86453eb 100644
--- a/gpu/command_buffer/service/command_buffer_service.cc
+++ b/gpu/command_buffer/service/command_buffer_service.cc
@@ -125,22 +125,27 @@ void CommandBufferService::SetGetOffset(int32 get_offset) {
get_offset_ = get_offset;
}
-int32 CommandBufferService::CreateTransferBuffer(size_t size) {
+int32 CommandBufferService::CreateTransferBuffer(size_t size,
+ int32 id_request) {
SharedMemory buffer;
if (!buffer.CreateAnonymous(size))
return -1;
- return RegisterTransferBuffer(&buffer, size);
+ return RegisterTransferBuffer(&buffer, size, id_request);
}
int32 CommandBufferService::RegisterTransferBuffer(
- base::SharedMemory* shared_memory, size_t size) {
+ base::SharedMemory* shared_memory, size_t size, int32 id_request) {
// Check we haven't exceeded the range that fits in a 32-bit integer.
if (unused_registered_object_elements_.empty()) {
if (registered_objects_.size() > std::numeric_limits<uint32>::max())
return -1;
}
+ // Check that the requested ID is sane (not too large, or less than -1)
+ if (id_request != -1 && (id_request > 100 || id_request < -1))
+ return -1;
+
// Duplicate the handle.
base::SharedMemoryHandle duped_shared_memory_handle;
if (!shared_memory->ShareToProcess(base::GetCurrentProcessHandle(),
@@ -160,6 +165,25 @@ int32 CommandBufferService::RegisterTransferBuffer(
buffer.ptr = duped_shared_memory->memory();
buffer.size = size;
buffer.shared_memory = duped_shared_memory.release();
+
+ // If caller requested specific id, first try to use id_request.
+ if (id_request != -1) {
+ int32 cur_size = static_cast<int32>(registered_objects_.size());
+ if (cur_size <= id_request) {
+ // Pad registered_objects_ to reach id_request.
+ registered_objects_.resize(static_cast<size_t>(id_request + 1));
+ for (int32 id = cur_size; id < id_request; ++id)
+ unused_registered_object_elements_.insert(id);
+ registered_objects_[id_request] = buffer;
+ return id_request;
+ } else if (!registered_objects_[id_request].shared_memory) {
+ // id_request is already in free list.
+ registered_objects_[id_request] = buffer;
+ unused_registered_object_elements_.erase(id_request);
+ return id_request;
+ }
+ }
+
if (unused_registered_object_elements_.empty()) {
int32 handle = static_cast<int32>(registered_objects_.size());
registered_objects_.push_back(buffer);
diff --git a/gpu/command_buffer/service/command_buffer_service.h b/gpu/command_buffer/service/command_buffer_service.h
index 0203623..a83a4e5 100644
--- a/gpu/command_buffer/service/command_buffer_service.h
+++ b/gpu/command_buffer/service/command_buffer_service.h
@@ -32,9 +32,10 @@ class CommandBufferService : public CommandBuffer {
virtual void Flush(int32 put_offset);
virtual State FlushSync(int32 put_offset);
virtual void SetGetOffset(int32 get_offset);
- virtual int32 CreateTransferBuffer(size_t size);
+ virtual int32 CreateTransferBuffer(size_t size, int32 id_request);
virtual int32 RegisterTransferBuffer(base::SharedMemory* shared_memory,
- size_t size);
+ size_t size,
+ int32 id_request);
virtual void DestroyTransferBuffer(int32 id);
virtual Buffer GetTransferBuffer(int32 handle);
virtual void SetToken(int32 token);
diff --git a/gpu/command_buffer/service/common_decoder_unittest.cc b/gpu/command_buffer/service/common_decoder_unittest.cc
index c71c92e..7099265 100644
--- a/gpu/command_buffer/service/common_decoder_unittest.cc
+++ b/gpu/command_buffer/service/common_decoder_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 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.
@@ -131,7 +131,8 @@ class MockCommandBufferEngine : public CommandBufferEngine {
private:
bool IsValidSharedMemoryId(int32 shm_id) {
- return shm_id == kValidShmId || shm_id == kStartValidShmId;
+ return shm_id == kValidShmId || shm_id == kStartValidShmId ||
+ shm_id == gpu::kLatchSharedMemoryId;
}
int8 buffer_[kBufferSize];
diff --git a/gpu/command_buffer/service/feature_info.cc b/gpu/command_buffer/service/feature_info.cc
index aa0f51b..61514a8 100644
--- a/gpu/command_buffer/service/feature_info.cc
+++ b/gpu/command_buffer/service/feature_info.cc
@@ -107,6 +107,7 @@ void FeatureInfo::AddFeatures(const char* desired_features) {
AddExtensionString("GL_CHROMIUM_resource_safe");
AddExtensionString("GL_CHROMIUM_resize");
AddExtensionString("GL_CHROMIUM_strict_attribs");
+ AddExtensionString("GL_CHROMIUM_latch");
// Only turn this feature on if it is requested. Not by default.
if (desired_features && ext.Desire("GL_CHROMIUM_webglsl")) {
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc
index e2bfc7a..9702902 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc
@@ -6274,7 +6274,13 @@ error::Error GLES2DecoderImpl::HandleSwapBuffers(
error::Error GLES2DecoderImpl::HandleSetLatchCHROMIUM(
uint32 immediate_data_size, const gles2::SetLatchCHROMIUM& c) {
- int32 shm_id = c.shm_id;
+ // Ensure the side effects of previous commands are visible to other contexts.
+ // There is no need to do this for ANGLE because it uses a
+ // single D3D device for all contexts.
+ if (!IsAngle())
+ glFlush();
+
+ int32 shm_id = gpu::kLatchSharedMemoryId;
uint32 latch_id = c.latch_id;
uint32 shm_offset = 0;
base::subtle::Atomic32* latch;
@@ -6292,7 +6298,7 @@ error::Error GLES2DecoderImpl::HandleSetLatchCHROMIUM(
error::Error GLES2DecoderImpl::HandleWaitLatchCHROMIUM(
uint32 immediate_data_size, const gles2::WaitLatchCHROMIUM& c) {
- int32 shm_id = c.shm_id;
+ int32 shm_id = gpu::kLatchSharedMemoryId;
uint32 latch_id = c.latch_id;
uint32 shm_offset = 0;
base::subtle::Atomic32* latch;
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc b/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc
index 89cae82..99b41de 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc
@@ -15,6 +15,7 @@
#include "gpu/command_buffer/service/program_manager.h"
#include "gpu/command_buffer/service/test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/gfx/gl/gl_implementation.h"
using ::gfx::MockGLInterface;
using ::testing::_;
@@ -2873,6 +2874,13 @@ TEST_F(GLES2DecoderWithShaderTest, VertexAttribPointer) {
}
TEST_F(GLES2DecoderTest, SetLatch) {
+ bool isAngle = false;
+#if defined(OS_WIN)
+ isAngle = (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2);
+#endif
+ if (!isAngle) {
+ EXPECT_CALL(*gl_, Flush()).Times(3);
+ }
const uint32 kLatchId = 1;
base::subtle::Atomic32* latches = static_cast<base::subtle::Atomic32*>(
shared_memory_base_);
@@ -2881,20 +2889,17 @@ TEST_F(GLES2DecoderTest, SetLatch) {
latches[kLatchId] = 0;
latches[kLastValidLatchId] = 0;
SetLatchCHROMIUM cmd;
- // Check bad shared memory id.
- cmd.Init(kInvalidSharedMemoryId, kLatchId);
- EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd));
// Check out of range latch id.
- cmd.Init(shared_memory_id_, kInvalidLatchId);
+ cmd.Init(kInvalidLatchId);
EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd));
- cmd.Init(shared_memory_id_, kLatchId);
+ cmd.Init(kLatchId);
// Check valid latch.
EXPECT_EQ(0, latches[kLatchId]);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(1, latches[kLatchId]);
// Check last valid latch.
EXPECT_EQ(0, latches[kLastValidLatchId]);
- cmd.Init(shared_memory_id_, kLastValidLatchId);
+ cmd.Init(kLastValidLatchId);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(1, latches[kLastValidLatchId]);
}
@@ -2908,21 +2913,18 @@ TEST_F(GLES2DecoderTest, WaitLatch) {
latches[kLatchId] = 0;
latches[kLastValidLatchId] = 0;
WaitLatchCHROMIUM cmd;
- // Check bad shared memory id.
- cmd.Init(kInvalidSharedMemoryId, kLatchId);
- EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd));
// Check out of range latch id.
- cmd.Init(shared_memory_id_, kInvalidLatchId);
+ cmd.Init(kInvalidLatchId);
EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd));
// Check valid latch.
- cmd.Init(shared_memory_id_, kLatchId);
+ cmd.Init(kLatchId);
EXPECT_EQ(0, latches[kLatchId]);
EXPECT_EQ(error::kWaiting, ExecuteCmd(cmd));
latches[kLatchId] = 1;
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(0, latches[kLatchId]);
// Check last valid latch.
- cmd.Init(shared_memory_id_, kLastValidLatchId);
+ cmd.Init(kLastValidLatchId);
EXPECT_EQ(0, latches[kLastValidLatchId]);
EXPECT_EQ(error::kWaiting, ExecuteCmd(cmd));
latches[kLastValidLatchId] = 1;
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h
index ed1f025..2d027f7 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h
@@ -287,7 +287,8 @@ class GLES2DecoderTestBase : public testing::Test {
}
virtual Buffer GetSharedMemoryBuffer(int32 shm_id) {
- return shm_id == kSharedMemoryId ? valid_buffer_ : invalid_buffer_;
+ return shm_id == kSharedMemoryId || shm_id == gpu::kLatchSharedMemoryId ?
+ valid_buffer_ : invalid_buffer_;
}
void ClearSharedMemory() {
diff --git a/gpu/demos/framework/window.cc b/gpu/demos/framework/window.cc
index 1440110..fead4ac 100644
--- a/gpu/demos/framework/window.cc
+++ b/gpu/demos/framework/window.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 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.
@@ -78,7 +78,7 @@ bool Window::CreateRenderContext(gfx::PluginWindowHandle hwnd) {
}
int32 transfer_buffer_id =
- command_buffer->CreateTransferBuffer(kTransferBufferSize);
+ command_buffer->CreateTransferBuffer(kTransferBufferSize, -1);
Buffer transfer_buffer =
command_buffer->GetTransferBuffer(transfer_buffer_id);
if (transfer_buffer.ptr == NULL) return false;
diff --git a/gpu/pgl/command_buffer_pepper.cc b/gpu/pgl/command_buffer_pepper.cc
index c508b53..38b642e 100644
--- a/gpu/pgl/command_buffer_pepper.cc
+++ b/gpu/pgl/command_buffer_pepper.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 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.
@@ -139,7 +139,7 @@ void CommandBufferPepper::SetGetOffset(int32 get_offset) {
GPU_NOTREACHED();
}
-int32 CommandBufferPepper::CreateTransferBuffer(size_t size) {
+int32 CommandBufferPepper::CreateTransferBuffer(size_t size, int32 id_request) {
int32_t id;
if (NPERR_NO_ERROR != device_->createBuffer(npp_, context_, size, &id))
return -1;
@@ -149,7 +149,8 @@ int32 CommandBufferPepper::CreateTransferBuffer(size_t size) {
int32 CommandBufferPepper::RegisterTransferBuffer(
base::SharedMemory* shared_memory,
- size_t size) {
+ size_t size,
+ int32 id_request) {
// Not implemented by proxy.
GPU_NOTREACHED();
return -1;
diff --git a/gpu/pgl/command_buffer_pepper.h b/gpu/pgl/command_buffer_pepper.h
index 8f990da..446ec4a 100644
--- a/gpu/pgl/command_buffer_pepper.h
+++ b/gpu/pgl/command_buffer_pepper.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 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.
@@ -37,11 +37,12 @@ class CommandBufferPepper : public gpu::CommandBuffer {
virtual void Flush(int32 put_offset);
virtual State FlushSync(int32 put_offset);
virtual void SetGetOffset(int32 get_offset);
- virtual int32 CreateTransferBuffer(size_t size);
+ virtual int32 CreateTransferBuffer(size_t size, int32 id_request);
virtual void DestroyTransferBuffer(int32 id);
virtual gpu::Buffer GetTransferBuffer(int32 handle);
virtual int32 RegisterTransferBuffer(base::SharedMemory* shared_memory,
- size_t size);
+ size_t size,
+ int32 id_request);
virtual void SetToken(int32 token);
virtual void SetParseError(gpu::error::Error error);
diff --git a/gpu/pgl/pgl.cc b/gpu/pgl/pgl.cc
index c3b62f1..d98cb62 100644
--- a/gpu/pgl/pgl.cc
+++ b/gpu/pgl/pgl.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 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.
@@ -77,7 +77,7 @@ PGLBoolean PGLContextImpl::Initialize(int32 transfer_buffer_size) {
gpu::Buffer buffer = command_buffer_->GetRingBuffer();
if (gles2_helper_->Initialize(buffer.size)) {
transfer_buffer_id_ =
- command_buffer_->CreateTransferBuffer(kTransferBufferSize);
+ command_buffer_->CreateTransferBuffer(kTransferBufferSize, -1);
gpu::Buffer transfer_buffer =
command_buffer_->GetTransferBuffer(transfer_buffer_id_);
if (transfer_buffer.ptr) {
diff --git a/ppapi/proxy/ppb_context_3d_proxy.cc b/ppapi/proxy/ppb_context_3d_proxy.cc
index dcbe943..396ccf6 100644
--- a/ppapi/proxy/ppb_context_3d_proxy.cc
+++ b/ppapi/proxy/ppb_context_3d_proxy.cc
@@ -183,9 +183,10 @@ class PepperCommandBuffer : public gpu::CommandBuffer {
virtual void Flush(int32 put_offset);
virtual State FlushSync(int32 put_offset);
virtual void SetGetOffset(int32 get_offset);
- virtual int32 CreateTransferBuffer(size_t size);
+ virtual int32 CreateTransferBuffer(size_t size, int32 id_request);
virtual int32 RegisterTransferBuffer(base::SharedMemory* shared_memory,
- size_t size);
+ size_t size,
+ int32 id_request);
virtual void DestroyTransferBuffer(int32 id);
virtual gpu::Buffer GetTransferBuffer(int32 handle);
virtual void SetToken(int32 token);
@@ -303,7 +304,7 @@ void PepperCommandBuffer::SetGetOffset(int32 get_offset) {
NOTREACHED();
}
-int32 PepperCommandBuffer::CreateTransferBuffer(size_t size) {
+int32 PepperCommandBuffer::CreateTransferBuffer(size_t size, int32 id_request) {
if (last_state_.error == gpu::error::kNoError) {
int32 id;
if (Send(new PpapiHostMsg_PPBContext3D_CreateTransferBuffer(
@@ -317,7 +318,8 @@ int32 PepperCommandBuffer::CreateTransferBuffer(size_t size) {
int32 PepperCommandBuffer::RegisterTransferBuffer(
base::SharedMemory* shared_memory,
- size_t size) {
+ size_t size,
+ int32 id_request) {
// Not implemented in proxy.
NOTREACHED();
return -1;
@@ -425,7 +427,7 @@ bool Context3D::CreateImplementation() {
return false;
transfer_buffer_id_ =
- command_buffer_->CreateTransferBuffer(kTransferBufferSize);
+ command_buffer_->CreateTransferBuffer(kTransferBufferSize, -1);
if (transfer_buffer_id_ < 0)
return false;
diff --git a/webkit/gpu/webgraphicscontext3d_in_process_impl.cc b/webkit/gpu/webgraphicscontext3d_in_process_impl.cc
index 5c72367..27a0c99 100644
--- a/webkit/gpu/webgraphicscontext3d_in_process_impl.cc
+++ b/webkit/gpu/webgraphicscontext3d_in_process_impl.cc
@@ -654,6 +654,26 @@ void WebGraphicsContext3DInProcessImpl::copyTextureToParentTextureCHROMIUM(
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, bound_fbo_);
}
+void WebGraphicsContext3DInProcessImpl::getLatchParentToChildCHROMIUM(
+ WGC3Duint* latch_id)
+{
+}
+
+void WebGraphicsContext3DInProcessImpl::getLatchChildToParentCHROMIUM(
+ WGC3Duint* latch_id)
+{
+}
+
+void WebGraphicsContext3DInProcessImpl::waitLatchCHROMIUM(
+ WGC3Duint latch_id)
+{
+}
+
+void WebGraphicsContext3DInProcessImpl::setLatchCHROMIUM(
+ WGC3Duint latch_id)
+{
+}
+
WebString WebGraphicsContext3DInProcessImpl::
getRequestableExtensionsCHROMIUM() {
return WebString();
diff --git a/webkit/gpu/webgraphicscontext3d_in_process_impl.h b/webkit/gpu/webgraphicscontext3d_in_process_impl.h
index e05cb6b..600b22c 100644
--- a/webkit/gpu/webgraphicscontext3d_in_process_impl.h
+++ b/webkit/gpu/webgraphicscontext3d_in_process_impl.h
@@ -89,6 +89,11 @@ class WebGraphicsContext3DInProcessImpl : public WebGraphicsContext3D {
virtual void copyTextureToParentTextureCHROMIUM(
WebGLId texture, WebGLId parentTexture);
+ virtual void getLatchParentToChildCHROMIUM(WGC3Duint* latch_id);
+ virtual void getLatchChildToParentCHROMIUM(WGC3Duint* latch_id);
+ virtual void waitLatchCHROMIUM(WGC3Duint latch_id);
+ virtual void setLatchCHROMIUM(WGC3Duint latch_id);
+
virtual WebString getRequestableExtensionsCHROMIUM();
virtual void requestExtensionCHROMIUM(const char*);
diff --git a/webkit/plugins/ppapi/ppb_context_3d_impl.cc b/webkit/plugins/ppapi/ppb_context_3d_impl.cc
index 9494459..7d3b498 100644
--- a/webkit/plugins/ppapi/ppb_context_3d_impl.cc
+++ b/webkit/plugins/ppapi/ppb_context_3d_impl.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 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.
@@ -199,7 +199,7 @@ int32_t CreateTransferBuffer(PP_Resource context_id, uint32_t size) {
Resource::GetAs<PPB_Context3D_Impl>(context_id));
if (!context.get() || !context->command_buffer())
return 0;
- return context->command_buffer()->CreateTransferBuffer(size);
+ return context->command_buffer()->CreateTransferBuffer(size, -1);
}
PP_Bool DestroyTransferBuffer(PP_Resource context_id, int32_t id) {
@@ -310,7 +310,7 @@ bool PPB_Context3D_Impl::CreateImplementation() {
// Create a transfer buffer used to copy resources between the renderer
// process and the GPU process.
transfer_buffer_id_ =
- command_buffer->CreateTransferBuffer(kTransferBufferSize);
+ command_buffer->CreateTransferBuffer(kTransferBufferSize, -1);
if (transfer_buffer_id_ < 0)
return false;