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 #include "chrome/gpu/gpu_channel.h" | 5 #include "chrome/gpu/gpu_channel.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 } | 64 } |
65 | 65 |
66 if (!channel_.get()) { | 66 if (!channel_.get()) { |
67 delete message; | 67 delete message; |
68 return false; | 68 return false; |
69 } | 69 } |
70 | 70 |
71 return channel_->Send(message); | 71 return channel_->Send(message); |
72 } | 72 } |
73 | 73 |
| 74 void GpuChannel::CreateViewCommandBuffer( |
| 75 gfx::PluginWindowHandle window, |
| 76 int32 render_view_id, |
| 77 const GPUCreateCommandBufferConfig& init_params, |
| 78 int32* route_id) { |
| 79 *route_id = MSG_ROUTING_NONE; |
| 80 |
| 81 #if defined(ENABLE_GPU) |
| 82 *route_id = GenerateRouteID(); |
| 83 scoped_ptr<GpuCommandBufferStub> stub(new GpuCommandBufferStub( |
| 84 this, window, NULL, gfx::Size(), init_params.allowed_extensions, |
| 85 init_params.attribs, 0, *route_id, renderer_id_, render_view_id)); |
| 86 router_.AddRoute(*route_id, stub.get()); |
| 87 stubs_.AddWithID(stub.release(), *route_id); |
| 88 #endif // ENABLE_GPU |
| 89 } |
| 90 |
74 #if defined(OS_MACOSX) | 91 #if defined(OS_MACOSX) |
75 void GpuChannel::AcceleratedSurfaceBuffersSwapped( | 92 void GpuChannel::AcceleratedSurfaceBuffersSwapped( |
76 int32 route_id, uint64 swap_buffers_count) { | 93 int32 route_id, uint64 swap_buffers_count) { |
77 GpuCommandBufferStub* stub = stubs_.Lookup(route_id); | 94 GpuCommandBufferStub* stub = stubs_.Lookup(route_id); |
78 if (stub == NULL) | 95 if (stub == NULL) |
79 return; | 96 return; |
80 stub->AcceleratedSurfaceBuffersSwapped(swap_buffers_count); | 97 stub->AcceleratedSurfaceBuffersSwapped(swap_buffers_count); |
81 } | 98 } |
82 | 99 |
83 void GpuChannel::DidDestroySurface(int32 renderer_route_id) { | 100 void GpuChannel::DidDestroySurface(int32 renderer_route_id) { |
84 // Since acclerated views are created in the renderer process and then sent | 101 // Since acclerated views are created in the renderer process and then sent |
85 // to the browser process during GPU channel construction, it is possible that | 102 // to the browser process during GPU channel construction, it is possible that |
86 // this is called before a GpuCommandBufferStub for |renderer_route_id| was | 103 // this is called before a GpuCommandBufferStub for |renderer_route_id| was |
87 // put into |stubs_|. Hence, do not walk |stubs_| here but instead remember | 104 // put into |stubs_|. Hence, do not walk |stubs_| here but instead remember |
88 // all |renderer_route_id|s this was called for and use them later. | 105 // all |renderer_route_id|s this was called for and use them later. |
89 destroyed_renderer_routes_.insert(renderer_route_id); | 106 destroyed_renderer_routes_.insert(renderer_route_id); |
90 } | 107 } |
91 | 108 |
92 bool GpuChannel::IsRenderViewGone(int32 renderer_route_id) { | 109 bool GpuChannel::IsRenderViewGone(int32 renderer_route_id) { |
93 return destroyed_renderer_routes_.count(renderer_route_id) > 0; | 110 return destroyed_renderer_routes_.count(renderer_route_id) > 0; |
94 } | 111 } |
95 #endif | 112 #endif |
96 | 113 |
97 bool GpuChannel::OnControlMessageReceived(const IPC::Message& msg) { | 114 bool GpuChannel::OnControlMessageReceived(const IPC::Message& msg) { |
98 bool handled = true; | 115 bool handled = true; |
99 IPC_BEGIN_MESSAGE_MAP(GpuChannel, msg) | 116 IPC_BEGIN_MESSAGE_MAP(GpuChannel, msg) |
100 IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateViewCommandBuffer, | |
101 OnCreateViewCommandBuffer) | |
102 IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateOffscreenCommandBuffer, | 117 IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateOffscreenCommandBuffer, |
103 OnCreateOffscreenCommandBuffer) | 118 OnCreateOffscreenCommandBuffer) |
104 IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroyCommandBuffer, | 119 IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroyCommandBuffer, |
105 OnDestroyCommandBuffer) | 120 OnDestroyCommandBuffer) |
106 IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateVideoDecoder, | 121 IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateVideoDecoder, |
107 OnCreateVideoDecoder) | 122 OnCreateVideoDecoder) |
108 IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroyVideoDecoder, | 123 IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroyVideoDecoder, |
109 OnDestroyVideoDecoder) | 124 OnDestroyVideoDecoder) |
110 IPC_MESSAGE_UNHANDLED(handled = false) | 125 IPC_MESSAGE_UNHANDLED(handled = false) |
111 IPC_END_MESSAGE_MAP() | 126 IPC_END_MESSAGE_MAP() |
112 DCHECK(handled); | 127 DCHECK(handled); |
113 return handled; | 128 return handled; |
114 } | 129 } |
115 | 130 |
116 int GpuChannel::GenerateRouteID() { | 131 int GpuChannel::GenerateRouteID() { |
117 static int last_id = 0; | 132 static int last_id = 0; |
118 return ++last_id; | 133 return ++last_id; |
119 } | 134 } |
120 | 135 |
121 void GpuChannel::OnCreateViewCommandBuffer( | |
122 gfx::NativeViewId view_id, | |
123 int32 render_view_id, | |
124 const GPUCreateCommandBufferConfig& init_params, | |
125 int32* route_id) { | |
126 *route_id = MSG_ROUTING_NONE; | |
127 | |
128 #if defined(ENABLE_GPU) | |
129 | |
130 gfx::PluginWindowHandle handle = gfx::kNullPluginWindow; | |
131 #if defined(OS_WIN) | |
132 // TODO(apatrick): We don't actually need the window handle on the Windows | |
133 // platform. At this point, it only indicates to the GpuCommandBufferStub | |
134 // whether onscreen or offscreen rendering is requested. The window handle | |
135 // that will be rendered to is the child compositor window and that window | |
136 // handle is provided by the browser process. Looking at what we are doing on | |
137 // this and other platforms, I think a redesign is in order here. Perhaps | |
138 // on all platforms the renderer just indicates whether it wants onscreen or | |
139 // offscreen rendering and the browser provides whichever platform specific | |
140 // "render target" the GpuCommandBufferStub targets. | |
141 handle = gfx::NativeViewFromId(view_id); | |
142 #elif defined(OS_LINUX) | |
143 // Ask the browser for the view's XID. | |
144 gpu_thread_->Send(new GpuHostMsg_GetViewXID(view_id, &handle)); | |
145 #elif defined(OS_MACOSX) | |
146 // On Mac OS X we currently pass a (fake) PluginWindowHandle for the | |
147 // NativeViewId. We could allocate fake NativeViewIds on the browser | |
148 // side as well, and map between those and PluginWindowHandles, but | |
149 // this seems excessive. | |
150 handle = static_cast<gfx::PluginWindowHandle>( | |
151 static_cast<intptr_t>(view_id)); | |
152 #else | |
153 // TODO(apatrick): This needs to be something valid for mac and linux. | |
154 // Offscreen rendering will work on these platforms but not rendering to the | |
155 // window. | |
156 DCHECK_EQ(view_id, 0); | |
157 #endif | |
158 | |
159 *route_id = GenerateRouteID(); | |
160 scoped_ptr<GpuCommandBufferStub> stub(new GpuCommandBufferStub( | |
161 this, handle, NULL, gfx::Size(), init_params.allowed_extensions, | |
162 init_params.attribs, 0, *route_id, renderer_id_, render_view_id)); | |
163 router_.AddRoute(*route_id, stub.get()); | |
164 stubs_.AddWithID(stub.release(), *route_id); | |
165 #endif // ENABLE_GPU | |
166 } | |
167 | |
168 void GpuChannel::OnCreateOffscreenCommandBuffer( | 136 void GpuChannel::OnCreateOffscreenCommandBuffer( |
169 int32 parent_route_id, | 137 int32 parent_route_id, |
170 const gfx::Size& size, | 138 const gfx::Size& size, |
171 const GPUCreateCommandBufferConfig& init_params, | 139 const GPUCreateCommandBufferConfig& init_params, |
172 uint32 parent_texture_id, | 140 uint32 parent_texture_id, |
173 int32* route_id) { | 141 int32* route_id) { |
174 #if defined(ENABLE_GPU) | 142 #if defined(ENABLE_GPU) |
175 *route_id = GenerateRouteID(); | 143 *route_id = GenerateRouteID(); |
176 GpuCommandBufferStub* parent_stub = NULL; | 144 GpuCommandBufferStub* parent_stub = NULL; |
177 if (parent_route_id != 0) | 145 if (parent_route_id != 0) |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 #if defined(OS_POSIX) | 224 #if defined(OS_POSIX) |
257 int GpuChannel::GetRendererFileDescriptor() { | 225 int GpuChannel::GetRendererFileDescriptor() { |
258 int fd = -1; | 226 int fd = -1; |
259 if (channel_.get()) { | 227 if (channel_.get()) { |
260 fd = channel_->GetClientFileDescriptor(); | 228 fd = channel_->GetClientFileDescriptor(); |
261 } | 229 } |
262 return fd; | 230 return fd; |
263 } | 231 } |
264 #endif // defined(OS_POSIX) | 232 #endif // defined(OS_POSIX) |
265 | 233 |
OLD | NEW |