OLD | NEW |
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 "ui/accelerated_widget_mac/display_link_mac.h" | 5 #include "ui/accelerated_widget_mac/display_link_mac.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 DPLOG_IF(ERROR, register_error != kCGErrorSuccess) | 79 DPLOG_IF(ERROR, register_error != kCGErrorSuccess) |
80 << "CGDisplayRegisterReconfigurationCallback: " | 80 << "CGDisplayRegisterReconfigurationCallback: " |
81 << register_error; | 81 << register_error; |
82 } | 82 } |
83 display_map_.Get().insert(std::make_pair(display_id_, this)); | 83 display_map_.Get().insert(std::make_pair(display_id_, this)); |
84 } | 84 } |
85 | 85 |
86 DisplayLinkMac::~DisplayLinkMac() { | 86 DisplayLinkMac::~DisplayLinkMac() { |
87 StopDisplayLink(); | 87 StopDisplayLink(); |
88 | 88 |
| 89 // Usually |display_link_| holds the last reference to CVDisplayLinkRef, but |
| 90 // that's not guaranteed, so it might not free all resources after the |
| 91 // destructor completes. Ensure the callback is cleared out regardless to |
| 92 // avoid possible crashes (see http://crbug.com/564780). |
| 93 CVReturn ret = |
| 94 CVDisplayLinkSetOutputCallback(display_link_, nullptr, nullptr); |
| 95 DCHECK_EQ(kCGErrorSuccess, ret); |
| 96 |
89 DisplayMap::iterator found = display_map_.Get().find(display_id_); | 97 DisplayMap::iterator found = display_map_.Get().find(display_id_); |
90 DCHECK(found != display_map_.Get().end()); | 98 DCHECK(found != display_map_.Get().end()); |
91 DCHECK(found->second == this); | 99 DCHECK(found->second == this); |
92 display_map_.Get().erase(found); | 100 display_map_.Get().erase(found); |
93 if (display_map_.Get().empty()) { | 101 if (display_map_.Get().empty()) { |
94 CGError remove_error = CGDisplayRemoveReconfigurationCallback( | 102 CGError remove_error = CGDisplayRemoveReconfigurationCallback( |
95 DisplayReconfigurationCallBack, nullptr); | 103 DisplayReconfigurationCallBack, nullptr); |
96 DPLOG_IF(ERROR, remove_error != kCGErrorSuccess) | 104 DPLOG_IF(ERROR, remove_error != kCGErrorSuccess) |
97 << "CGDisplayRemoveReconfigurationCallback: " | 105 << "CGDisplayRemoveReconfigurationCallback: " |
98 << remove_error; | 106 << remove_error; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 DisplayLinkMac* display_link_mac = found->second; | 197 DisplayLinkMac* display_link_mac = found->second; |
190 display_link_mac->timebase_and_interval_valid_ = false; | 198 display_link_mac->timebase_and_interval_valid_ = false; |
191 } | 199 } |
192 | 200 |
193 // static | 201 // static |
194 base::LazyInstance<DisplayLinkMac::DisplayMap> | 202 base::LazyInstance<DisplayLinkMac::DisplayMap> |
195 DisplayLinkMac::display_map_ = LAZY_INSTANCE_INITIALIZER; | 203 DisplayLinkMac::display_map_ = LAZY_INSTANCE_INITIALIZER; |
196 | 204 |
197 } // ui | 205 } // ui |
198 | 206 |
OLD | NEW |