Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Side by Side Diff: chrome/gpu/gpu_command_buffer_stub.cc

Issue 4815001: Use inner HWND for accelerated rendering on windows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 20 matching lines...) Expand all
31 parent ? parent->AsWeakPtr() : base::WeakPtr<GpuCommandBufferStub>()), 31 parent ? parent->AsWeakPtr() : base::WeakPtr<GpuCommandBufferStub>()),
32 initial_size_(size), 32 initial_size_(size),
33 allowed_extensions_(allowed_extensions), 33 allowed_extensions_(allowed_extensions),
34 requested_attribs_(attribs), 34 requested_attribs_(attribs),
35 parent_texture_id_(parent_texture_id), 35 parent_texture_id_(parent_texture_id),
36 route_id_(route_id), 36 route_id_(route_id),
37 renderer_id_(renderer_id), 37 renderer_id_(renderer_id),
38 render_view_id_(render_view_id) { 38 render_view_id_(render_view_id) {
39 } 39 }
40 40
41 #if defined(OS_WIN)
42 static LRESULT CALLBACK CompositorWindowProc(HWND hWnd, UINT message,
apatrick_chromium 2010/11/11 22:32:15 One parameter per line. hWnd, lParam and wParam sh
nduca 2010/11/11 23:53:33 Done.
43 WPARAM wParam, LPARAM lParam) {
44 switch (message) {
45 case WM_ERASEBKGND:
46 return 0;
47 case WM_DESTROY:
48 return 0;
49 case WM_PAINT:
50 {
51 PAINTSTRUCT paint;
52 BeginPaint(hWnd, &paint);
53 HANDLE h = GetProp(hWnd, L"CompositorWindowGpuCommandBufferStub");
apatrick_chromium 2010/11/11 22:32:15 Can you make the property name a constant?
nduca 2010/11/11 23:53:33 Done.
54 GpuCommandBufferStub* stub = reinterpret_cast<GpuCommandBufferStub*>(h);
55 stub->OnCompositorWindowPainted();
56 EndPaint(hWnd, &paint);
57 }
58 break;
59 case WM_CHAR:
60 return 0;
apatrick_chromium 2010/11/11 22:32:15 Why handle WM_CHAR? Does setting WS_DISABLED not a
nduca 2010/11/11 23:53:33 This is largely a C&P of the code in render_widget
61 default:
62 return DefWindowProc(hWnd, message, wParam, lParam);
63 }
64 return 0;
65 }
66
67 void GpuCommandBufferStub::CreateCompositorWindow() {
68 DCHECK(handle_ != gfx::kNullPluginWindow);
69
70 // Ask the browser to create the the host window.
71 ChildThread* gpu_thread = ChildThread::current();
72 gfx::PluginWindowHandle host_window_id;
73 gpu_thread->Send(new GpuHostMsg_CreateCompositorHostWindow(renderer_id_,
apatrick_chromium 2010/11/11 22:32:15 One argument per line.
nduca 2010/11/11 23:53:33 Done.
74 render_view_id_, &host_window_id));
75 HWND host_window = static_cast<HWND>(host_window_id);
76
77 // Create the compositor window itself.
78 DCHECK(host_window);
79 static ATOM window_class = 0;
80 if (!window_class) {
81 WNDCLASSEX wcex;
82 wcex.cbSize = sizeof(WNDCLASSEX);
apatrick_chromium 2010/11/11 22:32:15 sizeof(wcex)
nduca 2010/11/11 23:53:33 Done.
83 wcex.style = 0;
84 wcex.lpfnWndProc = CompositorWindowProc;
85 wcex.cbClsExtra = 0;
86 wcex.cbWndExtra = 0;
87 wcex.hInstance = GetModuleHandle(NULL);
88 wcex.hIcon = 0;
89 wcex.hCursor = 0;
90 wcex.hbrBackground = NULL;
91 wcex.lpszMenuName = 0;
92 wcex.lpszClassName = L"CompositorWindowClass";
93 wcex.hIconSm = 0;
94 window_class = RegisterClassEx(&wcex);
95 DCHECK(window_class);
96 }
97
98 HWND compositor_window = CreateWindowEx(
99 WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR,
apatrick_chromium 2010/11/11 22:32:15 One argument per line unless they are related, lik
nduca 2010/11/11 23:53:33 Done.
100 MAKEINTATOM(window_class), 0,
101 WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_DISABLED,
102 0, 0, 0, 0, host_window, 0, GetModuleHandle(NULL), 0);
103 DCHECK(compositor_window);
104 SetProp(compositor_window, L"CompositorWindowGpuCommandBufferStub",
apatrick_chromium 2010/11/11 22:32:15 Use a string constant.
nduca 2010/11/11 23:53:33 Done.
105 reinterpret_cast<HANDLE>(this));
106
107 RECT parent_rect;
108 GetWindowRect(host_window, &parent_rect);
apatrick_chromium 2010/11/11 22:32:15 GetWindowRect or GetClientRect? Also, if this func
nduca 2010/11/11 23:53:33 Hahaha, I fail. Fixed. I'm not convinced you can
109
110 UINT flags = SWP_NOSENDCHANGING | SWP_NOCOPYBITS | SWP_NOZORDER |
111 SWP_NOACTIVATE | SWP_DEFERERASE | SWP_SHOWWINDOW;
112 SetWindowPos(compositor_window, NULL, 0, 0,
apatrick_chromium 2010/11/11 22:32:15 One argument per line unless they are related, lik
nduca 2010/11/11 23:53:33 Done.
113 parent_rect.right - parent_rect.left,
114 parent_rect.bottom - parent_rect.top,
115 flags);
116 compositor_window_ = static_cast<gfx::PluginWindowHandle>(compositor_window);
117 }
118
119 void GpuCommandBufferStub::OnCompositorWindowPainted()
120 {
121 ChildThread* gpu_thread = ChildThread::current();
122 gpu_thread->Send(new GpuHostMsg_ScheduleComposite(
123 renderer_id_, render_view_id_));
124 }
125 #endif // defined(OS_WIN)
126
127
41 GpuCommandBufferStub::~GpuCommandBufferStub() { 128 GpuCommandBufferStub::~GpuCommandBufferStub() {
42 if (processor_.get()) { 129 if (processor_.get()) {
43 processor_->Destroy(); 130 processor_->Destroy();
44 } 131 }
132 #if defined(OS_WIN)
133 if (compositor_window_) {
134 DestroyWindow(static_cast<HWND>(compositor_window_));
apatrick_chromium 2010/11/11 22:32:15 Windows apparently lets properties leak when you d
nduca 2010/11/11 23:53:33 Done.
135 compositor_window_ = NULL;
136 }
137 #endif
45 } 138 }
46 139
47 void GpuCommandBufferStub::OnMessageReceived(const IPC::Message& message) { 140 void GpuCommandBufferStub::OnMessageReceived(const IPC::Message& message) {
48 IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message) 141 IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message)
49 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Initialize, OnInitialize); 142 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Initialize, OnInitialize);
50 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_GetState, OnGetState); 143 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_GetState, OnGetState);
51 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncGetState, OnAsyncGetState); 144 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncGetState, OnAsyncGetState);
52 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Flush, OnFlush); 145 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Flush, OnFlush);
53 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncFlush, OnAsyncFlush); 146 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncFlush, OnAsyncFlush);
54 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateTransferBuffer, 147 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateTransferBuffer,
(...skipping 17 matching lines...) Expand all
72 165
73 void GpuCommandBufferStub::OnInitialize( 166 void GpuCommandBufferStub::OnInitialize(
74 int32 size, 167 int32 size,
75 base::SharedMemoryHandle* ring_buffer) { 168 base::SharedMemoryHandle* ring_buffer) {
76 DCHECK(!command_buffer_.get()); 169 DCHECK(!command_buffer_.get());
77 170
78 *ring_buffer = base::SharedMemory::NULLHandle(); 171 *ring_buffer = base::SharedMemory::NULLHandle();
79 172
80 command_buffer_.reset(new gpu::CommandBufferService); 173 command_buffer_.reset(new gpu::CommandBufferService);
81 174
175 // Create the child window, if needed
176 #if defined(OS_WIN)
177 CreateCompositorWindow();
178 gfx::PluginWindowHandle output_window_handle = compositor_window_;
179 #else
180 gfx::PluginWindowHandle output_window_handle = handle_;
181 #endif
182
82 // Initialize the CommandBufferService and GPUProcessor. 183 // Initialize the CommandBufferService and GPUProcessor.
83 if (command_buffer_->Initialize(size)) { 184 if (command_buffer_->Initialize(size)) {
84 Buffer buffer = command_buffer_->GetRingBuffer(); 185 Buffer buffer = command_buffer_->GetRingBuffer();
85 if (buffer.shared_memory) { 186 if (buffer.shared_memory) {
86 gpu::GPUProcessor* parent_processor = 187 gpu::GPUProcessor* parent_processor =
87 parent_ ? parent_->processor_.get() : NULL; 188 parent_ ? parent_->processor_.get() : NULL;
88 processor_.reset(new gpu::GPUProcessor(command_buffer_.get(), NULL)); 189 processor_.reset(new gpu::GPUProcessor(command_buffer_.get(), NULL));
89 if (processor_->Initialize( 190 if (processor_->Initialize(
90 handle_, 191 output_window_handle,
91 initial_size_, 192 initial_size_,
92 allowed_extensions_.c_str(), 193 allowed_extensions_.c_str(),
93 requested_attribs_, 194 requested_attribs_,
94 parent_processor, 195 parent_processor,
95 parent_texture_id_)) { 196 parent_texture_id_)) {
96 command_buffer_->SetPutOffsetChangeCallback( 197 command_buffer_->SetPutOffsetChangeCallback(
97 NewCallback(processor_.get(), 198 NewCallback(processor_.get(),
98 &gpu::GPUProcessor::ProcessCommands)); 199 &gpu::GPUProcessor::ProcessCommands));
99 processor_->SetSwapBuffersCallback( 200 processor_->SetSwapBuffersCallback(
100 NewCallback(this, &GpuCommandBufferStub::OnSwapBuffers)); 201 NewCallback(this, &GpuCommandBufferStub::OnSwapBuffers));
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 298 }
198 299
199 void GpuCommandBufferStub::SwapBuffersCallback() { 300 void GpuCommandBufferStub::SwapBuffersCallback() {
200 ChildThread* gpu_thread = ChildThread::current(); 301 ChildThread* gpu_thread = ChildThread::current();
201 gpu_thread->Send(new GpuHostMsg_AcceleratedSurfaceBuffersSwapped( 302 gpu_thread->Send(new GpuHostMsg_AcceleratedSurfaceBuffersSwapped(
202 renderer_id_, render_view_id_, handle_, processor_->GetSurfaceId())); 303 renderer_id_, render_view_id_, handle_, processor_->GetSurfaceId()));
203 } 304 }
204 #endif // defined(OS_MACOSX) 305 #endif // defined(OS_MACOSX)
205 306
206 #endif // ENABLE_GPU 307 #endif // ENABLE_GPU
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698