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

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"
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"kCompositorWindowOwner"
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,
jam 2010/11/12 18:08:00 nit: hwnd
nduca 2010/11/12 19:45:32 Done.
46 UINT message,
47 WPARAM wparam,
48 LPARAM lparam) {
49 switch (message) {
50 case WM_ERASEBKGND:
jam 2010/11/12 18:08:00 nit: the case should be indented in
nduca 2010/11/12 19:45:32 Done.
51 return 0;
52 case WM_DESTROY:
53 return 0;
54 case WM_PAINT:
55 {
jam 2010/11/12 18:08:00 nit: i think you have extra indentation here
nduca 2010/11/12 19:45:32 Done.
56 PAINTSTRUCT paint;
57 BeginPaint(hWnd, &paint);
58 HANDLE h = GetProp(hWnd, kCompositorWindowOwner);
59 GpuCommandBufferStub* stub = reinterpret_cast<GpuCommandBufferStub*>(h);
60 stub->OnCompositorWindowPainted();
61 EndPaint(hWnd, &paint);
62 }
63 break;
64 default:
65 return DefWindowProc(hWnd, message, wparam, lparam);
66 }
67 return 0;
68 }
69
70 void GpuCommandBufferStub::CreateCompositorWindow() {
71 DCHECK(handle_ != gfx::kNullPluginWindow);
72
73 // Ask the browser to create the the host window.
74 ChildThread* gpu_thread = ChildThread::current();
75 gfx::PluginWindowHandle host_window_id;
76 gpu_thread->Send(new GpuHostMsg_CreateCompositorHostWindow(
77 renderer_id_,
78 render_view_id_,
79 &host_window_id));
80 HWND host_window = static_cast<HWND>(host_window_id);
81
82 // Create the compositor window itself.
83 DCHECK(host_window);
84 static ATOM window_class = 0;
85 if (!window_class) {
86 WNDCLASSEX wcex;
87 wcex.cbSize = sizeof(wcex);
88 wcex.style = 0;
89 wcex.lpfnWndProc = CompositorWindowProc;
90 wcex.cbClsExtra = 0;
91 wcex.cbWndExtra = 0;
92 wcex.hInstance = GetModuleHandle(NULL);
93 wcex.hIcon = 0;
94 wcex.hCursor = 0;
95 wcex.hbrBackground = NULL;
96 wcex.lpszMenuName = 0;
97 wcex.lpszClassName = L"CompositorWindowClass";
98 wcex.hIconSm = 0;
99 window_class = RegisterClassEx(&wcex);
100 DCHECK(window_class);
101 }
102
103 HWND compositor_window = CreateWindowEx(
104 WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR,
jam 2010/11/12 18:08:00 nit: need 4 spaces for indentation
nduca 2010/11/12 19:45:32 Done.
105 MAKEINTATOM(window_class),
106 0,
107 WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_DISABLED,
108 0/*x*/, 0/*y*/,
jam 2010/11/12 18:08:00 nit: i don't see this pattern of commenting input
nduca 2010/11/12 19:45:32 I tend to agree.
109 0/*nWidth*/, 0/*nHeight*/,
110 host_window,
111 0,
112 GetModuleHandle(NULL),
113 0);
114 DCHECK(compositor_window);
115 SetProp(compositor_window, kCompositorWindowOwner,
116 reinterpret_cast<HANDLE>(this));
117
118 RECT parent_rect;
119 GetClientRect(host_window, &parent_rect);
120
121 UINT flags = SWP_NOSENDCHANGING | SWP_NOCOPYBITS | SWP_NOZORDER |
122 SWP_NOACTIVATE | SWP_DEFERERASE | SWP_SHOWWINDOW;
123 SetWindowPos(compositor_window,
124 NULL,
125 0/*x*/, 0/*y*/,
126 parent_rect.right - parent_rect.left,
127 parent_rect.bottom - parent_rect.top,
128 flags);
129 compositor_window_ = static_cast<gfx::PluginWindowHandle>(compositor_window);
130 }
131
132 void GpuCommandBufferStub::OnCompositorWindowPainted()
133 {
jam 2010/11/12 18:08:00 nit: brace bracket on previous line
nduca 2010/11/12 19:45:32 Done.
134 ChildThread* gpu_thread = ChildThread::current();
135 gpu_thread->Send(new GpuHostMsg_ScheduleComposite(
136 renderer_id_, render_view_id_));
137 }
138 #endif // defined(OS_WIN)
139
140
41 GpuCommandBufferStub::~GpuCommandBufferStub() { 141 GpuCommandBufferStub::~GpuCommandBufferStub() {
42 if (processor_.get()) { 142 if (processor_.get()) {
43 processor_->Destroy(); 143 processor_->Destroy();
44 } 144 }
145 #if defined(OS_WIN)
146 if (compositor_window_) {
147 RemoveProp(compositor_window_, kCompositorWindowOwner);
148 DestroyWindow(static_cast<HWND>(compositor_window_));
149 compositor_window_ = NULL;
150 }
151 #endif
45 } 152 }
46 153
47 void GpuCommandBufferStub::OnMessageReceived(const IPC::Message& message) { 154 void GpuCommandBufferStub::OnMessageReceived(const IPC::Message& message) {
48 IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message) 155 IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message)
49 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Initialize, OnInitialize); 156 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Initialize, OnInitialize);
50 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_GetState, OnGetState); 157 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_GetState, OnGetState);
51 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncGetState, OnAsyncGetState); 158 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncGetState, OnAsyncGetState);
52 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Flush, OnFlush); 159 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Flush, OnFlush);
53 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncFlush, OnAsyncFlush); 160 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncFlush, OnAsyncFlush);
54 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateTransferBuffer, 161 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateTransferBuffer,
(...skipping 17 matching lines...) Expand all
72 179
73 void GpuCommandBufferStub::OnInitialize( 180 void GpuCommandBufferStub::OnInitialize(
74 int32 size, 181 int32 size,
75 base::SharedMemoryHandle* ring_buffer) { 182 base::SharedMemoryHandle* ring_buffer) {
76 DCHECK(!command_buffer_.get()); 183 DCHECK(!command_buffer_.get());
77 184
78 *ring_buffer = base::SharedMemory::NULLHandle(); 185 *ring_buffer = base::SharedMemory::NULLHandle();
79 186
80 command_buffer_.reset(new gpu::CommandBufferService); 187 command_buffer_.reset(new gpu::CommandBufferService);
81 188
189 // Create the child window, if needed
190 #if defined(OS_WIN)
191 CreateCompositorWindow();
192 gfx::PluginWindowHandle output_window_handle = compositor_window_;
193 #else
194 gfx::PluginWindowHandle output_window_handle = handle_;
195 #endif
196
82 // Initialize the CommandBufferService and GPUProcessor. 197 // Initialize the CommandBufferService and GPUProcessor.
83 if (command_buffer_->Initialize(size)) { 198 if (command_buffer_->Initialize(size)) {
84 Buffer buffer = command_buffer_->GetRingBuffer(); 199 Buffer buffer = command_buffer_->GetRingBuffer();
85 if (buffer.shared_memory) { 200 if (buffer.shared_memory) {
86 gpu::GPUProcessor* parent_processor = 201 gpu::GPUProcessor* parent_processor =
87 parent_ ? parent_->processor_.get() : NULL; 202 parent_ ? parent_->processor_.get() : NULL;
88 processor_.reset(new gpu::GPUProcessor(command_buffer_.get(), NULL)); 203 processor_.reset(new gpu::GPUProcessor(command_buffer_.get(), NULL));
89 if (processor_->Initialize( 204 if (processor_->Initialize(
90 handle_, 205 output_window_handle,
91 initial_size_, 206 initial_size_,
92 allowed_extensions_.c_str(), 207 allowed_extensions_.c_str(),
93 requested_attribs_, 208 requested_attribs_,
94 parent_processor, 209 parent_processor,
95 parent_texture_id_)) { 210 parent_texture_id_)) {
96 command_buffer_->SetPutOffsetChangeCallback( 211 command_buffer_->SetPutOffsetChangeCallback(
97 NewCallback(processor_.get(), 212 NewCallback(processor_.get(),
98 &gpu::GPUProcessor::ProcessCommands)); 213 &gpu::GPUProcessor::ProcessCommands));
99 processor_->SetSwapBuffersCallback( 214 processor_->SetSwapBuffersCallback(
100 NewCallback(this, &GpuCommandBufferStub::OnSwapBuffers)); 215 NewCallback(this, &GpuCommandBufferStub::OnSwapBuffers));
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 312 }
198 313
199 void GpuCommandBufferStub::SwapBuffersCallback() { 314 void GpuCommandBufferStub::SwapBuffersCallback() {
200 ChildThread* gpu_thread = ChildThread::current(); 315 ChildThread* gpu_thread = ChildThread::current();
201 gpu_thread->Send(new GpuHostMsg_AcceleratedSurfaceBuffersSwapped( 316 gpu_thread->Send(new GpuHostMsg_AcceleratedSurfaceBuffersSwapped(
202 renderer_id_, render_view_id_, handle_, processor_->GetSurfaceId())); 317 renderer_id_, render_view_id_, handle_, processor_->GetSurfaceId()));
203 } 318 }
204 #endif // defined(OS_MACOSX) 319 #endif // defined(OS_MACOSX)
205 320
206 #endif // ENABLE_GPU 321 #endif // ENABLE_GPU
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698