summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authorpiman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-01 09:06:43 +0000
committerpiman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-01 09:06:43 +0000
commit046fa1ac81455233e53b629f2160ca9eab08e741 (patch)
treeb9376b2320f2fd801a71580f9325bf31ee950359 /ppapi
parent966a3c6eda39c487da641e1b5e4ccba06802e3ba (diff)
downloadchromium_src-046fa1ac81455233e53b629f2160ca9eab08e741.zip
chromium_src-046fa1ac81455233e53b629f2160ca9eab08e741.tar.gz
chromium_src-046fa1ac81455233e53b629f2160ca9eab08e741.tar.bz2
Remove CommandBuffer::GetTransferBuffer.
The only time we call GetTransferBuffer is on Pepper, right after CreateTransferBuffer, so combine the two. This lets us dramatically remove all the maintenance burden (maps) and extra IPCs. Also separate service-only calls out of CommandBuffer, into CommandBufferServiceBase BUG=None Review URL: https://codereview.chromium.org/215803002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260806 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/proxy/nacl_message_scanner.cc2
-rw-r--r--ppapi/proxy/nacl_message_scanner_unittest.cc6
-rw-r--r--ppapi/proxy/ppapi_command_buffer_proxy.cc76
-rw-r--r--ppapi/proxy/ppapi_command_buffer_proxy.h9
-rw-r--r--ppapi/proxy/ppapi_messages.h9
-rw-r--r--ppapi/proxy/ppb_graphics_3d_proxy.cc64
-rw-r--r--ppapi/proxy/ppb_graphics_3d_proxy.h17
-rw-r--r--ppapi/thunk/ppb_graphics_3d_api.h6
8 files changed, 52 insertions, 137 deletions
diff --git a/ppapi/proxy/nacl_message_scanner.cc b/ppapi/proxy/nacl_message_scanner.cc
index 6fb98f5..1cbf53d 100644
--- a/ppapi/proxy/nacl_message_scanner.cc
+++ b/ppapi/proxy/nacl_message_scanner.cc
@@ -327,7 +327,7 @@ bool NaClMessageScanner::ScanMessage(
uint32_t type = iter->second;
pending_sync_msgs_.erase(iter);
switch (type) {
- CASE_FOR_REPLY(PpapiHostMsg_PPBGraphics3D_GetTransferBuffer)
+ CASE_FOR_REPLY(PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer)
CASE_FOR_REPLY(PpapiHostMsg_PPBImageData_CreateSimple)
CASE_FOR_REPLY(PpapiHostMsg_ResourceSyncCall)
CASE_FOR_REPLY(PpapiHostMsg_SharedMemory_CreateSharedMemory)
diff --git a/ppapi/proxy/nacl_message_scanner_unittest.cc b/ppapi/proxy/nacl_message_scanner_unittest.cc
index 8e81e24..3e43955 100644
--- a/ppapi/proxy/nacl_message_scanner_unittest.cc
+++ b/ppapi/proxy/nacl_message_scanner_unittest.cc
@@ -69,11 +69,13 @@ TEST_F(NaClMessageScannerTest, SyncMessageAndReply) {
NaClMessageScanner test;
ppapi::proxy::SerializedHandle handle(
ppapi::proxy::SerializedHandle::SHARED_MEMORY);
+ int id = -1;
IPC::Message msg =
- PpapiHostMsg_PPBGraphics3D_GetTransferBuffer(
+ PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer(
ppapi::API_ID_PPB_GRAPHICS_3D,
HostResource(),
- 0, // id
+ 4096, // size
+ &id,
&handle);
scoped_ptr<IPC::Message> new_msg_ptr;
EXPECT_NE(msg.type(), FindPendingSyncMessage(test, msg));
diff --git a/ppapi/proxy/ppapi_command_buffer_proxy.cc b/ppapi/proxy/ppapi_command_buffer_proxy.cc
index 4d140f2..a1ac347 100644
--- a/ppapi/proxy/ppapi_command_buffer_proxy.cc
+++ b/ppapi/proxy/ppapi_command_buffer_proxy.cc
@@ -106,11 +106,6 @@ void PpapiCommandBufferProxy::SetGetBuffer(int32 transfer_buffer_id) {
}
}
-void PpapiCommandBufferProxy::SetGetOffset(int32 get_offset) {
- // Not implemented in proxy.
- NOTREACHED();
-}
-
scoped_refptr<gpu::Buffer> PpapiCommandBufferProxy::CreateTransferBuffer(
size_t size,
int32* id) {
@@ -119,66 +114,18 @@ scoped_refptr<gpu::Buffer> PpapiCommandBufferProxy::CreateTransferBuffer(
if (last_state_.error != gpu::error::kNoError)
return NULL;
- if (!Send(new PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer(
- ppapi::API_ID_PPB_GRAPHICS_3D, resource_, size, id))) {
- return NULL;
- }
-
- if ((*id) <= 0)
- return NULL;
-
- return GetTransferBuffer(*id);
-}
-
-void PpapiCommandBufferProxy::DestroyTransferBuffer(int32 id) {
- if (last_state_.error != gpu::error::kNoError)
- return;
-
- // Remove the transfer buffer from the client side4 cache.
- TransferBufferMap::iterator it = transfer_buffers_.find(id);
-
- // Remove reference to buffer, allowing the shared memory object to be
- // deleted, closing the handle in the process.
- if (it != transfer_buffers_.end())
- transfer_buffers_.erase(it);
-
- Send(new PpapiHostMsg_PPBGraphics3D_DestroyTransferBuffer(
- ppapi::API_ID_PPB_GRAPHICS_3D, resource_, id));
-}
-
-void PpapiCommandBufferProxy::Echo(const base::Closure& callback) {
- NOTREACHED();
-}
-
-uint32 PpapiCommandBufferProxy::CreateStreamTexture(uint32 texture_id) {
- NOTREACHED();
- return 0;
-}
-
-scoped_refptr<gpu::Buffer> PpapiCommandBufferProxy::GetTransferBuffer(
- int32 id) {
- if (last_state_.error != gpu::error::kNoError)
- return NULL;
-
- // Check local cache to see if there is already a client side shared memory
- // object for this id.
- TransferBufferMap::iterator it = transfer_buffers_.find(id);
- if (it != transfer_buffers_.end()) {
- return it->second;
- }
-
// Assuming we are in the renderer process, the service is responsible for
// duplicating the handle. This might not be true for NaCl.
ppapi::proxy::SerializedHandle handle(
ppapi::proxy::SerializedHandle::SHARED_MEMORY);
- if (!Send(new PpapiHostMsg_PPBGraphics3D_GetTransferBuffer(
- ppapi::API_ID_PPB_GRAPHICS_3D, resource_, id, &handle))) {
+ if (!Send(new PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer(
+ ppapi::API_ID_PPB_GRAPHICS_3D, resource_, size, id, &handle))) {
return NULL;
}
- if (!handle.is_shmem())
+
+ if (*id <= 0 || !handle.is_shmem())
return NULL;
- // Cache the transfer buffer shared memory object client side.
scoped_ptr<base::SharedMemory> shared_memory(
new base::SharedMemory(handle.shmem(), false));
@@ -191,21 +138,24 @@ scoped_refptr<gpu::Buffer> PpapiCommandBufferProxy::GetTransferBuffer(
scoped_refptr<gpu::Buffer> buffer =
new gpu::Buffer(shared_memory.Pass(), handle.size());
- transfer_buffers_[id] = buffer;
return buffer;
}
-void PpapiCommandBufferProxy::SetToken(int32 token) {
- NOTREACHED();
+void PpapiCommandBufferProxy::DestroyTransferBuffer(int32 id) {
+ if (last_state_.error != gpu::error::kNoError)
+ return;
+
+ Send(new PpapiHostMsg_PPBGraphics3D_DestroyTransferBuffer(
+ ppapi::API_ID_PPB_GRAPHICS_3D, resource_, id));
}
-void PpapiCommandBufferProxy::SetParseError(gpu::error::Error error) {
+void PpapiCommandBufferProxy::Echo(const base::Closure& callback) {
NOTREACHED();
}
-void PpapiCommandBufferProxy::SetContextLostReason(
- gpu::error::ContextLostReason reason) {
+uint32 PpapiCommandBufferProxy::CreateStreamTexture(uint32 texture_id) {
NOTREACHED();
+ return 0;
}
uint32 PpapiCommandBufferProxy::InsertSyncPoint() {
diff --git a/ppapi/proxy/ppapi_command_buffer_proxy.h b/ppapi/proxy/ppapi_command_buffer_proxy.h
index 3116306..20a09a5 100644
--- a/ppapi/proxy/ppapi_command_buffer_proxy.h
+++ b/ppapi/proxy/ppapi_command_buffer_proxy.h
@@ -37,15 +37,9 @@ class PPAPI_PROXY_EXPORT PpapiCommandBufferProxy : public gpu::CommandBuffer,
virtual void WaitForTokenInRange(int32 start, int32 end) OVERRIDE;
virtual void WaitForGetOffsetInRange(int32 start, int32 end) OVERRIDE;
virtual void SetGetBuffer(int32 transfer_buffer_id) OVERRIDE;
- virtual void SetGetOffset(int32 get_offset) OVERRIDE;
virtual scoped_refptr<gpu::Buffer> CreateTransferBuffer(size_t size,
int32* id) OVERRIDE;
virtual void DestroyTransferBuffer(int32 id) OVERRIDE;
- virtual scoped_refptr<gpu::Buffer> GetTransferBuffer(int32 id) OVERRIDE;
- virtual void SetToken(int32 token) OVERRIDE;
- virtual void SetParseError(gpu::error::Error error) OVERRIDE;
- virtual void SetContextLostReason(gpu::error::ContextLostReason reason)
- OVERRIDE;
// gpu::GpuControl implementation:
virtual gpu::Capabilities GetCapabilities() OVERRIDE;
@@ -70,9 +64,6 @@ class PPAPI_PROXY_EXPORT PpapiCommandBufferProxy : public gpu::CommandBuffer,
bool Send(IPC::Message* msg);
void UpdateState(const gpu::CommandBuffer::State& state, bool success);
- typedef base::hash_map<int32, scoped_refptr<gpu::Buffer> > TransferBufferMap;
- TransferBufferMap transfer_buffers_;
-
State last_state_;
HostResource resource_;
diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h
index 4366773..3c666df 100644
--- a/ppapi/proxy/ppapi_messages.h
+++ b/ppapi/proxy/ppapi_messages.h
@@ -807,17 +807,14 @@ IPC_SYNC_MESSAGE_ROUTED3_2(PpapiHostMsg_PPBGraphics3D_WaitForGetOffsetInRange,
IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBGraphics3D_AsyncFlush,
ppapi::HostResource /* context */,
int32 /* put_offset */)
-IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer,
+IPC_SYNC_MESSAGE_ROUTED2_2(PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer,
ppapi::HostResource /* context */,
uint32 /* size */,
- int32 /* id */)
+ int32 /* id */,
+ ppapi::proxy::SerializedHandle /* transfer_buffer */)
IPC_SYNC_MESSAGE_ROUTED2_0(PpapiHostMsg_PPBGraphics3D_DestroyTransferBuffer,
ppapi::HostResource /* context */,
int32 /* id */)
-IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBGraphics3D_GetTransferBuffer,
- ppapi::HostResource /* context */,
- int32 /* id */,
- ppapi::proxy::SerializedHandle /* transfer_buffer */)
IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBGraphics3D_SwapBuffers,
ppapi::HostResource /* graphics_3d */)
IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBGraphics3D_InsertSyncPoint,
diff --git a/ppapi/proxy/ppb_graphics_3d_proxy.cc b/ppapi/proxy/ppb_graphics_3d_proxy.cc
index 847e294..20c55de 100644
--- a/ppapi/proxy/ppb_graphics_3d_proxy.cc
+++ b/ppapi/proxy/ppb_graphics_3d_proxy.cc
@@ -28,18 +28,10 @@ namespace {
const int32 kCommandBufferSize = 1024 * 1024;
const int32 kTransferBufferSize = 1024 * 1024;
-base::SharedMemoryHandle TransportSHMHandleFromInt(Dispatcher* dispatcher,
- int shm_handle) {
- // TODO(piman): Change trusted interface to return a PP_FileHandle, those
- // casts are ugly.
+base::SharedMemoryHandle TransportSHMHandle(Dispatcher* dispatcher,
+ base::SharedMemory* shm) {
base::PlatformFile source =
-#if defined(OS_WIN)
- reinterpret_cast<HANDLE>(static_cast<intptr_t>(shm_handle));
-#elif defined(OS_POSIX)
- shm_handle;
-#else
- #error Not implemented.
-#endif
+ IPC::PlatformFileForTransitToPlatformFile(shm->handle());
// Don't close the handle, it doesn't belong to us.
return dispatcher->ShareHandleWithRemote(source, false);
}
@@ -84,20 +76,17 @@ PP_Bool Graphics3D::Flush(int32_t put_offset) {
return PP_FALSE;
}
-int32_t Graphics3D::CreateTransferBuffer(uint32_t size) {
- return PP_FALSE;
+scoped_refptr<gpu::Buffer> Graphics3D::CreateTransferBuffer(
+ uint32_t size,
+ int32_t* id) {
+ *id = -1;
+ return NULL;
}
PP_Bool Graphics3D::DestroyTransferBuffer(int32_t id) {
return PP_FALSE;
}
-PP_Bool Graphics3D::GetTransferBuffer(int32_t id,
- int* shm_handle,
- uint32_t* shm_size) {
- return PP_FALSE;
-}
-
gpu::CommandBuffer::State Graphics3D::WaitForTokenInRange(int32_t start,
int32_t end) {
return GetErrorState();
@@ -203,8 +192,6 @@ bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) {
OnMsgCreateTransferBuffer)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_DestroyTransferBuffer,
OnMsgDestroyTransferBuffer)
- IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_GetTransferBuffer,
- OnMsgGetTransferBuffer)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_SwapBuffers,
OnMsgSwapBuffers)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_InsertSyncPoint,
@@ -301,12 +288,22 @@ void PPB_Graphics3D_Proxy::OnMsgAsyncFlush(const HostResource& context,
void PPB_Graphics3D_Proxy::OnMsgCreateTransferBuffer(
const HostResource& context,
uint32 size,
- int32* id) {
+ int32* id,
+ ppapi::proxy::SerializedHandle* transfer_buffer) {
+ transfer_buffer->set_null_shmem();
EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
- if (enter.succeeded())
- *id = enter.object()->CreateTransferBuffer(size);
- else
+ if (enter.succeeded()) {
+ scoped_refptr<gpu::Buffer> buffer =
+ enter.object()->CreateTransferBuffer(size, id);
+ if (!buffer)
+ return;
+ DCHECK(buffer->shared_memory());
+ transfer_buffer->set_shmem(
+ TransportSHMHandle(dispatcher(), buffer->shared_memory()),
+ buffer->size());
+ } else {
*id = -1;
+ }
}
void PPB_Graphics3D_Proxy::OnMsgDestroyTransferBuffer(
@@ -317,23 +314,6 @@ void PPB_Graphics3D_Proxy::OnMsgDestroyTransferBuffer(
enter.object()->DestroyTransferBuffer(id);
}
-void PPB_Graphics3D_Proxy::OnMsgGetTransferBuffer(
- const HostResource& context,
- int32 id,
- ppapi::proxy::SerializedHandle* transfer_buffer) {
- transfer_buffer->set_null_shmem();
-
- EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
- int shm_handle = 0;
- uint32_t shm_size = 0;
- if (enter.succeeded() &&
- enter.object()->GetTransferBuffer(id, &shm_handle, &shm_size)) {
- transfer_buffer->set_shmem(
- TransportSHMHandleFromInt(dispatcher(), shm_handle),
- shm_size);
- }
-}
-
void PPB_Graphics3D_Proxy::OnMsgSwapBuffers(const HostResource& context) {
EnterHostFromHostResourceForceCallback<PPB_Graphics3D_API> enter(
context, callback_factory_,
diff --git a/ppapi/proxy/ppb_graphics_3d_proxy.h b/ppapi/proxy/ppb_graphics_3d_proxy.h
index 70c96e9..f86b16d 100644
--- a/ppapi/proxy/ppb_graphics_3d_proxy.h
+++ b/ppapi/proxy/ppb_graphics_3d_proxy.h
@@ -37,11 +37,9 @@ class Graphics3D : public PPB_Graphics3D_Shared {
virtual PP_Bool SetGetBuffer(int32_t shm_id) OVERRIDE;
virtual gpu::CommandBuffer::State GetState() OVERRIDE;
virtual PP_Bool Flush(int32_t put_offset) OVERRIDE;
- virtual int32_t CreateTransferBuffer(uint32_t size) OVERRIDE;
+ virtual scoped_refptr<gpu::Buffer> CreateTransferBuffer(uint32_t size,
+ int32* id) OVERRIDE;
virtual PP_Bool DestroyTransferBuffer(int32_t id) OVERRIDE;
- virtual PP_Bool GetTransferBuffer(int32_t id,
- int* shm_handle,
- uint32_t* shm_size) OVERRIDE;
virtual gpu::CommandBuffer::State WaitForTokenInRange(int32_t start,
int32_t end) OVERRIDE;
virtual gpu::CommandBuffer::State WaitForGetOffsetInRange(int32_t start,
@@ -96,14 +94,13 @@ class PPB_Graphics3D_Proxy : public InterfaceProxy {
gpu::CommandBuffer::State* state,
bool* success);
void OnMsgAsyncFlush(const HostResource& context, int32 put_offset);
- void OnMsgCreateTransferBuffer(const HostResource& context,
- uint32 size,
- int32* id);
+ void OnMsgCreateTransferBuffer(
+ const HostResource& context,
+ uint32 size,
+ int32* id,
+ ppapi::proxy::SerializedHandle* transfer_buffer);
void OnMsgDestroyTransferBuffer(const HostResource& context,
int32 id);
- void OnMsgGetTransferBuffer(const HostResource& context,
- int32 id,
- ppapi::proxy::SerializedHandle* transfer_buffer);
void OnMsgSwapBuffers(const HostResource& context);
void OnMsgInsertSyncPoint(const HostResource& context, uint32* sync_point);
// Renderer->plugin message handlers.
diff --git a/ppapi/thunk/ppb_graphics_3d_api.h b/ppapi/thunk/ppb_graphics_3d_api.h
index a88b4ab..92e392e 100644
--- a/ppapi/thunk/ppb_graphics_3d_api.h
+++ b/ppapi/thunk/ppb_graphics_3d_api.h
@@ -32,11 +32,9 @@ class PPAPI_THUNK_EXPORT PPB_Graphics3D_API {
// Graphics3DTrusted API.
virtual PP_Bool SetGetBuffer(int32_t shm_id) = 0;
virtual gpu::CommandBuffer::State GetState() = 0;
- virtual int32_t CreateTransferBuffer(uint32_t size) = 0;
+ virtual scoped_refptr<gpu::Buffer> CreateTransferBuffer(uint32_t size,
+ int32_t* id) = 0;
virtual PP_Bool DestroyTransferBuffer(int32_t id) = 0;
- virtual PP_Bool GetTransferBuffer(int32_t id,
- int* shm_handle,
- uint32_t* shm_size) = 0;
virtual PP_Bool Flush(int32_t put_offset) = 0;
virtual gpu::CommandBuffer::State WaitForTokenInRange(int32_t start,
int32_t end) = 0;