OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #if defined(ENABLE_GPU) | 5 #if defined(ENABLE_GPU) |
6 | 6 |
7 #include "base/process_util.h" | 7 #include "base/process_util.h" |
8 #include "base/shared_memory.h" | 8 #include "base/shared_memory.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "chrome/common/child_thread.h" | 10 #include "chrome/common/child_thread.h" |
11 #include "chrome/common/gpu_messages.h" | 11 #include "chrome/common/gpu_messages.h" |
12 #include "chrome/gpu/gpu_channel.h" | 12 #include "chrome/gpu/gpu_channel.h" |
13 #include "chrome/gpu/gpu_command_buffer_stub.h" | 13 #include "chrome/gpu/gpu_command_buffer_stub.h" |
14 | 14 |
15 using gpu::Buffer; | 15 using gpu::Buffer; |
16 | 16 |
17 #define kCompositorWindowOwner L"CompositorWindowOwner" | |
18 | |
17 GpuCommandBufferStub::GpuCommandBufferStub( | 19 GpuCommandBufferStub::GpuCommandBufferStub( |
18 GpuChannel* channel, | 20 GpuChannel* channel, |
19 gfx::PluginWindowHandle handle, | 21 gfx::PluginWindowHandle handle, |
20 GpuCommandBufferStub* parent, | 22 GpuCommandBufferStub* parent, |
21 const gfx::Size& size, | 23 const gfx::Size& size, |
22 const std::string& allowed_extensions, | 24 const std::string& allowed_extensions, |
23 const std::vector<int32>& attribs, | 25 const std::vector<int32>& attribs, |
24 uint32 parent_texture_id, | 26 uint32 parent_texture_id, |
25 int32 route_id, | 27 int32 route_id, |
26 int32 renderer_id, | 28 int32 renderer_id, |
27 int32 render_view_id) | 29 int32 render_view_id) |
28 : channel_(channel), | 30 : channel_(channel), |
29 handle_(handle), | 31 handle_(handle), |
30 parent_( | 32 parent_( |
31 parent ? parent->AsWeakPtr() : base::WeakPtr<GpuCommandBufferStub>()), | 33 parent ? parent->AsWeakPtr() : base::WeakPtr<GpuCommandBufferStub>()), |
32 initial_size_(size), | 34 initial_size_(size), |
33 allowed_extensions_(allowed_extensions), | 35 allowed_extensions_(allowed_extensions), |
34 requested_attribs_(attribs), | 36 requested_attribs_(attribs), |
35 parent_texture_id_(parent_texture_id), | 37 parent_texture_id_(parent_texture_id), |
36 route_id_(route_id), | 38 route_id_(route_id), |
37 renderer_id_(renderer_id), | 39 renderer_id_(renderer_id), |
38 render_view_id_(render_view_id) { | 40 render_view_id_(render_view_id) { |
39 } | 41 } |
40 | 42 |
43 #if defined(OS_WIN) | |
44 static LRESULT CALLBACK CompositorWindowProc( | |
45 HWND hwnd, | |
46 UINT message, | |
47 WPARAM wparam, | |
48 LPARAM lparam) { | |
49 switch (message) { | |
50 case WM_ERASEBKGND: | |
51 return 0; | |
52 case WM_DESTROY: | |
53 return 0; | |
54 case WM_PAINT: { | |
55 PAINTSTRUCT paint; | |
56 HDC dc = BeginPaint(hwnd, &paint); | |
57 if (dc) { | |
58 HANDLE h = GetProp(hwnd, kCompositorWindowOwner); | |
59 if (h) { | |
60 GpuCommandBufferStub* stub = | |
61 reinterpret_cast<GpuCommandBufferStub*>(h); | |
62 stub->OnCompositorWindowPainted(); | |
63 EndPaint(hwnd, &paint); | |
apatrick_chromium
2010/11/22 20:43:03
EndPaint needs to be matched with every successful
nduca
2010/11/22 22:37:44
Done.
| |
64 } | |
65 } | |
66 break; | |
67 } | |
68 default: | |
69 return DefWindowProc(hwnd, message, wparam, lparam); | |
70 } | |
71 return 0; | |
72 } | |
73 | |
74 bool GpuCommandBufferStub::CreateCompositorWindow() { | |
75 DCHECK(handle_ != gfx::kNullPluginWindow); | |
76 | |
77 // Ask the browser to create the the host window. | |
78 ChildThread* gpu_thread = ChildThread::current(); | |
79 gfx::PluginWindowHandle host_window_id; | |
80 gpu_thread->Send(new GpuHostMsg_CreateCompositorHostWindow( | |
apatrick_chromium
2010/11/22 20:43:03
indentation is out.
nduca
2010/11/22 22:37:44
Done.
| |
81 renderer_id_, | |
82 render_view_id_, | |
83 &host_window_id)); | |
84 HWND host_window = static_cast<HWND>(host_window_id); | |
85 | |
86 // Create the compositor window itself. | |
87 DCHECK(host_window); | |
88 static ATOM window_class = 0; | |
89 if (!window_class) { | |
90 WNDCLASSEX wcex; | |
91 wcex.cbSize = sizeof(wcex); | |
92 wcex.style = 0; | |
93 wcex.lpfnWndProc = CompositorWindowProc; | |
94 wcex.cbClsExtra = 0; | |
95 wcex.cbWndExtra = 0; | |
96 wcex.hInstance = GetModuleHandle(NULL); | |
97 wcex.hIcon = 0; | |
98 wcex.hCursor = 0; | |
99 wcex.hbrBackground = NULL; | |
100 wcex.lpszMenuName = 0; | |
101 wcex.lpszClassName = L"CompositorWindowClass"; | |
102 wcex.hIconSm = 0; | |
103 window_class = RegisterClassEx(&wcex); | |
104 DCHECK(window_class); | |
105 } | |
106 | |
107 HWND compositor_window = CreateWindowEx( | |
108 WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR, | |
109 MAKEINTATOM(window_class), | |
110 0, | |
111 WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_DISABLED, | |
112 0, 0, | |
113 0, 0, | |
114 host_window, | |
115 0, | |
116 GetModuleHandle(NULL), | |
117 0); | |
118 if (!compositor_window) { | |
119 compositor_window_ = gfx::kNullPluginWindow; | |
120 return false; | |
121 } | |
122 SetProp(compositor_window, kCompositorWindowOwner, | |
123 reinterpret_cast<HANDLE>(this)); | |
124 | |
125 RECT parent_rect; | |
126 GetClientRect(host_window, &parent_rect); | |
127 | |
128 UINT flags = SWP_NOSENDCHANGING | SWP_NOCOPYBITS | SWP_NOZORDER | | |
129 SWP_NOACTIVATE | SWP_DEFERERASE | SWP_SHOWWINDOW; | |
130 SetWindowPos(compositor_window, | |
131 NULL, | |
132 0, 0, | |
133 parent_rect.right - parent_rect.left, | |
134 parent_rect.bottom - parent_rect.top, | |
135 flags); | |
136 compositor_window_ = static_cast<gfx::PluginWindowHandle>(compositor_window); | |
137 return true; | |
138 } | |
139 | |
140 void GpuCommandBufferStub::OnCompositorWindowPainted() { | |
141 ChildThread* gpu_thread = ChildThread::current(); | |
142 gpu_thread->Send(new GpuHostMsg_ScheduleComposite( | |
143 renderer_id_, render_view_id_)); | |
144 } | |
145 #endif // defined(OS_WIN) | |
146 | |
147 | |
41 GpuCommandBufferStub::~GpuCommandBufferStub() { | 148 GpuCommandBufferStub::~GpuCommandBufferStub() { |
42 if (processor_.get()) { | 149 if (processor_.get()) { |
43 processor_->Destroy(); | 150 processor_->Destroy(); |
44 } | 151 } |
152 #if defined(OS_WIN) | |
153 if (compositor_window_) { | |
154 RemoveProp(compositor_window_, kCompositorWindowOwner); | |
155 DestroyWindow(static_cast<HWND>(compositor_window_)); | |
156 compositor_window_ = NULL; | |
157 } | |
158 #endif | |
45 } | 159 } |
46 | 160 |
47 void GpuCommandBufferStub::OnMessageReceived(const IPC::Message& message) { | 161 void GpuCommandBufferStub::OnMessageReceived(const IPC::Message& message) { |
48 IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message) | 162 IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message) |
49 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Initialize, OnInitialize); | 163 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Initialize, OnInitialize); |
50 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_GetState, OnGetState); | 164 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_GetState, OnGetState); |
51 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncGetState, OnAsyncGetState); | 165 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncGetState, OnAsyncGetState); |
52 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Flush, OnFlush); | 166 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Flush, OnFlush); |
53 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncFlush, OnAsyncFlush); | 167 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncFlush, OnAsyncFlush); |
54 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateTransferBuffer, | 168 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateTransferBuffer, |
(...skipping 17 matching lines...) Expand all Loading... | |
72 | 186 |
73 void GpuCommandBufferStub::OnInitialize( | 187 void GpuCommandBufferStub::OnInitialize( |
74 int32 size, | 188 int32 size, |
75 base::SharedMemoryHandle* ring_buffer) { | 189 base::SharedMemoryHandle* ring_buffer) { |
76 DCHECK(!command_buffer_.get()); | 190 DCHECK(!command_buffer_.get()); |
77 | 191 |
78 *ring_buffer = base::SharedMemory::NULLHandle(); | 192 *ring_buffer = base::SharedMemory::NULLHandle(); |
79 | 193 |
80 command_buffer_.reset(new gpu::CommandBufferService); | 194 command_buffer_.reset(new gpu::CommandBufferService); |
81 | 195 |
196 // Create the child window, if needed | |
197 #if defined(OS_WIN) | |
198 gfx::PluginWindowHandle output_window_handle; | |
199 if (handle_) { | |
200 if (!CreateCompositorWindow()) { | |
201 *ring_buffer = NULL; | |
apatrick_chromium
2010/11/22 20:43:03
We use base::SharedMemory::NULLHandle() instead of
nduca
2010/11/22 22:37:44
Done.
| |
202 return; | |
203 } | |
204 handle_ = compositor_window_; | |
205 } else { | |
206 output_window_handle = handle_; | |
207 } | |
208 #else | |
209 gfx::PluginWindowHandle output_window_handle = handle_; | |
210 #endif | |
211 | |
82 // Initialize the CommandBufferService and GPUProcessor. | 212 // Initialize the CommandBufferService and GPUProcessor. |
83 if (command_buffer_->Initialize(size)) { | 213 if (command_buffer_->Initialize(size)) { |
84 Buffer buffer = command_buffer_->GetRingBuffer(); | 214 Buffer buffer = command_buffer_->GetRingBuffer(); |
85 if (buffer.shared_memory) { | 215 if (buffer.shared_memory) { |
86 gpu::GPUProcessor* parent_processor = | 216 gpu::GPUProcessor* parent_processor = |
87 parent_ ? parent_->processor_.get() : NULL; | 217 parent_ ? parent_->processor_.get() : NULL; |
88 processor_.reset(new gpu::GPUProcessor(command_buffer_.get(), NULL)); | 218 processor_.reset(new gpu::GPUProcessor(command_buffer_.get(), NULL)); |
89 if (processor_->Initialize( | 219 if (processor_->Initialize( |
90 handle_, | 220 output_window_handle, |
91 initial_size_, | 221 initial_size_, |
92 allowed_extensions_.c_str(), | 222 allowed_extensions_.c_str(), |
93 requested_attribs_, | 223 requested_attribs_, |
94 parent_processor, | 224 parent_processor, |
95 parent_texture_id_)) { | 225 parent_texture_id_)) { |
96 command_buffer_->SetPutOffsetChangeCallback( | 226 command_buffer_->SetPutOffsetChangeCallback( |
97 NewCallback(processor_.get(), | 227 NewCallback(processor_.get(), |
98 &gpu::GPUProcessor::ProcessCommands)); | 228 &gpu::GPUProcessor::ProcessCommands)); |
99 processor_->SetSwapBuffersCallback( | 229 processor_->SetSwapBuffersCallback( |
100 NewCallback(this, &GpuCommandBufferStub::OnSwapBuffers)); | 230 NewCallback(this, &GpuCommandBufferStub::OnSwapBuffers)); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 } | 327 } |
198 | 328 |
199 void GpuCommandBufferStub::SwapBuffersCallback() { | 329 void GpuCommandBufferStub::SwapBuffersCallback() { |
200 ChildThread* gpu_thread = ChildThread::current(); | 330 ChildThread* gpu_thread = ChildThread::current(); |
201 gpu_thread->Send(new GpuHostMsg_AcceleratedSurfaceBuffersSwapped( | 331 gpu_thread->Send(new GpuHostMsg_AcceleratedSurfaceBuffersSwapped( |
202 renderer_id_, render_view_id_, handle_, processor_->GetSurfaceId())); | 332 renderer_id_, render_view_id_, handle_, processor_->GetSurfaceId())); |
203 } | 333 } |
204 #endif // defined(OS_MACOSX) | 334 #endif // defined(OS_MACOSX) |
205 | 335 |
206 #endif // ENABLE_GPU | 336 #endif // ENABLE_GPU |
OLD | NEW |