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

Side by Side Diff: ui/accelerated_widget_mac/window_resize_helper_mac.h

Issue 1354533002: Mac: move content::RenderWidgetResizeHelper to ui::WindowResizeHelperMac (acelerated_widget_mac) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_RESIZE_HELPER_MAC_H_ 5 #ifndef UI_ACCELERATED_WIDGET_MAC_WINDOW_RESIZE_HELPER_MAC_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_RESIZE_HELPER_MAC_H_ 6 #define UI_ACCELERATED_WIDGET_MAC_WINDOW_RESIZE_HELPER_MAC_H_
7 7
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/macros.h"
10 #include "base/synchronization/lock.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/synchronization/waitable_event.h" 11 #include "ui/accelerated_widget_mac/accelerated_widget_mac_export.h"
12 #include "ipc/ipc_message.h"
13 12
14 namespace content { 13 namespace base {
14 class SingleThreadTaskRunner;
15 class TimeDelta;
16 class WaitableEvent;
17 }
15 18
16 // RenderWidgetResizeHelper is used to make resize appear smooth. That is to 19 namespace ui {
20
21 // WindowResizeHelperMac is used to make resize appear smooth. That is to
17 // say, make sure that the window size and the size of the content being drawn 22 // say, make sure that the window size and the size of the content being drawn
18 // in that window are resized in lock-step. This is accomplished by waiting 23 // in that window are resized in lock-step. This is accomplished by waiting
19 // inside -[RenderWidgetHostViewCocoa setFrameSize:] for the renderer (and 24 // inside AppKit drawing routines on the UI thread for the compositor to produce
20 // potentially browser compositor as well) to produce a frame of same size 25 // a frame of same size as the NSView that hosts an AcceleratedWidgetMac.
21 // as the RenderWidgetHostViewCocoa.
22 // 26 //
23 // The function of waiting for a frame of the correct size is done inside 27 // For RenderWidgets, waiting for a frame of the correct size is done inside
24 // RenderWidgetHostImpl::WaitForSurface. That function will call 28 // RenderWidgetHostImpl::WaitForSurface. That function will call
25 // RenderWidgetResizeHelper::WaitForSingleTaskToRun until a timeout occurs, 29 // WindowResizeHelperMac::WaitForSingleTaskToRun until a timeout occurs,
26 // or the corresponding RenderWidgetHostViewCocoa has a renderer frame of the 30 // or the corresponding AcceleratedWidgetMac has a renderer frame of the
27 // same size as its NSView. 31 // same size as its NSView.
28 // 32 //
29 // This is somewhat complicated because waiting for frames requires that 33 // This is somewhat complicated because waiting for frames requires that
30 // that the browser handle the IPCs (from the renderer and the GPU processes) 34 // that the browser handle the IPCs (from the renderer and the GPU processes)
31 // that are required to pick up a new frame. In the ordinary run of things 35 // that are required to pick up a new frame. In the ordinary run of things
32 // (ignoring RenderWidgetResizeHelper), those IPCs arrive on the IO thread 36 // (ignoring WindowResizeHelperMac), those IPCs arrive on the IO thread
33 // and are posted as tasks to the UI thread either by the RenderMessageFilter 37 // and are posted as tasks to the UI thread either by the RenderMessageFilter
34 // (for renderer processes) or the GpuProcessHostUIShim (for the GPU process). 38 // (for renderer processes) or the GpuProcessHostUIShim (for the GPU process).
39 //
40 // To synchronize these processes, content uses RenderWidgetResizeHelper.
35 // The IPCs that are required to create new frames for smooth resize are sent 41 // The IPCs that are required to create new frames for smooth resize are sent
36 // to the RenderWidgetResizeHelper using the PostRendererProcessMsg and 42 // to the RenderWidgetResizeHelper using the PostRendererProcessMsg and
37 // PostGpuProcessMsg methods. These functions will post them as tasks to the UI 43 // PostGpuProcessMsg methods. These functions will post them as tasks to the UI
38 // thread (as usual), and will also enqueue them into a queue which will be 44 // thread (as usual), and will also enqueue them into a queue which will be
39 // read and run in RenderWidgetResizeHelper::WaitForSingleTaskToRun, potentially 45 // read and run in WindowResizeHelperMac::WaitForSingleTaskToRun, potentially
40 // before the task posted to the UI thread is run. Some care is taken (see 46 // before the task posted to the UI thread is run. Some care is taken (see
41 // WrappedTask) to make sure that the messages are only executed once. 47 // WrappedTask) to make sure that the messages are only executed once.
42 // 48 //
43 // This is further complicated because, in order for a frame to appear, it is 49 // This is further complicated because, in order for a frame to appear, it is
44 // necessary to run tasks posted by the ui::Compositor. To accomplish this, the 50 // necessary to run tasks posted by the ui::Compositor. To accomplish this, the
45 // RenderWidgetResizeHelper provides a base::SingleThreadTaskRunner which, 51 // WindowResizeHelperMac provides a base::SingleThreadTaskRunner which,
46 // when a task is posted to it, enqueues the task in the aforementioned queue, 52 // when a task is posted to it, enqueues the task in the aforementioned queue,
47 // which may be pumped by RenderWidgetResizeHelper::WaitForSingleTaskToRun. 53 // which may be pumped by WindowResizeHelperMac::WaitForSingleTaskToRun.
48 // 54 class ACCELERATED_WIDGET_MAC_EXPORT WindowResizeHelperMac {
49 class RenderWidgetResizeHelper {
50 public: 55 public:
51 static RenderWidgetResizeHelper* Get(); 56 static WindowResizeHelperMac* Get();
57
58 // Initializes the pumpable task_runner(), providing it with the task runner
59 // for UI thread tasks. task_runner() will be null before Init() is called,
60 // and WaitForSingleTaskToRun() will immediately return false.
61 void Init(
62 const scoped_refptr<base::SingleThreadTaskRunner>& target_task_runner);
63
52 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const; 64 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const;
53 65
54 // UI THREAD ONLY ----------------------------------------------------------- 66 // UI THREAD ONLY -----------------------------------------------------------
55 67
56 // Waits at most |max_delay| for a task to run. Returns true if a task ran, 68 // Waits at most |max_delay| for a task to run. Returns true if a task ran,
57 // false if no task ran. 69 // false if no task ran.
58 bool WaitForSingleTaskToRun(const base::TimeDelta& max_delay); 70 bool WaitForSingleTaskToRun(const base::TimeDelta& max_delay);
59 71
60 // IO THREAD ONLY -----------------------------------------------------------
61
62 // This will cause |msg| to be handled by the RenderProcessHost corresponding
63 // to |render_process_id|, on the UI thread. This will either happen when the
64 // ordinary message loop would run it, or potentially earlier in a call to
65 // WaitForSingleTaskToRun .
66 void PostRendererProcessMsg(int render_process_id, const IPC::Message& msg);
67
68 // This is similar to PostRendererProcessMsg, but will handle the message in
69 // the GpuProcessHostUIShim corresponding to |gpu_host_id|.
70 void PostGpuProcessMsg(int gpu_host_id, const IPC::Message& msg);
71
72 private: 72 private:
73 friend struct base::DefaultLazyInstanceTraits<RenderWidgetResizeHelper>; 73 friend struct base::DefaultLazyInstanceTraits<WindowResizeHelperMac>;
74 RenderWidgetResizeHelper(); 74 WindowResizeHelperMac();
75 ~RenderWidgetResizeHelper(); 75 ~WindowResizeHelperMac();
76 76
77 // This helper is needed to create a ScopedAllowWait inside the scope of a 77 // This helper is needed to create a ScopedAllowWait inside the scope of a
78 // class where it is allowed. 78 // class where it is allowed.
79 static void EventTimedWait(base::WaitableEvent* event, base::TimeDelta delay); 79 static void EventTimedWait(base::WaitableEvent* event, base::TimeDelta delay);
80 80
81 // The task runner to which the helper will post tasks. This also maintains 81 // The task runner to which the helper will post tasks. This also maintains
82 // the task queue and does the actual work for WaitForSingleTaskToRun. 82 // the task queue and does the actual work for WaitForSingleTaskToRun.
83 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 83 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
84 84
85 DISALLOW_COPY_AND_ASSIGN(RenderWidgetResizeHelper); 85 DISALLOW_COPY_AND_ASSIGN(WindowResizeHelperMac);
86 }; 86 };
87 87
88 } // namespace content 88 } // namespace ui
89 89
90 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_RESIZE_HELPER_MAC_H_ 90 #endif // UI_ACCELERATED_WIDGET_MAC_WINDOW_RESIZE_HELPER_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698