OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_AURA_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_AURA_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_AURA_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_AURA_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/memory/linked_ptr.h" | 13 #include "base/memory/linked_ptr.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | |
16 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
17 #include "content/browser/renderer_host/image_transport_factory.h" | 16 #include "content/browser/renderer_host/image_transport_factory.h" |
18 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 17 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
19 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
20 #include "third_party/skia/include/core/SkRegion.h" | |
21 #include "ui/aura/client/activation_delegate.h" | 19 #include "ui/aura/client/activation_delegate.h" |
22 #include "ui/aura/window_delegate.h" | 20 #include "ui/aura/window_delegate.h" |
23 #include "ui/base/ime/text_input_client.h" | 21 #include "ui/base/ime/text_input_client.h" |
24 #include "ui/compositor/compositor.h" | |
25 #include "ui/compositor/compositor_observer.h" | 22 #include "ui/compositor/compositor_observer.h" |
26 #include "ui/gfx/display_observer.h" | 23 #include "ui/gfx/display_observer.h" |
27 #include "ui/gfx/rect.h" | 24 #include "ui/gfx/rect.h" |
28 #include "webkit/glue/webcursor.h" | 25 #include "webkit/glue/webcursor.h" |
29 | 26 |
30 namespace aura { | 27 namespace aura { |
31 class WindowTracker; | 28 class WindowTracker; |
32 } | 29 } |
33 | 30 |
34 namespace gfx { | 31 namespace gfx { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 skia::PlatformBitmap* output) OVERRIDE; | 114 skia::PlatformBitmap* output) OVERRIDE; |
118 virtual void OnAcceleratedCompositingStateChange() OVERRIDE; | 115 virtual void OnAcceleratedCompositingStateChange() OVERRIDE; |
119 virtual void AcceleratedSurfaceBuffersSwapped( | 116 virtual void AcceleratedSurfaceBuffersSwapped( |
120 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel, | 117 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel, |
121 int gpu_host_id) OVERRIDE; | 118 int gpu_host_id) OVERRIDE; |
122 virtual void AcceleratedSurfacePostSubBuffer( | 119 virtual void AcceleratedSurfacePostSubBuffer( |
123 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel, | 120 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel, |
124 int gpu_host_id) OVERRIDE; | 121 int gpu_host_id) OVERRIDE; |
125 virtual void AcceleratedSurfaceSuspend() OVERRIDE; | 122 virtual void AcceleratedSurfaceSuspend() OVERRIDE; |
126 virtual bool HasAcceleratedSurface(const gfx::Size& desired_size) OVERRIDE; | 123 virtual bool HasAcceleratedSurface(const gfx::Size& desired_size) OVERRIDE; |
127 virtual void AcceleratedSurfaceNew(int32 width_in_pixel, | 124 virtual void AcceleratedSurfaceNew( |
128 int32 height_in_pixel, | 125 int32 width_in_pixel, |
129 uint64 surface_id, | 126 int32 height_in_pixel, |
130 const std::string& mailbox_name) OVERRIDE; | 127 uint64 surface_id) OVERRIDE; |
131 virtual void AcceleratedSurfaceRelease() OVERRIDE; | 128 virtual void AcceleratedSurfaceRelease(uint64 surface_id) OVERRIDE; |
132 virtual void GetScreenInfo(WebKit::WebScreenInfo* results) OVERRIDE; | 129 virtual void GetScreenInfo(WebKit::WebScreenInfo* results) OVERRIDE; |
133 virtual gfx::Rect GetBoundsInRootWindow() OVERRIDE; | 130 virtual gfx::Rect GetBoundsInRootWindow() OVERRIDE; |
134 virtual void ProcessAckedTouchEvent( | 131 virtual void ProcessAckedTouchEvent( |
135 const WebKit::WebTouchEvent& touch, | 132 const WebKit::WebTouchEvent& touch, |
136 InputEventAckState ack_result) OVERRIDE; | 133 InputEventAckState ack_result) OVERRIDE; |
137 virtual void SetHasHorizontalScrollbar( | 134 virtual void SetHasHorizontalScrollbar( |
138 bool has_horizontal_scrollbar) OVERRIDE; | 135 bool has_horizontal_scrollbar) OVERRIDE; |
139 virtual void SetScrollOffsetPinning( | 136 virtual void SetScrollOffsetPinning( |
140 bool is_pinned_to_left, bool is_pinned_to_right) OVERRIDE; | 137 bool is_pinned_to_left, bool is_pinned_to_right) OVERRIDE; |
141 virtual gfx::GLSurfaceHandle GetCompositingSurface() OVERRIDE; | 138 virtual gfx::GLSurfaceHandle GetCompositingSurface() OVERRIDE; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 virtual void OnCompositingAborted(ui::Compositor* compositor) OVERRIDE; | 224 virtual void OnCompositingAborted(ui::Compositor* compositor) OVERRIDE; |
228 virtual void OnCompositingLockStateChanged( | 225 virtual void OnCompositingLockStateChanged( |
229 ui::Compositor* compositor) OVERRIDE; | 226 ui::Compositor* compositor) OVERRIDE; |
230 | 227 |
231 // Overridden from ImageTransportFactoryObserver: | 228 // Overridden from ImageTransportFactoryObserver: |
232 virtual void OnLostResources() OVERRIDE; | 229 virtual void OnLostResources() OVERRIDE; |
233 | 230 |
234 virtual ~RenderWidgetHostViewAura(); | 231 virtual ~RenderWidgetHostViewAura(); |
235 | 232 |
236 void UpdateCursorIfOverSelf(); | 233 void UpdateCursorIfOverSelf(); |
237 bool ShouldSkipFrame(const gfx::Size& size); | 234 bool ShouldFastACK(uint64 surface_id); |
238 void UpdateExternalTexture(); | 235 void UpdateExternalTexture(); |
239 ui::InputMethod* GetInputMethod() const; | 236 ui::InputMethod* GetInputMethod() const; |
240 | 237 |
241 // Returns whether the widget needs an input grab to work properly. | 238 // Returns whether the widget needs an input grab to work properly. |
242 bool NeedsInputGrab(); | 239 bool NeedsInputGrab(); |
243 | 240 |
244 // Confirm existing composition text in the webpage and ask the input method | 241 // Confirm existing composition text in the webpage and ask the input method |
245 // to cancel its ongoing composition session. | 242 // to cancel its ongoing composition session. |
246 void FinishImeCompositionSession(); | 243 void FinishImeCompositionSession(); |
247 | 244 |
248 // This method computes movementX/Y and keeps track of mouse location for | 245 // This method computes movementX/Y and keeps track of mouse location for |
249 // mouse lock on all mouse move events. | 246 // mouse lock on all mouse move events. |
250 void ModifyEventMovementAndCoords(WebKit::WebMouseEvent* event); | 247 void ModifyEventMovementAndCoords(WebKit::WebMouseEvent* event); |
251 | 248 |
252 // If |clip| is non-empty and and doesn't contain |rect| or |clip| is empty | 249 // If |clip| is non-empty and and doesn't contain |rect| or |clip| is empty |
253 // SchedulePaint() is invoked for |rect|. | 250 // SchedulePaint() is invoked for |rect|. |
254 void SchedulePaintIfNotInClip(const gfx::Rect& rect, const gfx::Rect& clip); | 251 void SchedulePaintIfNotInClip(const gfx::Rect& rect, const gfx::Rect& clip); |
255 | 252 |
256 // Helper method to determine if, in mouse locked mode, the cursor should be | 253 // Helper method to determine if, in mouse locked mode, the cursor should be |
257 // moved to center. | 254 // moved to center. |
258 bool ShouldMoveToCenter(); | 255 bool ShouldMoveToCenter(); |
259 | 256 |
260 // Run the compositing callbacks. | 257 // Run the compositing callbacks. |
261 void RunCompositingDidCommitCallbacks(); | 258 void RunCompositingDidCommitCallbacks(ui::Compositor* compositor); |
262 | |
263 struct BufferPresentedParams { | |
264 BufferPresentedParams(int route_id, | |
265 int gpu_host_id, | |
266 uint64 surface_handle); | |
267 ~BufferPresentedParams(); | |
268 | |
269 int32 route_id; | |
270 int gpu_host_id; | |
271 uint64 surface_handle; | |
272 scoped_refptr<ui::Texture> texture_to_produce; | |
273 }; | |
274 | 259 |
275 // Insert a sync point into the compositor's command stream and acknowledge | 260 // Insert a sync point into the compositor's command stream and acknowledge |
276 // that we have presented the accelerated surface buffer. | 261 // that we have presented the accelerated surface buffer. |
277 static void InsertSyncPointAndACK(const BufferPresentedParams& params); | 262 static void InsertSyncPointAndACK(int32 route_id, |
| 263 int gpu_host_id, |
| 264 bool presented, |
| 265 ui::Compositor* compositor); |
278 | 266 |
279 // Called when window_ gets added to a new window tree. | 267 // Called when window_ gets added to a new window tree. |
280 void AddingToRootWindow(); | 268 void AddingToRootWindow(); |
281 | 269 |
282 // Called when window_ is removed from the window tree. | 270 // Called when window_ is removed from the window tree. |
283 void RemovingFromRootWindow(); | 271 void RemovingFromRootWindow(); |
284 | 272 |
285 // Called after commit for the last reference to the texture going away | 273 // After clearing |current_surface_|, and waiting for the compositor to finish |
286 // after it was released as the frontbuffer. | 274 // using it, call this to inform the gpu process. |
287 void SetSurfaceNotInUseByCompositor(scoped_refptr<ui::Texture>); | 275 void SetSurfaceNotInUseByCompositor(ui::Compositor* compositor); |
| 276 |
| 277 // This is called every time |current_surface_| usage changes (by thumbnailer, |
| 278 // compositor draws, and tab visibility). Every time usage of current surface |
| 279 // changes between "may be used" and "certain to not be used" by the ui, we |
| 280 // inform the gpu process. |
| 281 void AdjustSurfaceProtection(); |
288 | 282 |
289 // Called after async thumbnailer task completes. Used to call | 283 // Called after async thumbnailer task completes. Used to call |
290 // AdjustSurfaceProtection. | 284 // AdjustSurfaceProtection. |
291 static void CopyFromCompositingSurfaceFinished( | 285 static void CopyFromCompositingSurfaceFinished( |
292 base::WeakPtr<RenderWidgetHostViewAura> render_widget_host_view, | 286 base::WeakPtr<RenderWidgetHostViewAura> render_widget_host_view, |
293 const base::Callback<void(bool)>& callback, | 287 const base::Callback<void(bool)>& callback, |
294 bool result); | 288 bool result); |
295 | 289 |
296 ui::Compositor* GetCompositor(); | 290 ui::Compositor* GetCompositor(); |
297 | 291 |
298 // Detaches |this| from the input method object. | 292 // Detaches |this| from the input method object. |
299 void DetachFromInputMethod(); | 293 void DetachFromInputMethod(); |
300 | 294 |
301 // Converts |rect| from window coordinate to screen coordinate. | 295 // Converts |rect| from window coordinate to screen coordinate. |
302 gfx::Rect ConvertRectToScreen(const gfx::Rect& rect); | 296 gfx::Rect ConvertRectToScreen(const gfx::Rect& rect); |
303 | 297 |
304 bool SwapBuffersPrepare(const gfx::Rect& surface_rect, | |
305 const gfx::Rect& damage_rect, | |
306 BufferPresentedParams* params); | |
307 | |
308 void SwapBuffersCompleted(const BufferPresentedParams& params); | |
309 | |
310 // The model object. | 298 // The model object. |
311 RenderWidgetHostImpl* host_; | 299 RenderWidgetHostImpl* host_; |
312 | 300 |
313 aura::Window* window_; | 301 aura::Window* window_; |
314 | 302 |
315 scoped_ptr<WindowObserver> window_observer_; | 303 scoped_ptr<WindowObserver> window_observer_; |
316 | 304 |
317 // Are we in the process of closing? Tracked so fullscreen views can avoid | 305 // Are we in the process of closing? Tracked so fullscreen views can avoid |
318 // sending a second shutdown request to the host when they lose the focus | 306 // sending a second shutdown request to the host when they lose the focus |
319 // after requesting shutdown for another reason (e.g. Escape key). | 307 // after requesting shutdown for another reason (e.g. Escape key). |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 | 340 |
353 // Indicates if there is onging composition text. | 341 // Indicates if there is onging composition text. |
354 bool has_composition_text_; | 342 bool has_composition_text_; |
355 | 343 |
356 // Current tooltip text. | 344 // Current tooltip text. |
357 string16 tooltip_; | 345 string16 tooltip_; |
358 | 346 |
359 // The scale factor of the display the renderer is currently on. | 347 // The scale factor of the display the renderer is currently on. |
360 float device_scale_factor_; | 348 float device_scale_factor_; |
361 | 349 |
362 std::vector<base::Closure> on_compositing_did_commit_callbacks_; | 350 std::vector< base::Callback<void(ui::Compositor*)> > |
| 351 on_compositing_did_commit_callbacks_; |
363 | 352 |
364 std::map<uint64, scoped_refptr<ui::Texture> > image_transport_clients_; | 353 std::map<uint64, scoped_refptr<ui::Texture> > |
| 354 image_transport_clients_; |
365 | 355 |
366 // The identifier of the current frontbuffer. | |
367 uint64 current_surface_; | 356 uint64 current_surface_; |
368 | 357 |
369 // The damage in the previously presented buffer. | 358 // Protected means that the |current_surface_| may be in use by ui and cannot |
370 SkRegion previous_damage_; | 359 // be safely discarded. Things to consider are thumbnailer, compositor draw, |
371 | 360 // and tab visibility. |
372 // Pending damage from previous frames that we skipped. | 361 bool current_surface_is_protected_; |
373 SkRegion skipped_damage_; | 362 bool current_surface_in_use_by_compositor_; |
374 | |
375 // The size of the last frame that was swapped (even if we skipped it). | |
376 // Used to determine when the skipped_damage_ needs to be reset due to | |
377 // size changes between front- and backbuffer. | |
378 gfx::Size last_swapped_surface_size_; | |
379 | 363 |
380 int pending_thumbnail_tasks_; | 364 int pending_thumbnail_tasks_; |
381 | 365 |
| 366 // This id increments every time surface_is_protected changes. We tag IPC |
| 367 // messages which rely on protection state with this id to stay in sync. |
| 368 uint32 protection_state_id_; |
| 369 |
| 370 int32 surface_route_id_; |
| 371 |
382 gfx::GLSurfaceHandle shared_surface_handle_; | 372 gfx::GLSurfaceHandle shared_surface_handle_; |
383 | 373 |
384 // If non-NULL we're in OnPaint() and this is the supplied canvas. | 374 // If non-NULL we're in OnPaint() and this is the supplied canvas. |
385 gfx::Canvas* paint_canvas_; | 375 gfx::Canvas* paint_canvas_; |
386 | 376 |
387 // Used to record the last position of the mouse. | 377 // Used to record the last position of the mouse. |
388 // While the mouse is locked, they store the last known position just as mouse | 378 // While the mouse is locked, they store the last known position just as mouse |
389 // lock was entered. | 379 // lock was entered. |
390 // Relative to the upper-left corner of the view. | 380 // Relative to the upper-left corner of the view. |
391 gfx::Point unlocked_mouse_position_; | 381 gfx::Point unlocked_mouse_position_; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 NO_PENDING_COMMIT, | 421 NO_PENDING_COMMIT, |
432 }; | 422 }; |
433 CanLockCompositorState can_lock_compositor_; | 423 CanLockCompositorState can_lock_compositor_; |
434 | 424 |
435 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAura); | 425 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAura); |
436 }; | 426 }; |
437 | 427 |
438 } // namespace content | 428 } // namespace content |
439 | 429 |
440 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_AURA_H_ | 430 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_AURA_H_ |
OLD | NEW |