Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / browser / renderer_host / display_link_mac.h
blob1833f8f2d3fee60474bb9bb9e4655aaeb9d09169
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 static CVReturn DisplayLinkCallback(
43 CVDisplayLinkRef display_link,
44 const CVTimeStamp* now,
45 const CVTimeStamp* output_time,
46 CVOptionFlags flags_in,
47 CVOptionFlags* flags_out,
48 void* context);
50 // The display that this display link is attached to.
51 CGDirectDisplayID display_id_;
53 // CVDisplayLink for querying VSync timing info.
54 base::ScopedTypeRef<CVDisplayLinkRef> display_link_;
56 // Timer for stopping the display link if it has not been queried in
57 // the last second.
58 base::DelayTimer<DisplayLinkMac> stop_timer_;
60 // VSync parameters computed during Tick.
61 bool timebase_and_interval_valid_;
62 base::TimeTicks timebase_;
63 base::TimeDelta interval_;
65 // Lock for sharing data between UI thread and display-link thread.
66 base::Lock lock_;
68 // Each display link instance consumes a non-negligible number of cycles, so
69 // make all display links on the same screen share the same object.
70 typedef std::map<CGDirectDisplayID, DisplayLinkMac*> DisplayMap;
71 static base::LazyInstance<DisplayMap> display_map_;
74 } // content
76 #endif // CONTENT_BROWSER_RENDERER_HOST_DISPLAY_LINK_MAC_H_