OLD | NEW |
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 parser. | 5 // This file contains the implementation of the command parser. |
6 | 6 |
7 #include "gpu/command_buffer/service/cmd_parser.h" | 7 #include "gpu/command_buffer/service/cmd_parser.h" |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 | 10 |
11 namespace gpu { | 11 namespace gpu { |
12 | 12 |
13 CommandParser::CommandParser(AsyncAPIInterface* handler) | 13 CommandParser::CommandParser(void *shm_address, |
14 : get_(0), | 14 size_t shm_size, |
15 put_(0), | 15 ptrdiff_t offset, |
16 buffer_(NULL), | 16 size_t size, |
17 entry_count_(0), | 17 CommandBufferOffset start_get, |
| 18 AsyncAPIInterface *handler) |
| 19 : get_(start_get), |
| 20 put_(start_get), |
18 handler_(handler) { | 21 handler_(handler) { |
19 } | |
20 | |
21 void CommandParser::SetBuffer( | |
22 void* shm_address, | |
23 size_t shm_size, | |
24 ptrdiff_t offset, | |
25 size_t size) { | |
26 // check proper alignments. | 22 // check proper alignments. |
27 DCHECK_EQ(0, (reinterpret_cast<intptr_t>(shm_address)) % 4); | 23 DCHECK_EQ(0, (reinterpret_cast<intptr_t>(shm_address)) % 4); |
28 DCHECK_EQ(0, offset % 4); | 24 DCHECK_EQ(0, offset % 4); |
29 DCHECK_EQ(0u, size % 4); | 25 DCHECK_EQ(0u, size % 4); |
30 // check that the command buffer fits into the memory buffer. | 26 // check that the command buffer fits into the memory buffer. |
31 DCHECK_GE(shm_size, offset + size); | 27 DCHECK_GE(shm_size, offset + size); |
32 get_ = 0; | 28 char * buffer_begin = static_cast<char *>(shm_address) + offset; |
33 put_ = 0; | 29 buffer_ = reinterpret_cast<CommandBufferEntry *>(buffer_begin); |
34 char* buffer_begin = static_cast<char*>(shm_address) + offset; | |
35 buffer_ = reinterpret_cast<CommandBufferEntry*>(buffer_begin); | |
36 entry_count_ = size / 4; | 30 entry_count_ = size / 4; |
37 } | 31 } |
38 | 32 |
39 // Process one command, reading the header from the command buffer, and | 33 // Process one command, reading the header from the command buffer, and |
40 // forwarding the command index and the arguments to the handler. | 34 // forwarding the command index and the arguments to the handler. |
41 // Note that: | 35 // Note that: |
42 // - validation needs to happen on a copy of the data (to avoid race | 36 // - validation needs to happen on a copy of the data (to avoid race |
43 // conditions). This function only validates the header, leaving the arguments | 37 // conditions). This function only validates the header, leaving the arguments |
44 // validation to the handler, so it can pass a reference to them. | 38 // validation to the handler, so it can pass a reference to them. |
45 // - get_ is modified *after* the command has been executed. | 39 // - get_ is modified *after* the command has been executed. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 error::Error CommandParser::ProcessAllCommands() { | 80 error::Error CommandParser::ProcessAllCommands() { |
87 while (!IsEmpty()) { | 81 while (!IsEmpty()) { |
88 error::Error error = ProcessCommand(); | 82 error::Error error = ProcessCommand(); |
89 if (error) | 83 if (error) |
90 return error; | 84 return error; |
91 } | 85 } |
92 return error::kNoError; | 86 return error::kNoError; |
93 } | 87 } |
94 | 88 |
95 } // namespace gpu | 89 } // namespace gpu |
OLD | NEW |