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

Side by Side Diff: content/browser/renderer_host/display_link_mac.cc

Issue 147493011: Use base::ScopedTypeRef for CGL types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase again Created 6 years, 10 months 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 2014 The Chromium Authors. All rights reserved. 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 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 #include "content/browser/renderer_host/display_link_mac.h" 5 #include "content/browser/renderer_host/display_link_mac.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 9
10 namespace base {
11
12 template<>
13 struct ScopedTypeRefTraits<CVDisplayLinkRef> {
14 static void Retain(CVDisplayLinkRef object) {
15 CVDisplayLinkRetain(object);
16 }
17 static void Release(CVDisplayLinkRef object) {
18 CVDisplayLinkRelease(object);
19 }
20 };
21
22 } // namespace base
23
10 namespace content { 24 namespace content {
11 25
12 // static 26 // static
13 scoped_refptr<DisplayLinkMac> DisplayLinkMac::Create() { 27 scoped_refptr<DisplayLinkMac> DisplayLinkMac::Create() {
14 CVReturn ret = kCVReturnSuccess; 28 CVReturn ret = kCVReturnSuccess;
15 29
30 base::ScopedTypeRef<CVDisplayLinkRef> display_link;
31 ret = CVDisplayLinkCreateWithActiveCGDisplays(display_link.InitializeInto());
32 if (ret != kCVReturnSuccess) {
33 LOG(ERROR) << "CVDisplayLinkCreateWithActiveCGDisplays failed: " << ret;
34 return NULL;
35 }
36
16 scoped_refptr<DisplayLinkMac> display_link_mac; 37 scoped_refptr<DisplayLinkMac> display_link_mac;
17 { 38 display_link_mac = new DisplayLinkMac(display_link);
18 CVDisplayLinkRef display_link = NULL;
19 ret = CVDisplayLinkCreateWithActiveCGDisplays(&display_link);
20 if (ret != kCVReturnSuccess) {
21 LOG(ERROR) << "CVDisplayLinkCreateWithActiveCGDisplays failed: " << ret;
22 return NULL;
23 }
24 display_link_mac = new DisplayLinkMac(display_link);
25 }
26 39
27 ret = CVDisplayLinkSetOutputCallback( 40 ret = CVDisplayLinkSetOutputCallback(
28 display_link_mac->display_link_, 41 display_link_mac->display_link_,
29 &DisplayLinkCallback, 42 &DisplayLinkCallback,
30 display_link_mac.get()); 43 display_link_mac.get());
31 if (ret != kCVReturnSuccess) { 44 if (ret != kCVReturnSuccess) {
32 LOG(ERROR) << "CVDisplayLinkSetOutputCallback failed: " << ret; 45 LOG(ERROR) << "CVDisplayLinkSetOutputCallback failed: " << ret;
33 return NULL; 46 return NULL;
34 } 47 }
35 48
36 return display_link_mac; 49 return display_link_mac;
37 } 50 }
38 51
39 DisplayLinkMac::DisplayLinkMac(CVDisplayLinkRef display_link) 52 DisplayLinkMac::DisplayLinkMac(
40 : display_link_(display_link), 53 base::ScopedTypeRef<CVDisplayLinkRef> display_link)
41 stop_timer_( 54 : display_link_(display_link),
42 FROM_HERE, base::TimeDelta::FromSeconds(1), 55 stop_timer_(
43 this, &DisplayLinkMac::StopDisplayLink), 56 FROM_HERE, base::TimeDelta::FromSeconds(1),
44 timebase_and_interval_valid_(false) { 57 this, &DisplayLinkMac::StopDisplayLink),
58 timebase_and_interval_valid_(false) {
45 } 59 }
46 60
47 DisplayLinkMac::~DisplayLinkMac() { 61 DisplayLinkMac::~DisplayLinkMac() {
48 if (CVDisplayLinkIsRunning(display_link_)) 62 if (CVDisplayLinkIsRunning(display_link_))
49 CVDisplayLinkStop(display_link_); 63 CVDisplayLinkStop(display_link_);
50 CVDisplayLinkRelease(display_link_);
51 } 64 }
52 65
53 bool DisplayLinkMac::GetVSyncParameters( 66 bool DisplayLinkMac::GetVSyncParameters(
54 base::TimeTicks* timebase, base::TimeDelta* interval) { 67 base::TimeTicks* timebase, base::TimeDelta* interval) {
55 StartOrContinueDisplayLink(); 68 StartOrContinueDisplayLink();
56 69
57 base::AutoLock lock(lock_); 70 base::AutoLock lock(lock_);
58 if (!timebase_and_interval_valid_) 71 if (!timebase_and_interval_valid_)
59 return false; 72 return false;
60 73
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 CVOptionFlags flags_in, 129 CVOptionFlags flags_in,
117 CVOptionFlags* flags_out, 130 CVOptionFlags* flags_out,
118 void* context) { 131 void* context) {
119 DisplayLinkMac* display_link_mac = static_cast<DisplayLinkMac*>(context); 132 DisplayLinkMac* display_link_mac = static_cast<DisplayLinkMac*>(context);
120 display_link_mac->Tick(output_time); 133 display_link_mac->Tick(output_time);
121 return kCVReturnSuccess; 134 return kCVReturnSuccess;
122 } 135 }
123 136
124 } // content 137 } // content
125 138
OLDNEW
« no previous file with comments | « content/browser/renderer_host/display_link_mac.h ('k') | content/browser/renderer_host/render_widget_host_view_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698