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

Side by Side Diff: ui/accelerated_widget_mac/window_resize_helper_mac.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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef UI_ACCELERATED_WIDGET_MAC_WINDOW_RESIZE_HELPER_MAC_H_
6 #define UI_ACCELERATED_WIDGET_MAC_WINDOW_RESIZE_HELPER_MAC_H_
7
8 #include "base/lazy_instance.h"
9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h"
11 #include "ui/accelerated_widget_mac/accelerated_widget_mac_export.h"
12
13 namespace base {
14 class SingleThreadTaskRunner;
15 class TimeDelta;
16 class WaitableEvent;
17 }
18
19 namespace ui {
20
21 // WindowResizeHelperMac 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
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
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
27 // by calling WindowResizeHelperMac::WaitForSingleTaskToRun() until a timeout
28 // occurs, or the corresponding AcceleratedWidgetMac has a renderer frame of the
29 // same size as its NSView.
30 //
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
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
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
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.
39 //
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,
42 // the task_runner() that WindowResizeHelperMac provides can be used to
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
45 // WindowResizeHelperMac::WaitForSingleTaskToRun().
46 class ACCELERATED_WIDGET_MAC_EXPORT WindowResizeHelperMac {
47 public:
48 static WindowResizeHelperMac* Get();
49
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,
52 // and WaitForSingleTaskToRun() will immediately return false.
53 void Init(
54 const scoped_refptr<base::SingleThreadTaskRunner>& target_task_runner);
55
56 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const;
57
58 // UI THREAD ONLY -----------------------------------------------------------
59
60 // Waits at most |max_delay| for a task to run. Returns true if a task ran,
61 // false if no task ran.
62 bool WaitForSingleTaskToRun(const base::TimeDelta& max_delay);
63
64 private:
65 friend struct base::DefaultLazyInstanceTraits<WindowResizeHelperMac>;
66 WindowResizeHelperMac();
67 ~WindowResizeHelperMac();
68
69 // This helper is needed to create a ScopedAllowWait inside the scope of a
70 // class where it is allowed.
71 static void EventTimedWait(base::WaitableEvent* event, base::TimeDelta delay);
72
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.
75 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
76
77 DISALLOW_COPY_AND_ASSIGN(WindowResizeHelperMac);
78 };
79
80 } // namespace ui
81
82 #endif // UI_ACCELERATED_WIDGET_MAC_WINDOW_RESIZE_HELPER_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698