OLD | NEW |
1 // Copyright (c) 2006-2008 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 <windows.h> | 5 #include <windows.h> |
6 | 6 |
7 #include "gpu/command_buffer/service/gpu_processor.h" | 7 #include "gpu/command_buffer/service/gpu_processor.h" |
8 | 8 |
9 using ::base::SharedMemory; | 9 using ::base::SharedMemory; |
10 | 10 |
11 namespace command_buffer { | 11 namespace gpu { |
12 | 12 |
13 GPUProcessor::GPUProcessor(CommandBuffer* command_buffer) | 13 GPUProcessor::GPUProcessor(CommandBuffer* command_buffer) |
14 : command_buffer_(command_buffer), | 14 : command_buffer_(command_buffer), |
15 commands_per_update_(100) { | 15 commands_per_update_(100) { |
16 DCHECK(command_buffer); | 16 DCHECK(command_buffer); |
17 decoder_.reset(gles2::GLES2Decoder::Create()); | 17 decoder_.reset(gles2::GLES2Decoder::Create()); |
18 decoder_->set_engine(this); | 18 decoder_->set_engine(this); |
19 } | 19 } |
20 | 20 |
21 GPUProcessor::GPUProcessor(CommandBuffer* command_buffer, | 21 GPUProcessor::GPUProcessor(CommandBuffer* command_buffer, |
22 gles2::GLES2Decoder* decoder, | 22 gles2::GLES2Decoder* decoder, |
23 CommandParser* parser, | 23 CommandParser* parser, |
24 int commands_per_update) | 24 int commands_per_update) |
25 : command_buffer_(command_buffer), | 25 : command_buffer_(command_buffer), |
26 commands_per_update_(commands_per_update) { | 26 commands_per_update_(commands_per_update) { |
27 DCHECK(command_buffer); | 27 DCHECK(command_buffer); |
28 decoder_.reset(decoder); | 28 decoder_.reset(decoder); |
29 parser_.reset(parser); | 29 parser_.reset(parser); |
30 } | 30 } |
31 | 31 |
32 bool GPUProcessor::Initialize(HWND handle) { | 32 bool GPUProcessor::Initialize(gfx::PluginWindowHandle handle) { |
33 DCHECK(handle); | 33 DCHECK(handle); |
34 | 34 |
35 // Cannot reinitialize. | 35 // Cannot reinitialize. |
36 if (decoder_->hwnd() != NULL) | 36 if (decoder_->hwnd() != NULL) |
37 return false; | 37 return false; |
38 | 38 |
39 // Map the ring buffer and create the parser. | 39 // Map the ring buffer and create the parser. |
40 ::base::SharedMemory* ring_buffer = command_buffer_->GetRingBuffer(); | 40 ::base::SharedMemory* ring_buffer = command_buffer_->GetRingBuffer(); |
41 if (ring_buffer) { | 41 if (ring_buffer) { |
42 size_t size = ring_buffer->max_size(); | 42 size_t size = ring_buffer->max_size(); |
43 if (!ring_buffer->Map(size)) { | 43 if (!ring_buffer->Map(size)) { |
44 return false; | 44 return false; |
45 } | 45 } |
46 | 46 |
47 void* ptr = ring_buffer->memory(); | 47 void* ptr = ring_buffer->memory(); |
48 parser_.reset(new command_buffer::CommandParser(ptr, size, 0, size, 0, | 48 parser_.reset(new gpu::CommandParser(ptr, size, 0, size, 0, |
49 decoder_.get())); | 49 decoder_.get())); |
50 } else { | 50 } else { |
51 parser_.reset(new command_buffer::CommandParser(NULL, 0, 0, 0, 0, | 51 parser_.reset(new gpu::CommandParser(NULL, 0, 0, 0, 0, |
52 decoder_.get())); | 52 decoder_.get())); |
53 } | 53 } |
54 | 54 |
55 // Initialize GAPI immediately if the window handle is valid. | 55 // Initialize GAPI immediately if the window handle is valid. |
56 decoder_->set_hwnd(handle); | 56 decoder_->set_hwnd(handle); |
57 return decoder_->Initialize(); | 57 return decoder_->Initialize(); |
58 } | 58 } |
59 | 59 |
60 void GPUProcessor::Destroy() { | 60 void GPUProcessor::Destroy() { |
61 // Destroy GAPI if window handle has not already become invalid. | 61 // Destroy GAPI if window handle has not already become invalid. |
62 if (decoder_->hwnd()) { | 62 if (decoder_->hwnd()) { |
63 decoder_->Destroy(); | 63 decoder_->Destroy(); |
64 decoder_->set_hwnd(NULL); | 64 decoder_->set_hwnd(NULL); |
65 } | 65 } |
66 } | 66 } |
67 | 67 |
68 bool GPUProcessor::SetWindow(HWND handle, int width, int height) { | 68 bool GPUProcessor::SetWindow(gfx::PluginWindowHandle handle, |
| 69 int width, |
| 70 int height) { |
69 if (handle == NULL) { | 71 if (handle == NULL) { |
70 // Destroy GAPI when the window handle becomes invalid. | 72 // Destroy GAPI when the window handle becomes invalid. |
71 Destroy(); | 73 Destroy(); |
72 return true; | 74 return true; |
73 } else { | 75 } else { |
74 return Initialize(handle); | 76 return Initialize(handle); |
75 } | 77 } |
76 } | 78 } |
77 | 79 |
78 } // namespace command_buffer | 80 } // namespace gpu |
OLD | NEW |