OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/renderer_host/render_widget_host_view_views.h" | 5 #include "chrome/browser/renderer_host/render_widget_host_view_views.h" |
6 | 6 |
7 #include "base/bind.h" | |
8 #include "base/logging.h" | 7 #include "base/logging.h" |
9 #include "chrome/browser/renderer_host/accelerated_surface_container_touch.h" | |
10 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | |
11 #include "content/browser/renderer_host/render_widget_host.h" | 8 #include "content/browser/renderer_host/render_widget_host.h" |
12 #include "content/common/gpu/gpu_messages.h" | |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/gtk/WebInputEventFact
ory.h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/gtk/WebInputEventFact
ory.h" |
14 #include "ui/gfx/gl/gl_bindings.h" | |
15 #include "views/widget/widget.h" | 10 #include "views/widget/widget.h" |
16 | 11 |
17 static const char kRenderWidgetHostViewKey[] = "__RENDER_WIDGET_HOST_VIEW__"; | 12 static const char kRenderWidgetHostViewKey[] = "__RENDER_WIDGET_HOST_VIEW__"; |
18 | 13 |
19 using WebKit::WebInputEventFactory; | 14 using WebKit::WebInputEventFactory; |
20 using WebKit::WebTouchEvent; | 15 using WebKit::WebTouchEvent; |
21 | 16 |
22 namespace { | 17 namespace { |
23 | 18 |
24 WebKit::WebTouchPoint::State TouchPointStateFromEvent( | 19 WebKit::WebTouchPoint::State TouchPointStateFromEvent( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 void UpdateTouchPointPosition(const views::TouchEvent* event, | 59 void UpdateTouchPointPosition(const views::TouchEvent* event, |
65 const gfx::Point& origin, | 60 const gfx::Point& origin, |
66 WebKit::WebTouchPoint* tpoint) { | 61 WebKit::WebTouchPoint* tpoint) { |
67 tpoint->position.x = event->x(); | 62 tpoint->position.x = event->x(); |
68 tpoint->position.y = event->y(); | 63 tpoint->position.y = event->y(); |
69 | 64 |
70 tpoint->screenPosition.x = tpoint->position.x + origin.x(); | 65 tpoint->screenPosition.x = tpoint->position.x + origin.x(); |
71 tpoint->screenPosition.y = tpoint->position.y + origin.y(); | 66 tpoint->screenPosition.y = tpoint->position.y + origin.y(); |
72 } | 67 } |
73 | 68 |
74 void AcknowledgeSwapBuffers(int32 route_id, int gpu_host_id) { | |
75 // It's possible that gpu_host_id is no longer valid at this point (like if | |
76 // gpu process was restarted after a crash). SendToGpuHost handles this. | |
77 GpuProcessHostUIShim::SendToGpuHost(gpu_host_id, | |
78 new AcceleratedSurfaceMsg_BuffersSwappedACK(route_id)); | |
79 } | |
80 | |
81 } // namespace | 69 } // namespace |
82 | 70 |
83 ui::TouchStatus RenderWidgetHostViewViews::OnTouchEvent( | 71 ui::TouchStatus RenderWidgetHostViewViews::OnTouchEvent( |
84 const views::TouchEvent& event) { | 72 const views::TouchEvent& event) { |
85 if (!host_) | 73 if (!host_) |
86 return ui::TOUCH_STATUS_UNKNOWN; | 74 return ui::TOUCH_STATUS_UNKNOWN; |
87 | 75 |
88 // Update the list of touch points first. | 76 // Update the list of touch points first. |
89 WebKit::WebTouchPoint* point = NULL; | 77 WebKit::WebTouchPoint* point = NULL; |
90 ui::TouchStatus status = ui::TOUCH_STATUS_UNKNOWN; | 78 ui::TouchStatus status = ui::TOUCH_STATUS_UNKNOWN; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 touch_event_.touches[i] = touch_event_.touches[i + 1]; | 164 touch_event_.touches[i] = touch_event_.touches[i + 1]; |
177 } | 165 } |
178 if (touch_event_.touchesLength == 0) | 166 if (touch_event_.touchesLength == 0) |
179 status = ui::TOUCH_STATUS_END; | 167 status = ui::TOUCH_STATUS_END; |
180 } else if (event.type() == ui::ET_TOUCH_CANCELLED) { | 168 } else if (event.type() == ui::ET_TOUCH_CANCELLED) { |
181 status = ui::TOUCH_STATUS_CANCEL; | 169 status = ui::TOUCH_STATUS_CANCEL; |
182 } | 170 } |
183 | 171 |
184 return status; | 172 return status; |
185 } | 173 } |
186 | |
187 gfx::PluginWindowHandle RenderWidgetHostViewViews::GetCompositingSurface() { | |
188 // On TOUCH_UI builds, the GPU process renders to an offscreen surface | |
189 // (created by the GPU process), which is later displayed by the browser. | |
190 // As the GPU process creates this surface, we can return any non-zero value. | |
191 return 1; | |
192 } | |
193 | |
194 void RenderWidgetHostViewViews::AcceleratedSurfaceNew( | |
195 int32 width, | |
196 int32 height, | |
197 uint64* surface_id, | |
198 TransportDIB::Handle* surface_handle) { | |
199 scoped_ptr<AcceleratedSurfaceContainerTouch> surface( | |
200 AcceleratedSurfaceContainerTouch::CreateAcceleratedSurfaceContainer( | |
201 gfx::Size(width, height))); | |
202 if (!surface->Initialize(surface_id)) { | |
203 LOG(ERROR) << "Failed to create AcceleratedSurfaceContainer"; | |
204 return; | |
205 } | |
206 *surface_handle = surface->Handle(); | |
207 | |
208 accelerated_surface_containers_[*surface_id] = surface.release(); | |
209 } | |
210 | |
211 void RenderWidgetHostViewViews::AcceleratedSurfaceRelease(uint64 surface_id) { | |
212 accelerated_surface_containers_.erase(surface_id); | |
213 } | |
214 | |
215 void RenderWidgetHostViewViews::AcceleratedSurfaceBuffersSwapped( | |
216 uint64 surface_id, | |
217 int32 route_id, | |
218 int gpu_host_id) { | |
219 SetExternalTexture(accelerated_surface_containers_[surface_id].get()); | |
220 glFlush(); | |
221 | |
222 if (!GetWidget() || !GetWidget()->GetCompositor()) { | |
223 // We have no compositor, so we have no way to display the surface | |
224 AcknowledgeSwapBuffers(route_id, gpu_host_id); // Must still send the ACK | |
225 } else { | |
226 // Add sending an ACK to the list of things to do OnCompositingEnded | |
227 on_compositing_ended_callbacks_.push_back( | |
228 base::Bind(AcknowledgeSwapBuffers, route_id, gpu_host_id)); | |
229 ui::Compositor *compositor = GetWidget()->GetCompositor(); | |
230 if (!compositor->HasObserver(this)) | |
231 compositor->AddObserver(this); | |
232 } | |
233 } | |
234 | |
235 void RenderWidgetHostViewViews::OnCompositingEnded(ui::Compositor* compositor) { | |
236 for (std::vector< base::Callback<void(void)> >::const_iterator | |
237 it = on_compositing_ended_callbacks_.begin(); | |
238 it != on_compositing_ended_callbacks_.end(); ++it) { | |
239 it->Run(); | |
240 } | |
241 on_compositing_ended_callbacks_.clear(); | |
242 compositor->RemoveObserver(this); | |
243 } | |
244 | |
OLD | NEW |