Fix issue with longpress drag selection motion
[chromium-blink-merge.git] / ui / accelerated_widget_mac / display_link_mac.h
blob1ec7a7200cf3528ce11a428e32ac11c4efeda6fa
1 // Copyright 2014 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.
5 #ifndef UI_ACCELERATED_WIDGET_MAC_DISPLAY_LINK_MAC_H_
6 #define UI_ACCELERATED_WIDGET_MAC_DISPLAY_LINK_MAC_H_
8 #include <QuartzCore/CVDisplayLink.h>
9 #include <map>
11 #include "base/lazy_instance.h"
12 #include "base/mac/scoped_typeref.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/synchronization/lock.h"
15 #include "base/time/time.h"
16 #include "base/timer/timer.h"
17 #include "ui/accelerated_widget_mac/accelerated_widget_mac_export.h"
19 namespace ui {
21 class ACCELERATED_WIDGET_MAC_EXPORT DisplayLinkMac :
22 public base::RefCounted<DisplayLinkMac> {
23 public:
24 static scoped_refptr<DisplayLinkMac> GetForDisplay(
25 CGDirectDisplayID display_id);
27 // Get vsync scheduling parameters.
28 bool GetVSyncParameters(
29 base::TimeTicks* timebase,
30 base::TimeDelta* interval);
32 private:
33 friend class base::RefCounted<DisplayLinkMac>;
35 DisplayLinkMac(
36 CGDirectDisplayID display_id,
37 base::ScopedTypeRef<CVDisplayLinkRef> display_link);
38 virtual ~DisplayLinkMac();
40 void StartOrContinueDisplayLink();
41 void StopDisplayLink();
42 void Tick(const CVTimeStamp& time);
44 // Called by the system on the display link thread, and posts a call to Tick
45 // to the UI thread.
46 static CVReturn DisplayLinkCallback(
47 CVDisplayLinkRef display_link,
48 const CVTimeStamp* now,
49 const CVTimeStamp* output_time,
50 CVOptionFlags flags_in,
51 CVOptionFlags* flags_out,
52 void* context);
54 // This is called whenever the display is reconfigured, and marks that the
55 // vsync parameters must be recalculated.
56 static void DisplayReconfigurationCallBack(
57 CGDirectDisplayID display,
58 CGDisplayChangeSummaryFlags flags,
59 void* user_info);
61 // The task runner to post tasks to from the display link thread.
62 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
64 // The display that this display link is attached to.
65 CGDirectDisplayID display_id_;
67 // CVDisplayLink for querying VSync timing info.
68 base::ScopedTypeRef<CVDisplayLinkRef> display_link_;
70 // VSync parameters computed during Tick.
71 bool timebase_and_interval_valid_;
72 base::TimeTicks timebase_;
73 base::TimeDelta interval_;
75 // Each display link instance consumes a non-negligible number of cycles, so
76 // make all display links on the same screen share the same object.
77 typedef std::map<CGDirectDisplayID, DisplayLinkMac*> DisplayMap;
78 static base::LazyInstance<DisplayMap> display_map_;
81 } // ui
83 #endif // UI_ACCELERATED_WIDGET_MAC_DISPLAY_LINK_MAC_H_