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

Side by Side Diff: ui/base/window_resize_helper.h

Issue 1513053002: WIP - Gutterless resize on Windows Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: feedback Created 5 years 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 2015 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 UI_ACCELERATED_WIDGET_MAC_WINDOW_RESIZE_HELPER_MAC_H_ 5 #ifndef UI_BASE_WINDOW_RESIZE_HELPER_H_
6 #define UI_ACCELERATED_WIDGET_MAC_WINDOW_RESIZE_HELPER_MAC_H_ 6 #define UI_BASE_WINDOW_RESIZE_HELPER_H_
7 7
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "ui/accelerated_widget_mac/accelerated_widget_mac_export.h" 11 #include "ui/base/ui_base_export.h"
12 12
13 namespace base { 13 namespace base {
14 class SingleThreadTaskRunner; 14 class SingleThreadTaskRunner;
15 class TimeDelta; 15 class TimeDelta;
16 class WaitableEvent; 16 class WaitableEvent;
17 } 17 }
18 18
19 namespace ui { 19 namespace ui {
20 20
21 // WindowResizeHelperMac is used to make resize appear smooth. That is to 21 // WindowResizeHelper is used to make resize appear smooth. That is to
22 // say, make sure that the window size and the size of the contents being drawn 22 // say, make sure that the window size and the size of the contents being drawn
23 // 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
24 // inside AppKit drawing routines on the UI thread for the compositor to produce 24 // inside AppKit drawing routines on the UI thread for the compositor to produce
25 // a frame of same size as the NSView that hosts an AcceleratedWidgetMac. When a 25 // a frame of same size as the NSView that hosts an AcceleratedWidgetMac. When a
26 // resize occurs, the view controller can wait for a frame of the correct size 26 // resize occurs, the view controller can wait for a frame of the correct size
27 // by calling WindowResizeHelperMac::WaitForSingleTaskToRun() until a timeout 27 // by calling WindowResizeHelper::WaitForSingleTaskToRun() until a timeout
28 // occurs, or the corresponding AcceleratedWidgetMac has a renderer frame of the 28 // occurs, or the corresponding AcceleratedWidgetMac has a renderer frame of the
29 // same size as its NSView. 29 // same size as its NSView.
30 // 30 //
31 // By posting tasks to the custom task_runner(), other threads indicate tasks 31 // By posting tasks to the custom task_runner(), other threads indicate tasks
32 // that are required to pick up a new frame. In the ordinary run of things these 32 // that are required to pick up a new frame. In the ordinary run of things these
33 // would be posted to the |target_task_runner|; the UI thread given as an 33 // would be posted to the |target_task_runner|; the UI thread given as an
34 // argument to Init(). Posting instead to task_runner() will cause the tasks to 34 // argument to Init(). Posting instead to task_runner() will cause the tasks to
35 // be posted to the UI thread (as usual), and will also enqueue them into a 35 // be posted to the UI thread (as usual), and will also enqueue them into a
36 // queue which will be read and run in WaitForSingleTaskToRun(), potentially 36 // queue which will be read and run in WaitForSingleTaskToRun(), potentially
37 // before the task posted to the UI thread is run. Some care is taken (see 37 // before the task posted to the UI thread is run. Some care is taken (see
38 // WrappedTask) to make sure that the messages are only executed once. 38 // WrappedTask) to make sure that the messages are only executed once.
39 // 39 //
40 // This is further complicated because, in order for a frame to appear, it is 40 // This is further complicated because, in order for a frame to appear, it is
41 // also necessary to run tasks posted by the ui::Compositor. To accomplish this, 41 // also necessary to run tasks posted by the ui::Compositor. To accomplish this,
42 // the task_runner() that WindowResizeHelperMac provides can be used to 42 // the task_runner() that WindowResizeHelper provides can be used to
43 // construct a ui::Compositor. When the Compositor posts tasks to it, they are 43 // construct a ui::Compositor. When the Compositor posts tasks to it, they are
44 // enqueued in the aforementioned queue, which may be pumped by 44 // enqueued in the aforementioned queue, which may be pumped by
45 // WindowResizeHelperMac::WaitForSingleTaskToRun(). 45 // WindowResizeHelper::WaitForSingleTaskToRun().
46 class ACCELERATED_WIDGET_MAC_EXPORT WindowResizeHelperMac { 46 class UI_BASE_EXPORT WindowResizeHelper {
47 public: 47 public:
48 static WindowResizeHelperMac* Get(); 48 static WindowResizeHelper* Get();
49 49
50 // Initializes the pumpable task_runner(), providing it with the task runner 50 // Initializes the pumpable task_runner(), providing it with the task runner
51 // for UI thread tasks. task_runner() will be null before Init() is called, 51 // for UI thread tasks. task_runner() will be null before Init() is called,
52 // and WaitForSingleTaskToRun() will immediately return false. 52 // and WaitForSingleTaskToRun() will immediately return false.
53 void Init( 53 void Init(
54 const scoped_refptr<base::SingleThreadTaskRunner>& target_task_runner); 54 const scoped_refptr<base::SingleThreadTaskRunner>& target_task_runner);
55 55
56 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const; 56 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const;
57 57
58 // UI THREAD ONLY ----------------------------------------------------------- 58 // UI THREAD ONLY -----------------------------------------------------------
59 59
60 // Waits at most |max_delay| for a task to run. Returns true if a task ran, 60 // Waits at most |max_delay| for a task to run. Returns true if a task ran,
61 // false if no task ran. 61 // false if no task ran.
62 bool WaitForSingleTaskToRun(const base::TimeDelta& max_delay); 62 bool WaitForSingleTaskToRun(const base::TimeDelta& max_delay);
63 63
64 private: 64 private:
65 friend struct base::DefaultLazyInstanceTraits<WindowResizeHelperMac>; 65 friend struct base::DefaultLazyInstanceTraits<WindowResizeHelper>;
66 WindowResizeHelperMac(); 66 WindowResizeHelper();
67 ~WindowResizeHelperMac(); 67 ~WindowResizeHelper();
68 68
69 // This helper is needed to create a ScopedAllowWait inside the scope of a 69 // This helper is needed to create a ScopedAllowWait inside the scope of a
70 // class where it is allowed. 70 // class where it is allowed.
71 static void EventTimedWait(base::WaitableEvent* event, base::TimeDelta delay); 71 static void EventTimedWait(base::WaitableEvent* event, base::TimeDelta delay);
72 72
73 // The task runner to which the helper will post tasks. This also maintains 73 // The task runner to which the helper will post tasks. This also maintains
74 // the task queue and does the actual work for WaitForSingleTaskToRun. 74 // the task queue and does the actual work for WaitForSingleTaskToRun.
75 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 75 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
76 76
77 DISALLOW_COPY_AND_ASSIGN(WindowResizeHelperMac); 77 DISALLOW_COPY_AND_ASSIGN(WindowResizeHelper);
78 }; 78 };
79 79
80 } // namespace ui 80 } // namespace ui
81 81
82 #endif // UI_ACCELERATED_WIDGET_MAC_WINDOW_RESIZE_HELPER_MAC_H_ 82 #endif // UI_BASE_WINDOW_RESIZE_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698