| 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/callback.h" | 5 #include "base/callback.h" |
| 6 #include "base/compiler_specific.h" |
| 6 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 7 #include "gpu/command_buffer/service/gpu_processor.h" | 8 #include "gpu/command_buffer/service/gpu_processor.h" |
| 8 | 9 |
| 9 using ::base::SharedMemory; | 10 using ::base::SharedMemory; |
| 10 | 11 |
| 11 namespace gpu { | 12 namespace gpu { |
| 12 | 13 |
| 13 GPUProcessor::GPUProcessor(CommandBuffer* command_buffer) | 14 GPUProcessor::GPUProcessor(CommandBuffer* command_buffer) |
| 14 : command_buffer_(command_buffer), | 15 : command_buffer_(command_buffer), |
| 15 commands_per_update_(100) { | 16 commands_per_update_(100), |
| 17 method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 16 DCHECK(command_buffer); | 18 DCHECK(command_buffer); |
| 17 decoder_.reset(gles2::GLES2Decoder::Create(&group_)); | 19 decoder_.reset(gles2::GLES2Decoder::Create(&group_)); |
| 18 decoder_->set_engine(this); | 20 decoder_->set_engine(this); |
| 19 } | 21 } |
| 20 | 22 |
| 21 GPUProcessor::GPUProcessor(CommandBuffer* command_buffer, | 23 GPUProcessor::GPUProcessor(CommandBuffer* command_buffer, |
| 22 gles2::GLES2Decoder* decoder, | 24 gles2::GLES2Decoder* decoder, |
| 23 CommandParser* parser, | 25 CommandParser* parser, |
| 24 int commands_per_update) | 26 int commands_per_update) |
| 25 : command_buffer_(command_buffer), | 27 : command_buffer_(command_buffer), |
| 26 commands_per_update_(commands_per_update) { | 28 commands_per_update_(commands_per_update), |
| 29 method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 27 DCHECK(command_buffer); | 30 DCHECK(command_buffer); |
| 28 decoder_.reset(decoder); | 31 decoder_.reset(decoder); |
| 29 parser_.reset(parser); | 32 parser_.reset(parser); |
| 30 } | 33 } |
| 31 | 34 |
| 32 GPUProcessor::~GPUProcessor() { | 35 GPUProcessor::~GPUProcessor() { |
| 36 Destroy(); |
| 33 } | 37 } |
| 34 | 38 |
| 35 void GPUProcessor::ProcessCommands() { | 39 void GPUProcessor::ProcessCommands() { |
| 36 CommandBuffer::State state = command_buffer_->GetState(); | 40 CommandBuffer::State state = command_buffer_->GetState(); |
| 37 if (state.error != error::kNoError) | 41 if (state.error != error::kNoError) |
| 38 return; | 42 return; |
| 39 | 43 |
| 40 if (decoder_.get()) { | 44 if (decoder_.get()) { |
| 41 // TODO(apatrick): need to do more than this on failure. | 45 // TODO(apatrick): need to do more than this on failure. |
| 42 if (!decoder_->MakeCurrent()) | 46 if (!decoder_->MakeCurrent()) |
| 43 return; | 47 return; |
| 44 } | 48 } |
| 45 | 49 |
| 46 parser_->set_put(state.put_offset); | 50 parser_->set_put(state.put_offset); |
| 47 | 51 |
| 48 int commands_processed = 0; | 52 int commands_processed = 0; |
| 49 while (commands_processed < commands_per_update_ && !parser_->IsEmpty()) { | 53 while (commands_processed < commands_per_update_ && !parser_->IsEmpty()) { |
| 50 error::Error error = parser_->ProcessCommand(); | 54 error::Error error = parser_->ProcessCommand(); |
| 51 if (error != error::kNoError) { | 55 if (error != error::kNoError) { |
| 52 command_buffer_->SetParseError(error); | 56 command_buffer_->SetParseError(error); |
| 53 return; | 57 return; |
| 54 } | 58 } |
| 55 ++commands_processed; | 59 ++commands_processed; |
| 56 } | 60 } |
| 57 | 61 |
| 58 command_buffer_->SetGetOffset(static_cast<int32>(parser_->get())); | 62 command_buffer_->SetGetOffset(static_cast<int32>(parser_->get())); |
| 59 | 63 |
| 60 if (!parser_->IsEmpty()) { | 64 if (!parser_->IsEmpty()) { |
| 61 MessageLoop::current()->PostTask( | 65 MessageLoop::current()->PostTask( |
| 62 FROM_HERE, NewRunnableMethod(this, &GPUProcessor::ProcessCommands)); | 66 FROM_HERE, |
| 67 method_factory_.NewRunnableMethod(&GPUProcessor::ProcessCommands)); |
| 63 } | 68 } |
| 64 } | 69 } |
| 65 | 70 |
| 66 Buffer GPUProcessor::GetSharedMemoryBuffer(int32 shm_id) { | 71 Buffer GPUProcessor::GetSharedMemoryBuffer(int32 shm_id) { |
| 67 return command_buffer_->GetTransferBuffer(shm_id); | 72 return command_buffer_->GetTransferBuffer(shm_id); |
| 68 } | 73 } |
| 69 | 74 |
| 70 void GPUProcessor::set_token(int32 token) { | 75 void GPUProcessor::set_token(int32 token) { |
| 71 command_buffer_->SetToken(token); | 76 command_buffer_->SetToken(token); |
| 72 } | 77 } |
| 73 | 78 |
| 74 bool GPUProcessor::SetGetOffset(int32 offset) { | 79 bool GPUProcessor::SetGetOffset(int32 offset) { |
| 75 if (parser_->set_get(offset)) { | 80 if (parser_->set_get(offset)) { |
| 76 command_buffer_->SetGetOffset(static_cast<int32>(parser_->get())); | 81 command_buffer_->SetGetOffset(static_cast<int32>(parser_->get())); |
| 77 return true; | 82 return true; |
| 78 } | 83 } |
| 79 return false; | 84 return false; |
| 80 } | 85 } |
| 81 | 86 |
| 82 int32 GPUProcessor::GetGetOffset() { | 87 int32 GPUProcessor::GetGetOffset() { |
| 83 return parser_->get(); | 88 return parser_->get(); |
| 84 } | 89 } |
| 85 | 90 |
| 91 void GPUProcessor::ResizeOffscreenFrameBuffer(const gfx::Size& size) { |
| 92 decoder_->ResizeOffscreenFrameBuffer(size); |
| 93 } |
| 94 |
| 86 #if defined(OS_MACOSX) | 95 #if defined(OS_MACOSX) |
| 87 uint64 GPUProcessor::SetWindowSizeForIOSurface(int32 width, int32 height) { | 96 uint64 GPUProcessor::SetWindowSizeForIOSurface(int32 width, int32 height) { |
| 88 return decoder_->SetWindowSizeForIOSurface(width, height); | 97 return decoder_->SetWindowSizeForIOSurface(width, height); |
| 89 } | 98 } |
| 90 | 99 |
| 91 TransportDIB::Handle GPUProcessor::SetWindowSizeForTransportDIB(int32 width, | 100 TransportDIB::Handle GPUProcessor::SetWindowSizeForTransportDIB(int32 width, |
| 92 int32 height) { | 101 int32 height) { |
| 93 return decoder_->SetWindowSizeForTransportDIB(width, height); | 102 return decoder_->SetWindowSizeForTransportDIB(width, height); |
| 94 } | 103 } |
| 95 | 104 |
| 96 void GPUProcessor::SetTransportDIBAllocAndFree( | 105 void GPUProcessor::SetTransportDIBAllocAndFree( |
| 97 Callback2<size_t, TransportDIB::Handle*>::Type* allocator, | 106 Callback2<size_t, TransportDIB::Handle*>::Type* allocator, |
| 98 Callback1<TransportDIB::Id>::Type* deallocator) { | 107 Callback1<TransportDIB::Id>::Type* deallocator) { |
| 99 decoder_->SetTransportDIBAllocAndFree(allocator, deallocator); | 108 decoder_->SetTransportDIBAllocAndFree(allocator, deallocator); |
| 100 } | 109 } |
| 101 #endif | 110 #endif |
| 102 | 111 |
| 103 void GPUProcessor::SetSwapBuffersCallback( | 112 void GPUProcessor::SetSwapBuffersCallback( |
| 104 Callback0::Type* callback) { | 113 Callback0::Type* callback) { |
| 105 decoder_->SetSwapBuffersCallback(callback); | 114 decoder_->SetSwapBuffersCallback(callback); |
| 106 } | 115 } |
| 107 | 116 |
| 108 } // namespace gpu | 117 } // namespace gpu |
| OLD | NEW |