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

Side by Side Diff: gpu/command_buffer/service/command_buffer_service.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: fix hang when last_state_.error accidentally overwritten 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
« no previous file with comments | « gpu/command_buffer/service/command_buffer_service.h ('k') | gpu/gpu.gyp » ('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) 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 "gpu/command_buffer/service/command_buffer_service.h" 5 #include "gpu/command_buffer/service/command_buffer_service.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/process_util.h" 9 #include "base/process_util.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
11 #include "gpu/command_buffer/common/cmd_buffer_common.h" 11 #include "gpu/command_buffer/common/cmd_buffer_common.h"
12 #include "gpu/command_buffer/common/command_buffer_shared.h"
12 13
13 using ::base::SharedMemory; 14 using ::base::SharedMemory;
14 15
15 namespace gpu { 16 namespace gpu {
16 17
17 CommandBufferService::CommandBufferService() 18 CommandBufferService::CommandBufferService()
18 : ring_buffer_id_(-1), 19 : ring_buffer_id_(-1),
20 shared_state_(NULL),
19 num_entries_(0), 21 num_entries_(0),
20 get_offset_(0), 22 get_offset_(0),
21 put_offset_(0), 23 put_offset_(0),
22 token_(0), 24 token_(0),
23 generation_(0), 25 generation_(0),
24 error_(error::kNoError), 26 error_(error::kNoError),
25 context_lost_reason_(error::kUnknown), 27 context_lost_reason_(error::kUnknown),
26 shared_memory_bytes_allocated_(0) { 28 shared_memory_bytes_allocated_(0) {
27 // Element zero is always NULL. 29 // Element zero is always NULL.
28 registered_objects_.push_back(Buffer()); 30 registered_objects_.push_back(Buffer());
(...skipping 23 matching lines...) Expand all
52 state.context_lost_reason = context_lost_reason_; 54 state.context_lost_reason = context_lost_reason_;
53 state.generation = ++generation_; 55 state.generation = ++generation_;
54 56
55 return state; 57 return state;
56 } 58 }
57 59
58 CommandBufferService::State CommandBufferService::GetLastState() { 60 CommandBufferService::State CommandBufferService::GetLastState() {
59 return GetState(); 61 return GetState();
60 } 62 }
61 63
64 void CommandBufferService::UpdateState() {
65 if (shared_state_) {
66 CommandBufferService::State state = GetState();
67 shared_state_->Write(state);
68 }
69 }
70
62 CommandBufferService::State CommandBufferService::FlushSync( 71 CommandBufferService::State CommandBufferService::FlushSync(
63 int32 put_offset, int32 last_known_get) { 72 int32 put_offset, int32 last_known_get) {
64 if (put_offset < 0 || put_offset > num_entries_) { 73 if (put_offset < 0 || put_offset > num_entries_) {
65 error_ = gpu::error::kOutOfBounds; 74 error_ = gpu::error::kOutOfBounds;
66 return GetState(); 75 return GetState();
67 } 76 }
68 77
69 put_offset_ = put_offset; 78 put_offset_ = put_offset;
70 79
71 if (!put_offset_change_callback_.is_null()) 80 if (!put_offset_change_callback_.is_null())
(...skipping 19 matching lines...) Expand all
91 DCHECK_EQ(put_offset_, get_offset_); // Only if it's empty. 100 DCHECK_EQ(put_offset_, get_offset_); // Only if it's empty.
92 ring_buffer_ = GetTransferBuffer(transfer_buffer_id); 101 ring_buffer_ = GetTransferBuffer(transfer_buffer_id);
93 DCHECK(ring_buffer_.ptr); 102 DCHECK(ring_buffer_.ptr);
94 ring_buffer_id_ = transfer_buffer_id; 103 ring_buffer_id_ = transfer_buffer_id;
95 num_entries_ = ring_buffer_.size / sizeof(CommandBufferEntry); 104 num_entries_ = ring_buffer_.size / sizeof(CommandBufferEntry);
96 put_offset_ = 0; 105 put_offset_ = 0;
97 SetGetOffset(0); 106 SetGetOffset(0);
98 if (!get_buffer_change_callback_.is_null()) { 107 if (!get_buffer_change_callback_.is_null()) {
99 get_buffer_change_callback_.Run(ring_buffer_id_); 108 get_buffer_change_callback_.Run(ring_buffer_id_);
100 } 109 }
110
111 UpdateState();
112 }
113
114 void CommandBufferService::SetSharedStateBuffer(int32 transfer_buffer_id) {
115 gpu::Buffer buffer = GetTransferBuffer(transfer_buffer_id);
116 shared_state_ = reinterpret_cast<CommandBufferSharedState*>(buffer.ptr);
117
118 UpdateState();
101 } 119 }
102 120
103 void CommandBufferService::SetGetOffset(int32 get_offset) { 121 void CommandBufferService::SetGetOffset(int32 get_offset) {
104 DCHECK(get_offset >= 0 && get_offset < num_entries_); 122 DCHECK(get_offset >= 0 && get_offset < num_entries_);
105 get_offset_ = get_offset; 123 get_offset_ = get_offset;
106 } 124 }
107 125
108 int32 CommandBufferService::CreateTransferBuffer(size_t size, 126 int32 CommandBufferService::CreateTransferBuffer(size_t size,
109 int32 id_request) { 127 int32 id_request) {
110 SharedMemory buffer; 128 SharedMemory buffer;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 const GetBufferChangedCallback& callback) { 270 const GetBufferChangedCallback& callback) {
253 get_buffer_change_callback_ = callback; 271 get_buffer_change_callback_ = callback;
254 } 272 }
255 273
256 void CommandBufferService::SetParseErrorCallback( 274 void CommandBufferService::SetParseErrorCallback(
257 const base::Closure& callback) { 275 const base::Closure& callback) {
258 parse_error_callback_ = callback; 276 parse_error_callback_ = callback;
259 } 277 }
260 278
261 } // namespace gpu 279 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/command_buffer_service.h ('k') | gpu/gpu.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698