OLD | NEW |
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 #include "base/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "gpu/command_buffer/service/gpu_processor.h" | 6 #include "gpu/command_buffer/service/gpu_processor.h" |
7 | 7 |
8 using ::base::SharedMemory; | 8 using ::base::SharedMemory; |
9 | 9 |
10 namespace gpu { | 10 namespace gpu { |
11 | 11 |
12 GPUProcessor::~GPUProcessor() { | 12 GPUProcessor::~GPUProcessor() { |
13 } | 13 } |
14 | 14 |
15 void GPUProcessor::ProcessCommands() { | 15 void GPUProcessor::ProcessCommands() { |
16 if (command_buffer_->GetErrorStatus()) | 16 if (command_buffer_->GetErrorStatus()) |
17 return; | 17 return; |
18 | 18 |
19 parser_->set_put(command_buffer_->GetPutOffset()); | 19 parser_->set_put(command_buffer_->GetPutOffset()); |
20 | 20 |
21 int commands_processed = 0; | 21 int commands_processed = 0; |
22 while (commands_processed < commands_per_update_ && !parser_->IsEmpty()) { | 22 while (commands_processed < commands_per_update_ && !parser_->IsEmpty()) { |
23 gpu::parse_error::ParseError parse_error = | 23 parse_error::ParseError parse_error = parser_->ProcessCommand(); |
24 parser_->ProcessCommand(); | |
25 switch (parse_error) { | 24 switch (parse_error) { |
26 case gpu::parse_error::kParseUnknownCommand: | 25 case parse_error::kParseUnknownCommand: |
27 case gpu::parse_error::kParseInvalidArguments: | 26 case parse_error::kParseInvalidArguments: |
28 command_buffer_->SetParseError(parse_error); | 27 command_buffer_->SetParseError(parse_error); |
29 break; | 28 break; |
30 | 29 |
31 case gpu::parse_error::kParseInvalidSize: | 30 case parse_error::kParseInvalidSize: |
32 case gpu::parse_error::kParseOutOfBounds: | 31 case parse_error::kParseOutOfBounds: |
33 command_buffer_->SetParseError(parse_error); | 32 command_buffer_->SetParseError(parse_error); |
34 command_buffer_->RaiseErrorStatus(); | 33 command_buffer_->RaiseErrorStatus(); |
35 return; | 34 return; |
36 } | 35 } |
37 | 36 |
38 ++commands_processed; | 37 ++commands_processed; |
39 } | 38 } |
40 | 39 |
41 command_buffer_->SetGetOffset(static_cast<int32>(parser_->get())); | 40 command_buffer_->SetGetOffset(static_cast<int32>(parser_->get())); |
42 | 41 |
43 if (!parser_->IsEmpty()) { | 42 if (!parser_->IsEmpty()) { |
44 MessageLoop::current()->PostTask( | 43 MessageLoop::current()->PostTask( |
45 FROM_HERE, NewRunnableMethod(this, &GPUProcessor::ProcessCommands)); | 44 FROM_HERE, NewRunnableMethod(this, &GPUProcessor::ProcessCommands)); |
46 } | 45 } |
47 } | 46 } |
48 | 47 |
49 void *GPUProcessor::GetSharedMemoryAddress(int32 shm_id) { | 48 Buffer GPUProcessor::GetSharedMemoryBuffer(int32 shm_id) { |
50 ::base::SharedMemory* shared_memory = | 49 return command_buffer_->GetTransferBuffer(shm_id); |
51 command_buffer_->GetTransferBuffer(shm_id); | |
52 if (!shared_memory) | |
53 return NULL; | |
54 | |
55 if (!shared_memory->memory()) { | |
56 if (!shared_memory->Map(shared_memory->max_size())) | |
57 return NULL; | |
58 } | |
59 | |
60 return shared_memory->memory(); | |
61 } | |
62 | |
63 // TODO(apatrick): Consolidate this with the above and return both the address | |
64 // and size. | |
65 size_t GPUProcessor::GetSharedMemorySize(int32 shm_id) { | |
66 ::base::SharedMemory* shared_memory = | |
67 command_buffer_->GetTransferBuffer(shm_id); | |
68 if (!shared_memory) | |
69 return 0; | |
70 | |
71 return shared_memory->max_size(); | |
72 } | 50 } |
73 | 51 |
74 void GPUProcessor::set_token(int32 token) { | 52 void GPUProcessor::set_token(int32 token) { |
75 command_buffer_->SetToken(token); | 53 command_buffer_->SetToken(token); |
76 } | 54 } |
77 | 55 |
78 } // namespace gpu | 56 } // namespace gpu |
OLD | NEW |