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

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

Issue 555129: Add commands Jump, Call and Return... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 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) 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 // 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 "gpu/command_buffer/client/cmd_buffer_helper.h" 7 #include "gpu/command_buffer/client/cmd_buffer_helper.h"
8 #include "gpu/command_buffer/common/command_buffer.h" 8 #include "gpu/command_buffer/common/command_buffer.h"
9 9
10 namespace gpu { 10 namespace gpu {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 } 55 }
56 56
57 // Inserts a new token into the command stream. It uses an increasing value 57 // Inserts a new token into the command stream. It uses an increasing value
58 // scheme so that we don't lose tokens (a token has passed if the current token 58 // scheme so that we don't lose tokens (a token has passed if the current token
59 // value is higher than that token). Calls Finish() if the token value wraps, 59 // value is higher than that token). Calls Finish() if the token value wraps,
60 // which will be rare. 60 // which will be rare.
61 int32 CommandBufferHelper::InsertToken() { 61 int32 CommandBufferHelper::InsertToken() {
62 // Increment token as 31-bit integer. Negative values are used to signal an 62 // Increment token as 31-bit integer. Negative values are used to signal an
63 // error. 63 // error.
64 token_ = (token_ + 1) & 0x7FFFFFFF; 64 token_ = (token_ + 1) & 0x7FFFFFFF;
65 CommandBufferEntry args; 65 cmd::SetToken& cmd = GetCmdSpace<cmd::SetToken>();
66 args.value_uint32 = token_; 66 cmd.Init(token_);
67 const uint32 kSetToken = 1; // TODO(gman): add a common set of commands.
68 AddCommand(kSetToken, 1, &args);
69 if (token_ == 0) { 67 if (token_ == 0) {
70 // we wrapped 68 // we wrapped
71 Finish(); 69 Finish();
72 last_token_read_ = command_buffer_->GetToken(); 70 last_token_read_ = command_buffer_->GetToken();
73 DCHECK_EQ(token_, last_token_read_); 71 DCHECK_EQ(token_, last_token_read_);
74 } 72 }
75 return token_; 73 return token_;
76 } 74 }
77 75
78 // Waits until the current token value is greater or equal to the value passed 76 // Waits until the current token value is greater or equal to the value passed
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 // but we need to make sure get wraps first, actually that get is 1 or 109 // but we need to make sure get wraps first, actually that get is 1 or
112 // more (since put will wrap to 0 after we add the noops). 110 // more (since put will wrap to 0 after we add the noops).
113 DCHECK_LE(1, put_); 111 DCHECK_LE(1, put_);
114 Flush(); 112 Flush();
115 while (get_ > put_ || get_ == 0) { 113 while (get_ > put_ || get_ == 0) {
116 // Do not loop forever if the flush fails, meaning the command buffer 114 // Do not loop forever if the flush fails, meaning the command buffer
117 // reader has shutdown. 115 // reader has shutdown.
118 if (!Flush()) 116 if (!Flush())
119 return; 117 return;
120 } 118 }
121 // Add the noops. By convention, a noop is a command 0 with no args. 119 // Insert Noops to fill out buffer.
122 // TODO(apatrick): A noop can have a size. It would be better to add a 120 int32 num_entries = entry_count_ - put_;
123 // single noop with a variable size. Watch out for size limit on 121 while (num_entries > 0) {
124 // individual commands. 122 int32 num_to_skip = std::min(CommandHeader::kMaxSize, num_entries);
125 CommandHeader header; 123 cmd::Noop::Set(&entries_[put_], num_to_skip);
126 header.size = 1; 124 put_ += num_to_skip;
127 header.command = 0; 125 num_entries -= num_to_skip;
128 while (put_ < entry_count_) {
129 entries_[put_++].value_header = header;
130 } 126 }
131 put_ = 0; 127 put_ = 0;
132 } 128 }
133 // If we have enough room, return immediatly. 129 // If we have enough room, return immediatly.
134 if (count <= AvailableEntries()) return; 130 if (count <= AvailableEntries()) return;
135 // Otherwise flush, and wait until we do have enough room. 131 // Otherwise flush, and wait until we do have enough room.
136 Flush(); 132 Flush();
137 while (AvailableEntries() < count) { 133 while (AvailableEntries() < count) {
138 // Do not loop forever if the flush fails, meaning the command buffer reader 134 // Do not loop forever if the flush fails, meaning the command buffer reader
139 // has shutdown. 135 // has shutdown.
140 if (!Flush()) 136 if (!Flush())
141 return; 137 return;
142 } 138 }
143 } 139 }
144 140
145 CommandBufferEntry* CommandBufferHelper::GetSpace(uint32 entries) { 141 CommandBufferEntry* CommandBufferHelper::GetSpace(uint32 entries) {
146 WaitForAvailableEntries(entries); 142 WaitForAvailableEntries(entries);
147 CommandBufferEntry* space = &entries_[put_]; 143 CommandBufferEntry* space = &entries_[put_];
148 put_ += entries; 144 put_ += entries;
149 return space; 145 return space;
150 } 146 }
151 147
152 parse_error::ParseError CommandBufferHelper::GetParseError() { 148 parse_error::ParseError CommandBufferHelper::GetParseError() {
153 int32 parse_error = command_buffer_->ResetParseError(); 149 int32 parse_error = command_buffer_->ResetParseError();
154 return static_cast<parse_error::ParseError>(parse_error); 150 return static_cast<parse_error::ParseError>(parse_error);
155 } 151 }
156 152
157 } // namespace gpu 153 } // 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