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(CommandBuffer* command_buffer) | |
13 : command_buffer_(command_buffer), | |
14 commands_per_update_(100) { | |
15 DCHECK(command_buffer); | |
16 decoder_.reset(gles2::GLES2Decoder::Create()); | |
17 decoder_->set_engine(this); | |
18 } | |
19 | |
20 GPUProcessor::GPUProcessor(CommandBuffer* command_buffer, | |
21 gles2::GLES2Decoder* decoder, | |
22 CommandParser* parser, | |
23 int commands_per_update) | |
24 : command_buffer_(command_buffer), | |
25 commands_per_update_(commands_per_update) { | |
26 DCHECK(command_buffer); | |
27 decoder_.reset(decoder); | |
28 parser_.reset(parser); | |
29 } | |
30 | |
31 GPUProcessor::~GPUProcessor() { | 12 GPUProcessor::~GPUProcessor() { |
32 } | 13 } |
33 | 14 |
34 void GPUProcessor::ProcessCommands() { | 15 void GPUProcessor::ProcessCommands() { |
35 if (command_buffer_->GetErrorStatus()) | 16 if (command_buffer_->GetErrorStatus()) |
36 return; | 17 return; |
37 | 18 |
38 parser_->set_put(command_buffer_->GetPutOffset()); | 19 parser_->set_put(command_buffer_->GetPutOffset()); |
39 | 20 |
40 int commands_processed = 0; | 21 int commands_processed = 0; |
41 while (commands_processed < commands_per_update_ && !parser_->IsEmpty()) { | 22 while (commands_processed < commands_per_update_ && !parser_->IsEmpty()) { |
42 parse_error::ParseError parse_error = parser_->ProcessCommand(); | 23 parse_error::ParseError parse_error = parser_->ProcessCommand(); |
43 switch (parse_error) { | 24 switch (parse_error) { |
44 case parse_error::kParseUnknownCommand: | 25 case parse_error::kParseUnknownCommand: |
45 case parse_error::kParseInvalidArguments: | 26 case parse_error::kParseInvalidArguments: |
46 command_buffer_->SetParseError(parse_error); | 27 command_buffer_->SetParseError(parse_error); |
47 break; | 28 break; |
48 | 29 |
49 case parse_error::kParseInvalidSize: | 30 case parse_error::kParseInvalidSize: |
50 case parse_error::kParseOutOfBounds: | 31 case parse_error::kParseOutOfBounds: |
51 command_buffer_->SetParseError(parse_error); | 32 command_buffer_->SetParseError(parse_error); |
52 command_buffer_->RaiseErrorStatus(); | 33 command_buffer_->RaiseErrorStatus(); |
53 return; | 34 return; |
54 case gpu::parse_error::kParseNoError: | |
55 break; | |
56 } | 35 } |
57 | 36 |
58 ++commands_processed; | 37 ++commands_processed; |
59 } | 38 } |
60 | 39 |
61 command_buffer_->SetGetOffset(static_cast<int32>(parser_->get())); | 40 command_buffer_->SetGetOffset(static_cast<int32>(parser_->get())); |
62 | 41 |
63 if (!parser_->IsEmpty()) { | 42 if (!parser_->IsEmpty()) { |
64 MessageLoop::current()->PostTask( | 43 MessageLoop::current()->PostTask( |
65 FROM_HERE, NewRunnableMethod(this, &GPUProcessor::ProcessCommands)); | 44 FROM_HERE, NewRunnableMethod(this, &GPUProcessor::ProcessCommands)); |
66 } | 45 } |
67 } | 46 } |
68 | 47 |
69 Buffer GPUProcessor::GetSharedMemoryBuffer(int32 shm_id) { | 48 Buffer GPUProcessor::GetSharedMemoryBuffer(int32 shm_id) { |
70 return command_buffer_->GetTransferBuffer(shm_id); | 49 return command_buffer_->GetTransferBuffer(shm_id); |
71 } | 50 } |
72 | 51 |
73 void GPUProcessor::set_token(int32 token) { | 52 void GPUProcessor::set_token(int32 token) { |
74 command_buffer_->SetToken(token); | 53 command_buffer_->SetToken(token); |
75 } | 54 } |
76 | 55 |
77 } // namespace gpu | 56 } // namespace gpu |
OLD | NEW |