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

Side by Side Diff: chrome/renderer/command_buffer_proxy.cc

Issue 367002: Added Pepper 3D render context that instantiates the GPU plugin.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/command_buffer_proxy.h ('k') | chrome/renderer/render_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/logging.h" 5 #include "base/logging.h"
6 #include "base/process_util.h" 6 #include "base/process_util.h"
7 #include "chrome/common/command_buffer_messages.h" 7 #include "chrome/common/command_buffer_messages.h"
8 #include "chrome/common/plugin_messages.h" 8 #include "chrome/common/plugin_messages.h"
9 #include "chrome/renderer/command_buffer_proxy.h" 9 #include "chrome/renderer/command_buffer_proxy.h"
10 #include "chrome/renderer/plugin_channel_host.h" 10 #include "chrome/renderer/plugin_channel_host.h"
11 #include "gpu/command_buffer/common/cmd_buffer_common.h"
12
13 using gpu::Buffer;
11 14
12 CommandBufferProxy::CommandBufferProxy( 15 CommandBufferProxy::CommandBufferProxy(
13 PluginChannelHost* channel, 16 PluginChannelHost* channel,
14 int route_id) 17 int route_id)
15 : size_(0), 18 : size_(0),
16 channel_(channel), 19 channel_(channel),
17 route_id_(route_id) { 20 route_id_(route_id) {
18 } 21 }
19 22
20 CommandBufferProxy::~CommandBufferProxy() { 23 CommandBufferProxy::~CommandBufferProxy() {
24 // Delete all the locally cached shared memory objects, closing the handle
25 // in this process.
26 for (TransferBufferMap::iterator it = transfer_buffers_.begin();
27 it != transfer_buffers_.end();
28 ++it) {
29 delete it->second.shared_memory;
30 it->second.shared_memory = NULL;
31 }
21 } 32 }
22 33
23 bool CommandBufferProxy::Send(IPC::Message* msg) { 34 bool CommandBufferProxy::Send(IPC::Message* msg) {
24 if (channel_) 35 if (channel_)
25 return channel_->Send(msg); 36 return channel_->Send(msg);
26 37
27 // Callee takes ownership of message, regardless of whether Send is 38 // Callee takes ownership of message, regardless of whether Send is
28 // successful. See IPC::Message::Sender. 39 // successful. See IPC::Message::Sender.
29 delete msg; 40 delete msg;
30 return false; 41 return false;
31 } 42 }
32 43
33 base::SharedMemory* CommandBufferProxy::Initialize(int32 size) { 44 bool CommandBufferProxy::Initialize(int32 size) {
34 DCHECK(!ring_buffer_.get()); 45 DCHECK(!ring_buffer_.get());
35 46
36 // Initialize the service. Assuming we are in the renderer process, the GPU 47 // Initialize the service. Assuming we are sandboxed, the GPU
37 // process is responsible for duplicating the handle. This might not be true 48 // process is responsible for duplicating the handle. This might not be true
38 // for NaCl. 49 // for NaCl.
39 base::SharedMemoryHandle handle; 50 base::SharedMemoryHandle handle;
40 if (Send(new CommandBufferMsg_Initialize(route_id_, size, &handle)) && 51 if (Send(new CommandBufferMsg_Initialize(route_id_, size, &handle)) &&
41 base::SharedMemory::IsHandleValid(handle)) { 52 base::SharedMemory::IsHandleValid(handle)) {
42 ring_buffer_.reset(new base::SharedMemory(handle, false)); 53 ring_buffer_.reset(new base::SharedMemory(handle, false));
43 if (ring_buffer_->Map(size * sizeof(int32))) { 54 if (ring_buffer_->Map(size * sizeof(int32))) {
44 size_ = size; 55 size_ = size;
45 return ring_buffer_.get(); 56 return true;
46 } 57 }
47 58
48 ring_buffer_.reset(); 59 ring_buffer_.reset();
49 } 60 }
50 61
51 return NULL; 62 return false;
52 } 63 }
53 64
54 base::SharedMemory* CommandBufferProxy::GetRingBuffer() { 65 Buffer CommandBufferProxy::GetRingBuffer() {
55 // Return locally cached ring buffer. 66 // Return locally cached ring buffer.
56 return ring_buffer_.get(); 67 Buffer buffer;
68 buffer.ptr = ring_buffer_->memory();
69 buffer.size = size_ * sizeof(gpu::CommandBufferEntry);
70 buffer.shared_memory = ring_buffer_.get();
71 return buffer;
57 } 72 }
58 73
59 int32 CommandBufferProxy::GetSize() { 74 int32 CommandBufferProxy::GetSize() {
60 // Return locally cached size. 75 // Return locally cached size.
61 return size_; 76 return size_;
62 } 77 }
63 78
64 int32 CommandBufferProxy::SyncOffsets(int32 put_offset) { 79 int32 CommandBufferProxy::SyncOffsets(int32 put_offset) {
65 int32 get_offset; 80 int32 get_offset;
66 if (Send(new CommandBufferMsg_SyncOffsets(route_id_, 81 if (Send(new CommandBufferMsg_SyncOffsets(route_id_,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 int32 CommandBufferProxy::CreateTransferBuffer(size_t size) { 115 int32 CommandBufferProxy::CreateTransferBuffer(size_t size) {
101 int32 id; 116 int32 id;
102 if (Send(new CommandBufferMsg_CreateTransferBuffer(route_id_, size, &id))) 117 if (Send(new CommandBufferMsg_CreateTransferBuffer(route_id_, size, &id)))
103 return id; 118 return id;
104 119
105 return -1; 120 return -1;
106 } 121 }
107 122
108 void CommandBufferProxy::DestroyTransferBuffer(int32 id) { 123 void CommandBufferProxy::DestroyTransferBuffer(int32 id) {
109 // Remove the transfer buffer from the client side4 cache. 124 // Remove the transfer buffer from the client side4 cache.
110 transfer_buffers_.erase(id); 125 TransferBufferMap::iterator it = transfer_buffers_.find(id);
126 DCHECK(it != transfer_buffers_.end());
127
128 // Delete the shared memory object, closing the handle in this process.
129 delete it->second.shared_memory;
130
131 transfer_buffers_.erase(it);
111 132
112 Send(new CommandBufferMsg_DestroyTransferBuffer(route_id_, id)); 133 Send(new CommandBufferMsg_DestroyTransferBuffer(route_id_, id));
113 } 134 }
114 135
115 base::SharedMemory* CommandBufferProxy::GetTransferBuffer(int32 id) { 136 Buffer CommandBufferProxy::GetTransferBuffer(int32 id) {
116 // Check local cache to see if there is already a client side shared memory 137 // Check local cache to see if there is already a client side shared memory
117 // object for this id. 138 // object for this id.
118 TransferBufferMap::iterator it = transfer_buffers_.find(id); 139 TransferBufferMap::iterator it = transfer_buffers_.find(id);
119 if (it != transfer_buffers_.end()) 140 if (it != transfer_buffers_.end()) {
120 return it->second.get(); 141 return it->second;
142 }
121 143
122 // Assuming we are in the renderer process, the service is responsible for 144 // Assuming we are in the renderer process, the service is responsible for
123 // duplicating the handle. This might not be true for NaCl. 145 // duplicating the handle. This might not be true for NaCl.
124 base::SharedMemoryHandle handle; 146 base::SharedMemoryHandle handle;
125 if (!Send(new CommandBufferMsg_GetTransferBuffer(route_id_, id, &handle))) 147 size_t size;
126 return NULL; 148 if (!Send(new CommandBufferMsg_GetTransferBuffer(route_id_,
149 id,
150 &handle,
151 &size))) {
152 return Buffer();
153 }
127 154
128 // Cache the transfer buffer shared memory object client side. 155 // Cache the transfer buffer shared memory object client side.
129 base::SharedMemory* transfer_buffer = 156 base::SharedMemory* shared_memory =
130 new base::SharedMemory(handle, false, base::GetCurrentProcessHandle()); 157 new base::SharedMemory(handle, false, base::GetCurrentProcessHandle());
131 transfer_buffers_[id].reset(transfer_buffer);
132 158
133 return transfer_buffer; 159 // Map the shared memory on demand.
160 if (!shared_memory->memory()) {
161 if (!shared_memory->Map(shared_memory->max_size())) {
162 delete shared_memory;
163 return Buffer();
164 }
165 }
166
167 Buffer buffer;
168 buffer.ptr = shared_memory->memory();
169 buffer.size = size;
170 buffer.shared_memory = shared_memory;
171 transfer_buffers_[id] = buffer;
172
173 return buffer;
134 } 174 }
135 175
136 int32 CommandBufferProxy::GetToken() { 176 int32 CommandBufferProxy::GetToken() {
137 int32 token; 177 int32 token;
138 if (Send(new CommandBufferMsg_GetToken(route_id_, &token))) 178 if (Send(new CommandBufferMsg_GetToken(route_id_, &token)))
139 return token; 179 return token;
140 180
141 return -1; 181 return -1;
142 } 182 }
143 183
(...skipping 20 matching lines...) Expand all
164 if (Send(new CommandBufferMsg_GetErrorStatus(route_id_, &status))) 204 if (Send(new CommandBufferMsg_GetErrorStatus(route_id_, &status)))
165 return status; 205 return status;
166 206
167 return true; 207 return true;
168 } 208 }
169 209
170 void CommandBufferProxy::RaiseErrorStatus() { 210 void CommandBufferProxy::RaiseErrorStatus() {
171 // Not implemented in proxy. 211 // Not implemented in proxy.
172 NOTREACHED(); 212 NOTREACHED();
173 } 213 }
OLDNEW
« no previous file with comments | « chrome/renderer/command_buffer_proxy.h ('k') | chrome/renderer/render_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698