OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "o3d/gpu_plugin/gpu_processor.h" | 7 #include "o3d/gpu_plugin/gpu_processor.h" |
8 | 8 |
9 namespace o3d { | 9 namespace o3d { |
10 namespace gpu_plugin { | 10 namespace gpu_plugin { |
11 | 11 |
12 GPUProcessor::GPUProcessor(const NPObjectPointer<CommandBuffer>& command_buffer) | 12 GPUProcessor::GPUProcessor(NPP npp, |
13 : command_buffer_(command_buffer), | 13 const NPObjectPointer<CommandBuffer>& command_buffer) |
14 window_handle_(NULL), | 14 : npp_(npp), |
15 window_width_(0), | 15 command_buffer_(command_buffer), |
16 window_height_(0) { | 16 commands_per_update_(100) { |
| 17 gapi_.reset(new command_buffer::GAPID3D9); |
| 18 |
| 19 decoder_.reset(new command_buffer::GAPIDecoder(gapi_.get())); |
| 20 |
| 21 NPObjectPointer<CHRSharedMemory> ring_buffer = |
| 22 command_buffer->GetRingBuffer(); |
| 23 |
| 24 if (ring_buffer.Get()) { |
| 25 parser_.reset(new command_buffer::CommandParser(ring_buffer->ptr, |
| 26 ring_buffer->size, |
| 27 0, |
| 28 ring_buffer->size, |
| 29 0, |
| 30 decoder_.get())); |
| 31 } else { |
| 32 parser_.reset(new command_buffer::CommandParser(NULL, 0, 0, 0, 0, |
| 33 decoder_.get())); |
| 34 } |
| 35 } |
| 36 |
| 37 GPUProcessor::GPUProcessor(NPP npp, |
| 38 const NPObjectPointer<CommandBuffer>& command_buffer, |
| 39 command_buffer::GAPID3D9* gapi, |
| 40 command_buffer::GAPIDecoder* decoder, |
| 41 command_buffer::CommandParser* parser, |
| 42 int commands_per_update) |
| 43 : npp_(npp), |
| 44 command_buffer_(command_buffer), |
| 45 commands_per_update_(commands_per_update) { |
| 46 gapi_.reset(gapi); |
| 47 decoder_.reset(decoder); |
| 48 parser_.reset(parser); |
| 49 } |
| 50 |
| 51 bool GPUProcessor::Initialize(HWND handle) { |
| 52 // Cannot reinitialize. |
| 53 DCHECK(gapi_->hwnd() == NULL); |
| 54 |
| 55 // Initialize GAPI immediately if the window handle is valid. |
| 56 if (handle) { |
| 57 gapi_->set_hwnd(handle); |
| 58 return gapi_->Initialize(); |
| 59 } else { |
| 60 return true; |
| 61 } |
| 62 } |
| 63 |
| 64 void GPUProcessor::Destroy() { |
| 65 // Destroy GAPI if window handle has not already become invalid. |
| 66 if (gapi_->hwnd()) { |
| 67 gapi_->Destroy(); |
| 68 gapi_->set_hwnd(NULL); |
| 69 } |
17 } | 70 } |
18 | 71 |
19 void GPUProcessor::SetWindow(HWND handle, int width, int height) { | 72 void GPUProcessor::SetWindow(HWND handle, int width, int height) { |
20 window_handle_ = handle; | 73 if (handle == NULL) { |
21 window_width_ = width; | 74 // Destroy GAPI when the window handle becomes invalid. |
22 window_height_ = height; | 75 Destroy(); |
23 } | 76 } else { |
24 | 77 if (handle != gapi_->hwnd()) { |
25 void GPUProcessor::DrawRectangle(uint32 color, | 78 Initialize(handle); |
26 int left, int top, int right, int bottom) { | 79 } |
27 if (!window_handle_) | 80 } |
28 return; | |
29 | |
30 HBRUSH brush = ::CreateSolidBrush(color); | |
31 HDC dc = ::GetDC(window_handle_); | |
32 RECT rect = { left, right, top, bottom }; | |
33 ::FillRect(dc, &rect, brush); | |
34 ::ReleaseDC(window_handle_, dc); | |
35 ::DeleteObject(brush); | |
36 } | 81 } |
37 | 82 |
38 } // namespace gpu_plugin | 83 } // namespace gpu_plugin |
39 } // namespace o3d | 84 } // namespace o3d |
OLD | NEW |