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

Side by Side Diff: gpu/command_buffer/client/cmd_buffer_helper.cc

Issue 8919014: Revert "Revert 113479 - Revert "Revert 113250 - Add CommandBuffer::SetGetBuffer"" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // This file contains the implementation of the command buffer helper class. 5 // This file contains the implementation of the command buffer helper class.
6 6
7 #include "../client/cmd_buffer_helper.h" 7 #include "../client/cmd_buffer_helper.h"
8 #include "../common/command_buffer.h" 8 #include "../common/command_buffer.h"
9 #include "../common/trace_event.h" 9 #include "../common/trace_event.h"
10 10
11 namespace gpu { 11 namespace gpu {
12 12
13 namespace { 13 namespace {
14 const int kCommandsPerFlushCheck = 100; 14 const int kCommandsPerFlushCheck = 100;
15 const double kFlushDelay = 1.0 / (5.0 * 60.0); 15 const double kFlushDelay = 1.0 / (5.0 * 60.0);
16 } 16 }
17 17
18 CommandBufferHelper::CommandBufferHelper(CommandBuffer* command_buffer) 18 CommandBufferHelper::CommandBufferHelper(CommandBuffer* command_buffer)
19 : command_buffer_(command_buffer), 19 : command_buffer_(command_buffer),
20 ring_buffer_id_(-1),
21 ring_buffer_size_(0),
20 entries_(NULL), 22 entries_(NULL),
21 total_entry_count_(0), 23 total_entry_count_(0),
22 usable_entry_count_(0), 24 usable_entry_count_(0),
23 token_(0), 25 token_(0),
24 put_(0), 26 put_(0),
25 last_put_sent_(0), 27 last_put_sent_(0),
26 commands_issued_(0), 28 commands_issued_(0),
27 last_flush_time_(0) { 29 last_flush_time_(0) {
28 } 30 }
29 31
30 bool CommandBufferHelper::Initialize(int32 ring_buffer_size) { 32 bool CommandBufferHelper::AllocateRingBuffer() {
31 ring_buffer_ = command_buffer_->GetRingBuffer(); 33 int32 id = command_buffer_->CreateTransferBuffer(ring_buffer_size_, -1);
34 if (id < 0) {
35 return false;
36 }
37
38 ring_buffer_ = command_buffer_->GetTransferBuffer(id);
32 if (!ring_buffer_.ptr) 39 if (!ring_buffer_.ptr)
33 return false; 40 return false;
34 41
42 ring_buffer_id_ = id;
43 command_buffer_->SetGetBuffer(id);
44
45 // TODO(gman): Do we really need to call GetState here? We know get & put = 0
46 // Also do we need to check state.num_entries?
35 CommandBuffer::State state = command_buffer_->GetState(); 47 CommandBuffer::State state = command_buffer_->GetState();
36 entries_ = static_cast<CommandBufferEntry*>(ring_buffer_.ptr); 48 entries_ = static_cast<CommandBufferEntry*>(ring_buffer_.ptr);
37 int32 num_ring_buffer_entries = ring_buffer_size / sizeof(CommandBufferEntry); 49 int32 num_ring_buffer_entries =
50 ring_buffer_size_ / sizeof(CommandBufferEntry);
38 if (num_ring_buffer_entries > state.num_entries) { 51 if (num_ring_buffer_entries > state.num_entries) {
39 return false; 52 return false;
40 } 53 }
41 54
42 const int32 kJumpEntries = 55 const int32 kJumpEntries =
43 sizeof(cmd::Jump) / sizeof(*entries_); // NOLINT 56 sizeof(cmd::Jump) / sizeof(*entries_); // NOLINT
44 57
45 total_entry_count_ = num_ring_buffer_entries; 58 total_entry_count_ = num_ring_buffer_entries;
46 usable_entry_count_ = total_entry_count_ - kJumpEntries; 59 usable_entry_count_ = total_entry_count_ - kJumpEntries;
47 put_ = state.put_offset; 60 put_ = state.put_offset;
48 return true; 61 return true;
49 } 62 }
50 63
64 bool CommandBufferHelper::Initialize(int32 ring_buffer_size) {
65 ring_buffer_size_ = ring_buffer_size;
66 return AllocateRingBuffer();
67 }
68
51 CommandBufferHelper::~CommandBufferHelper() { 69 CommandBufferHelper::~CommandBufferHelper() {
52 } 70 }
53 71
54 bool CommandBufferHelper::FlushSync() { 72 bool CommandBufferHelper::FlushSync() {
55 last_flush_time_ = clock(); 73 last_flush_time_ = clock();
56 last_put_sent_ = put_; 74 last_put_sent_ = put_;
57 CommandBuffer::State state = command_buffer_->FlushSync(put_, get_offset()); 75 CommandBuffer::State state = command_buffer_->FlushSync(put_, get_offset());
58 return state.error == error::kNoError; 76 return state.error == error::kNoError;
59 } 77 }
60 78
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 } 199 }
182 return space; 200 return space;
183 } 201 }
184 202
185 error::Error CommandBufferHelper::GetError() { 203 error::Error CommandBufferHelper::GetError() {
186 CommandBuffer::State state = command_buffer_->GetState(); 204 CommandBuffer::State state = command_buffer_->GetState();
187 return static_cast<error::Error>(state.error); 205 return static_cast<error::Error>(state.error);
188 } 206 }
189 207
190 } // namespace gpu 208 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/cmd_buffer_helper.h ('k') | gpu/command_buffer/client/cmd_buffer_helper_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698