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