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