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

Side by Side Diff: mojo/gles2/command_buffer_client_impl.cc

Issue 380123002: Mojo: Eliminate SyncDispatcher in favor of WaitForIncomingMethodCall (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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
« no previous file with comments | « mojo/gles2/command_buffer_client_impl.h ('k') | mojo/mojo_public.gypi » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "mojo/gles2/command_buffer_client_impl.h" 5 #include "mojo/gles2/command_buffer_client_impl.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/process/process_handle.h" 10 #include "base/process/process_handle.h"
11 #include "mojo/public/cpp/bindings/sync_dispatcher.h"
12 #include "mojo/services/gles2/command_buffer_type_conversions.h" 11 #include "mojo/services/gles2/command_buffer_type_conversions.h"
13 #include "mojo/services/gles2/mojo_buffer_backing.h" 12 #include "mojo/services/gles2/mojo_buffer_backing.h"
14 13
15 namespace mojo { 14 namespace mojo {
16 namespace gles2 { 15 namespace gles2 {
17 16
18 namespace { 17 namespace {
19 18
20 bool CreateMapAndDupSharedBuffer(size_t size, 19 bool CreateMapAndDupSharedBuffer(size_t size,
21 void** memory, 20 void** memory,
(...skipping 10 matching lines...) Expand all
32 DCHECK(duped->is_valid()); 31 DCHECK(duped->is_valid());
33 32
34 result = mojo::MapBuffer( 33 result = mojo::MapBuffer(
35 handle->get(), 0, size, memory, MOJO_MAP_BUFFER_FLAG_NONE); 34 handle->get(), 0, size, memory, MOJO_MAP_BUFFER_FLAG_NONE);
36 if (result != MOJO_RESULT_OK) 35 if (result != MOJO_RESULT_OK)
37 return false; 36 return false;
38 DCHECK(*memory); 37 DCHECK(*memory);
39 38
40 return true; 39 return true;
41 } 40 }
42 } 41
42 } // namespace
43 43
44 CommandBufferDelegate::~CommandBufferDelegate() {} 44 CommandBufferDelegate::~CommandBufferDelegate() {}
45 45
46 void CommandBufferDelegate::ContextLost() {} 46 void CommandBufferDelegate::ContextLost() {}
47 void CommandBufferDelegate::DrawAnimationFrame() {} 47 void CommandBufferDelegate::DrawAnimationFrame() {}
48 48
49 class CommandBufferClientImpl::SyncClientImpl
50 : public InterfaceImpl<CommandBufferSyncClient> {
51 public:
52 SyncClientImpl() : initialized_successfully_(false) {}
53
54 bool WaitForInitialization() {
55 if (!WaitForIncomingMethodCall())
56 return false;
57 return initialized_successfully_;
58 }
59
60 CommandBufferStatePtr WaitForProgress() {
61 if (!WaitForIncomingMethodCall())
62 return CommandBufferStatePtr();
63 return command_buffer_state_.Pass();
64 }
65
66 private:
67 // CommandBufferSyncClient methods:
68 virtual void DidInitialize(bool success) OVERRIDE {
69 initialized_successfully_ = success;
70 }
71 virtual void DidMakeProgress(CommandBufferStatePtr state) OVERRIDE {
72 command_buffer_state_ = state.Pass();
73 }
74
75 bool initialized_successfully_;
76 CommandBufferStatePtr command_buffer_state_;
77 };
78
49 CommandBufferClientImpl::CommandBufferClientImpl( 79 CommandBufferClientImpl::CommandBufferClientImpl(
50 CommandBufferDelegate* delegate, 80 CommandBufferDelegate* delegate,
51 const MojoAsyncWaiter* async_waiter, 81 const MojoAsyncWaiter* async_waiter,
52 ScopedMessagePipeHandle command_buffer_handle) 82 ScopedMessagePipeHandle command_buffer_handle)
53 : delegate_(delegate), 83 : delegate_(delegate),
54 shared_state_(NULL), 84 shared_state_(NULL),
55 last_put_offset_(-1), 85 last_put_offset_(-1),
56 next_transfer_buffer_id_(0), 86 next_transfer_buffer_id_(0),
57 initialize_result_(false),
58 async_waiter_(async_waiter) { 87 async_waiter_(async_waiter) {
59 command_buffer_.Bind(command_buffer_handle.Pass(), async_waiter); 88 command_buffer_.Bind(command_buffer_handle.Pass(), async_waiter);
60 command_buffer_.set_error_handler(this); 89 command_buffer_.set_error_handler(this);
61 command_buffer_.set_client(this); 90 command_buffer_.set_client(this);
62 } 91 }
63 92
64 CommandBufferClientImpl::~CommandBufferClientImpl() {} 93 CommandBufferClientImpl::~CommandBufferClientImpl() {}
65 94
66 bool CommandBufferClientImpl::Initialize() { 95 bool CommandBufferClientImpl::Initialize() {
67 const size_t kSharedStateSize = sizeof(gpu::CommandBufferSharedState); 96 const size_t kSharedStateSize = sizeof(gpu::CommandBufferSharedState);
68 void* memory = NULL; 97 void* memory = NULL;
69 mojo::ScopedSharedBufferHandle duped; 98 mojo::ScopedSharedBufferHandle duped;
70 bool result = CreateMapAndDupSharedBuffer( 99 bool result = CreateMapAndDupSharedBuffer(
71 kSharedStateSize, &memory, &shared_state_handle_, &duped); 100 kSharedStateSize, &memory, &shared_state_handle_, &duped);
72 if (!result) 101 if (!result)
73 return false; 102 return false;
74 103
75 shared_state_ = static_cast<gpu::CommandBufferSharedState*>(memory); 104 shared_state_ = static_cast<gpu::CommandBufferSharedState*>(memory);
76 105
77 shared_state()->Initialize(); 106 shared_state()->Initialize();
78 107
79 // TODO(darin): We need better sugar for sync calls. 108 // TODO(darin): We need better sugar for sync calls.
jamesr 2014/07/10 05:50:37 comment still apply?
darin (slow to review) 2014/07/10 06:02:08 Whoops, no.. I can delete that now I think :)
80 MessagePipe sync_pipe; 109 CommandBufferSyncClientPtr sync_client;
81 sync_dispatcher_.reset(new SyncDispatcher<CommandBufferSyncClient>( 110 sync_client_impl_.reset(
82 sync_pipe.handle0.Pass(), this)); 111 BindToProxy(new SyncClientImpl(), &sync_client, async_waiter_));
83 CommandBufferSyncClientPtr sync_client = 112
84 MakeProxy<CommandBufferSyncClient>(sync_pipe.handle1.Pass(),
85 async_waiter_);
86 command_buffer_->Initialize(sync_client.Pass(), duped.Pass()); 113 command_buffer_->Initialize(sync_client.Pass(), duped.Pass());
114
87 // Wait for DidInitialize to come on the sync client pipe. 115 // Wait for DidInitialize to come on the sync client pipe.
88 if (!sync_dispatcher_->WaitAndDispatchOneMessage()) { 116 if (!sync_client_impl_->WaitForInitialization()) {
89 VLOG(1) << "Channel encountered error while creating command buffer"; 117 VLOG(1) << "Channel encountered error while creating command buffer";
90 return false; 118 return false;
91 } 119 }
92 return initialize_result_; 120 return true;
93 } 121 }
94 122
95 gpu::CommandBuffer::State CommandBufferClientImpl::GetLastState() { 123 gpu::CommandBuffer::State CommandBufferClientImpl::GetLastState() {
96 return last_state_; 124 return last_state_;
97 } 125 }
98 126
99 int32 CommandBufferClientImpl::GetLastToken() { 127 int32 CommandBufferClientImpl::GetLastToken() {
100 TryUpdateState(); 128 TryUpdateState();
101 return last_state_.token; 129 return last_state_.token;
102 } 130 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 } 254 }
227 255
228 void CommandBufferClientImpl::RequestAnimationFrames() { 256 void CommandBufferClientImpl::RequestAnimationFrames() {
229 command_buffer_->RequestAnimationFrames(); 257 command_buffer_->RequestAnimationFrames();
230 } 258 }
231 259
232 void CommandBufferClientImpl::CancelAnimationFrames() { 260 void CommandBufferClientImpl::CancelAnimationFrames() {
233 command_buffer_->CancelAnimationFrames(); 261 command_buffer_->CancelAnimationFrames();
234 } 262 }
235 263
236 void CommandBufferClientImpl::DidInitialize(bool success) {
237 initialize_result_ = success;
238 }
239
240 void CommandBufferClientImpl::DidMakeProgress(CommandBufferStatePtr state) {
241 if (state->generation - last_state_.generation < 0x80000000U)
242 last_state_ = state.To<State>();
243 }
244
245 void CommandBufferClientImpl::DidDestroy() { 264 void CommandBufferClientImpl::DidDestroy() {
246 LostContext(gpu::error::kUnknown); 265 LostContext(gpu::error::kUnknown);
247 } 266 }
248 267
249 void CommandBufferClientImpl::LostContext(int32_t lost_reason) { 268 void CommandBufferClientImpl::LostContext(int32_t lost_reason) {
250 last_state_.error = gpu::error::kLostContext; 269 last_state_.error = gpu::error::kLostContext;
251 last_state_.context_lost_reason = 270 last_state_.context_lost_reason =
252 static_cast<gpu::error::ContextLostReason>(lost_reason); 271 static_cast<gpu::error::ContextLostReason>(lost_reason);
253 delegate_->ContextLost(); 272 delegate_->ContextLost();
254 } 273 }
255 274
275 void CommandBufferClientImpl::DrawAnimationFrame() {
276 delegate_->DrawAnimationFrame();
277 }
278
256 void CommandBufferClientImpl::OnConnectionError() { 279 void CommandBufferClientImpl::OnConnectionError() {
257 LostContext(gpu::error::kUnknown); 280 LostContext(gpu::error::kUnknown);
258 } 281 }
259 282
260 void CommandBufferClientImpl::TryUpdateState() { 283 void CommandBufferClientImpl::TryUpdateState() {
261 if (last_state_.error == gpu::error::kNoError) 284 if (last_state_.error == gpu::error::kNoError)
262 shared_state()->Read(&last_state_); 285 shared_state()->Read(&last_state_);
263 } 286 }
264 287
265 void CommandBufferClientImpl::MakeProgressAndUpdateState() { 288 void CommandBufferClientImpl::MakeProgressAndUpdateState() {
266 command_buffer_->MakeProgress(last_state_.get_offset); 289 command_buffer_->MakeProgress(last_state_.get_offset);
267 if (!sync_dispatcher_->WaitAndDispatchOneMessage()) { 290
291 CommandBufferStatePtr state = sync_client_impl_->WaitForProgress();
292 if (!state.get()) {
268 VLOG(1) << "Channel encountered error while waiting for command buffer"; 293 VLOG(1) << "Channel encountered error while waiting for command buffer";
269 // TODO(piman): is it ok for this to re-enter? 294 // TODO(piman): is it ok for this to re-enter?
270 DidDestroy(); 295 DidDestroy();
271 return; 296 return;
272 } 297 }
273 }
274 298
275 void CommandBufferClientImpl::DrawAnimationFrame() { 299 if (state->generation - last_state_.generation < 0x80000000U)
276 delegate_->DrawAnimationFrame(); 300 last_state_ = state.To<State>();
277 } 301 }
278 302
279 } // namespace gles2 303 } // namespace gles2
280 } // namespace mojo 304 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/gles2/command_buffer_client_impl.h ('k') | mojo/mojo_public.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698