Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / content / browser / renderer_host / display_link_mac.h
blob479e06422988bd6b58eb784cdab93fec7376a974
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 CONTENT_BROWSER_RENDERER_HOST_DISPLAY_LINK_MAC_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_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"
18 namespace content {
20 class DisplayLinkMac : public base::RefCounted<DisplayLinkMac> {
21 public:
22 static scoped_refptr<DisplayLinkMac> GetForDisplay(
23 CGDirectDisplayID display_id);
25 // Get vsync scheduling parameters.
26 bool GetVSyncParameters(
27 base::TimeTicks* timebase,
28 base::TimeDelta* interval);
30 private:
31 friend class base::RefCounted<DisplayLinkMac>;
33 DisplayLinkMac(
34 CGDirectDisplayID display_id,
35 base::ScopedTypeRef<CVDisplayLinkRef> display_link);
36 virtual ~DisplayLinkMac();
38 void StartOrContinueDisplayLink();
39 void StopDisplayLink();
40 void Tick(const CVTimeStamp& time);
42 // Called by the system on the display link thread, and posts a call to Tick
43 // to the UI thread.
44 static CVReturn DisplayLinkCallback(
45 CVDisplayLinkRef display_link,
46 const CVTimeStamp* now,
47 const CVTimeStamp* output_time,
48 CVOptionFlags flags_in,
49 CVOptionFlags* flags_out,
50 void* context);
52 // This is called whenever the display is reconfigured, and marks that the
53 // vsync parameters must be recalculated.
54 static void DisplayReconfigurationCallBack(
55 CGDirectDisplayID display,
56 CGDisplayChangeSummaryFlags flags,
57 void* user_info);
59 // The display that this display link is attached to.
60 CGDirectDisplayID display_id_;
62 // CVDisplayLink for querying VSync timing info.
63 base::ScopedTypeRef<CVDisplayLinkRef> display_link_;
65 // VSync parameters computed during Tick.
66 bool timebase_and_interval_valid_;
67 base::TimeTicks timebase_;
68 base::TimeDelta interval_;
70 // Each display link instance consumes a non-negligible number of cycles, so
71 // make all display links on the same screen share the same object.
72 typedef std::map<CGDirectDisplayID, DisplayLinkMac*> DisplayMap;
73 static base::LazyInstance<DisplayMap> display_map_;
76 } // content
78 #endif // CONTENT_BROWSER_RENDERER_HOST_DISPLAY_LINK_MAC_H_