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

Side by Side Diff: content/common/gpu/client/command_buffer_proxy.cc

Issue 9380037: Use shared memory to update the renderer's view of the command buffer state. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minor unit test change Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/common/gpu/client/command_buffer_proxy.h" 5 #include "content/common/gpu/client/command_buffer_proxy.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/process_util.h" 10 #include "base/process_util.h"
11 #include "base/shared_memory.h" 11 #include "base/shared_memory.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "content/common/child_process_messages.h" 13 #include "content/common/child_process_messages.h"
14 #include "content/common/child_thread.h" 14 #include "content/common/child_thread.h"
15 #include "content/common/gpu/client/gpu_channel_host.h" 15 #include "content/common/gpu/client/gpu_channel_host.h"
16 #include "content/common/gpu/gpu_messages.h" 16 #include "content/common/gpu/gpu_messages.h"
17 #include "content/common/plugin_messages.h" 17 #include "content/common/plugin_messages.h"
18 #include "content/common/view_messages.h" 18 #include "content/common/view_messages.h"
19 #include "gpu/command_buffer/common/cmd_buffer_common.h" 19 #include "gpu/command_buffer/common/cmd_buffer_common.h"
20 #include "gpu/command_buffer/common/command_buffer_shared.h"
20 #include "ui/gfx/size.h" 21 #include "ui/gfx/size.h"
21 22
22 using gpu::Buffer; 23 using gpu::Buffer;
23 24
24 CommandBufferProxy::CommandBufferProxy( 25 CommandBufferProxy::CommandBufferProxy(
25 GpuChannelHost* channel, 26 GpuChannelHost* channel,
26 int route_id) 27 int route_id)
27 : channel_(channel), 28 : channel_(channel),
28 route_id_(route_id), 29 route_id_(route_id),
29 flush_count_(0) { 30 flush_count_(0) {
30 } 31 }
31 32
32 CommandBufferProxy::~CommandBufferProxy() { 33 CommandBufferProxy::~CommandBufferProxy() {
33 // Delete all the locally cached shared memory objects, closing the handle 34 // Delete all the locally cached shared memory objects, closing the handle
34 // in this process. 35 // in this process.
35 for (TransferBufferMap::iterator it = transfer_buffers_.begin(); 36 for (TransferBufferMap::iterator it = transfer_buffers_.begin();
36 it != transfer_buffers_.end(); 37 it != transfer_buffers_.end();
37 ++it) { 38 ++it) {
38 delete it->second.shared_memory; 39 delete it->second.shared_memory;
39 it->second.shared_memory = NULL; 40 it->second.shared_memory = NULL;
40 } 41 }
41 } 42 }
42 43
43 bool CommandBufferProxy::OnMessageReceived(const IPC::Message& message) { 44 bool CommandBufferProxy::OnMessageReceived(const IPC::Message& message) {
44 bool handled = true; 45 bool handled = true;
45 IPC_BEGIN_MESSAGE_MAP(CommandBufferProxy, message) 46 IPC_BEGIN_MESSAGE_MAP(CommandBufferProxy, message)
46 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_UpdateState, OnUpdateState);
47 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Destroyed, OnDestroyed); 47 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Destroyed, OnDestroyed);
48 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_NotifyRepaint, 48 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_NotifyRepaint,
49 OnNotifyRepaint); 49 OnNotifyRepaint);
50 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_EchoAck, OnEchoAck); 50 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_EchoAck, OnEchoAck);
51 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_ConsoleMsg, OnConsoleMessage); 51 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_ConsoleMsg, OnConsoleMessage);
52 IPC_MESSAGE_UNHANDLED(handled = false) 52 IPC_MESSAGE_UNHANDLED(handled = false)
53 IPC_END_MESSAGE_MAP() 53 IPC_END_MESSAGE_MAP()
54 54
55 DCHECK(handled); 55 DCHECK(handled);
56 return handled; 56 return handled;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 if (!Send(new GpuCommandBufferMsg_Initialize(route_id_, &result))) { 104 if (!Send(new GpuCommandBufferMsg_Initialize(route_id_, &result))) {
105 LOG(ERROR) << "Could not send GpuCommandBufferMsg_Initialize."; 105 LOG(ERROR) << "Could not send GpuCommandBufferMsg_Initialize.";
106 return false; 106 return false;
107 } 107 }
108 108
109 if (!result) { 109 if (!result) {
110 LOG(ERROR) << "Failed to initialize command buffer service."; 110 LOG(ERROR) << "Failed to initialize command buffer service.";
111 return false; 111 return false;
112 } 112 }
113 113
114 int32 state_buffer = CreateTransferBuffer(sizeof *shared_state_, -1);
greggman 2012/02/11 04:17:21 Just asking but does this need to be a separate pi
115
116 if (state_buffer == -1) {
117 LOG(ERROR) << "Failed to create shared state transfer buffer.";
118 return false;
119 }
120
121 gpu::Buffer buffer = GetTransferBuffer(state_buffer);
122 if (!buffer.ptr) {
123 LOG(ERROR) << "Failed to get shared state transfer buffer";
124 return false;
125 }
126
127 shared_state_ = reinterpret_cast<gpu::CommandBufferSharedState*>(buffer.ptr);
128 shared_state_->Initialize();
129
130 if (!Send(new GpuCommandBufferMsg_SetSharedStateBuffer(route_id_,
apatrick_chromium 2012/02/13 20:50:58 Could this be sent over as another argument to Gpu
131 state_buffer))) {
132 LOG(ERROR) << "Failed to initialize shared command buffer state.";
133 return false;
134 }
135
114 return true; 136 return true;
115 } 137 }
116 138
117 gpu::CommandBuffer::State CommandBufferProxy::GetState() { 139 gpu::CommandBuffer::State CommandBufferProxy::GetState() {
118 // Send will flag state with lost context if IPC fails. 140 // Send will flag state with lost context if IPC fails.
119 if (last_state_.error == gpu::error::kNoError) { 141 if (last_state_.error == gpu::error::kNoError) {
120 gpu::CommandBuffer::State state; 142 gpu::CommandBuffer::State state;
121 if (Send(new GpuCommandBufferMsg_GetState(route_id_, &state))) 143 if (Send(new GpuCommandBufferMsg_GetState(route_id_, &state)))
122 OnUpdateState(state); 144 OnUpdateState(state);
123 } 145 }
124 146
147 TryUpdateState();
125 return last_state_; 148 return last_state_;
126 } 149 }
127 150
128 gpu::CommandBuffer::State CommandBufferProxy::GetLastState() { 151 gpu::CommandBuffer::State CommandBufferProxy::GetLastState() {
129 return last_state_; 152 return last_state_;
130 } 153 }
131 154
132 void CommandBufferProxy::Flush(int32 put_offset) { 155 void CommandBufferProxy::Flush(int32 put_offset) {
133 if (last_state_.error != gpu::error::kNoError) 156 if (last_state_.error != gpu::error::kNoError)
134 return; 157 return;
135 158
136 TRACE_EVENT1("gpu", "CommandBufferProxy::Flush", "put_offset", put_offset); 159 TRACE_EVENT1("gpu", "CommandBufferProxy::Flush", "put_offset", put_offset);
137 160
138 Send(new GpuCommandBufferMsg_AsyncFlush(route_id_, 161 Send(new GpuCommandBufferMsg_AsyncFlush(route_id_,
139 put_offset, 162 put_offset,
140 ++flush_count_)); 163 ++flush_count_));
141 } 164 }
142 165
143 gpu::CommandBuffer::State CommandBufferProxy::FlushSync(int32 put_offset, 166 gpu::CommandBuffer::State CommandBufferProxy::FlushSync(int32 put_offset,
144 int32 last_known_get) { 167 int32 last_known_get) {
145 TRACE_EVENT1("gpu", "CommandBufferProxy::FlushSync", "put_offset", 168 TRACE_EVENT1("gpu", "CommandBufferProxy::FlushSync", "put_offset",
146 put_offset); 169 put_offset);
147 Flush(put_offset); 170 Flush(put_offset);
171 TryUpdateState();
148 if (last_known_get == last_state_.get_offset) { 172 if (last_known_get == last_state_.get_offset) {
149 // Send will flag state with lost context if IPC fails. 173 // Send will flag state with lost context if IPC fails.
150 if (last_state_.error == gpu::error::kNoError) { 174 if (last_state_.error == gpu::error::kNoError) {
151 gpu::CommandBuffer::State state; 175 gpu::CommandBuffer::State state;
152 if (Send(new GpuCommandBufferMsg_GetStateFast(route_id_, 176 if (Send(new GpuCommandBufferMsg_GetStateFast(route_id_,
153 &state))) 177 &state)))
154 OnUpdateState(state); 178 OnUpdateState(state);
155 } 179 }
180 TryUpdateState();
156 } 181 }
157 182
158 return last_state_; 183 return last_state_;
159 } 184 }
160 185
161 void CommandBufferProxy::SetGetBuffer(int32 shm_id) { 186 void CommandBufferProxy::SetGetBuffer(int32 shm_id) {
162 if (last_state_.error != gpu::error::kNoError) 187 if (last_state_.error != gpu::error::kNoError)
163 return; 188 return;
164 189
165 Send(new GpuCommandBufferMsg_SetGetBuffer(route_id_, shm_id)); 190 Send(new GpuCommandBufferMsg_SetGetBuffer(route_id_, shm_id));
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 // updates in flight across which reordering occurs. 431 // updates in flight across which reordering occurs.
407 if (state.generation - last_state_.generation < 0x80000000U) 432 if (state.generation - last_state_.generation < 0x80000000U)
408 last_state_ = state; 433 last_state_ = state;
409 } 434 }
410 435
411 void CommandBufferProxy::SetOnConsoleMessageCallback( 436 void CommandBufferProxy::SetOnConsoleMessageCallback(
412 const GpuConsoleMessageCallback& callback) { 437 const GpuConsoleMessageCallback& callback) {
413 console_message_callback_ = callback; 438 console_message_callback_ = callback;
414 } 439 }
415 440
441 void CommandBufferProxy::TryUpdateState() {
442 shared_state_->Read(&last_state_);
443 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698