| 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 | |
| 97 DisplayMap::iterator found = display_map_.Get().find(display_id_); | 89 DisplayMap::iterator found = display_map_.Get().find(display_id_); |
| 98 DCHECK(found != display_map_.Get().end()); | 90 DCHECK(found != display_map_.Get().end()); |
| 99 DCHECK(found->second == this); | 91 DCHECK(found->second == this); |
| 100 display_map_.Get().erase(found); | 92 display_map_.Get().erase(found); |
| 101 if (display_map_.Get().empty()) { | 93 if (display_map_.Get().empty()) { |
| 102 CGError remove_error = CGDisplayRemoveReconfigurationCallback( | 94 CGError remove_error = CGDisplayRemoveReconfigurationCallback( |
| 103 DisplayReconfigurationCallBack, nullptr); | 95 DisplayReconfigurationCallBack, nullptr); |
| 104 DPLOG_IF(ERROR, remove_error != kCGErrorSuccess) | 96 DPLOG_IF(ERROR, remove_error != kCGErrorSuccess) |
| 105 << "CGDisplayRemoveReconfigurationCallback: " | 97 << "CGDisplayRemoveReconfigurationCallback: " |
| 106 << remove_error; | 98 << remove_error; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 DisplayLinkMac* display_link_mac = found->second; | 189 DisplayLinkMac* display_link_mac = found->second; |
| 198 display_link_mac->timebase_and_interval_valid_ = false; | 190 display_link_mac->timebase_and_interval_valid_ = false; |
| 199 } | 191 } |
| 200 | 192 |
| 201 // static | 193 // static |
| 202 base::LazyInstance<DisplayLinkMac::DisplayMap> | 194 base::LazyInstance<DisplayLinkMac::DisplayMap> |
| 203 DisplayLinkMac::display_map_ = LAZY_INSTANCE_INITIALIZER; | 195 DisplayLinkMac::display_map_ = LAZY_INSTANCE_INITIALIZER; |
| 204 | 196 |
| 205 } // ui | 197 } // ui |
| 206 | 198 |
| OLD | NEW |