| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ozone/platform/dri/drm_device_manager.h" | 5 #include "ui/ozone/platform/dri/drm_device_manager.h" |
| 6 | 6 |
| 7 #include "ui/ozone/platform/dri/dri_wrapper.h" | 7 #include "ui/ozone/platform/dri/drm_device.h" |
| 8 | 8 |
| 9 namespace ui { | 9 namespace ui { |
| 10 | 10 |
| 11 DrmDeviceManager::DrmDeviceManager( | 11 DrmDeviceManager::DrmDeviceManager( |
| 12 const scoped_refptr<DriWrapper>& primary_device) | 12 const scoped_refptr<DrmDevice>& primary_device) |
| 13 : primary_device_(primary_device) { | 13 : primary_device_(primary_device) { |
| 14 } | 14 } |
| 15 | 15 |
| 16 DrmDeviceManager::~DrmDeviceManager() { | 16 DrmDeviceManager::~DrmDeviceManager() { |
| 17 DCHECK(drm_device_map_.empty()); | 17 DCHECK(drm_device_map_.empty()); |
| 18 } | 18 } |
| 19 | 19 |
| 20 void DrmDeviceManager::UpdateDrmDevice( | 20 void DrmDeviceManager::UpdateDrmDevice(gfx::AcceleratedWidget widget, |
| 21 gfx::AcceleratedWidget widget, | 21 const scoped_refptr<DrmDevice>& device) { |
| 22 const scoped_refptr<DriWrapper>& device) { | |
| 23 base::AutoLock lock(lock_); | 22 base::AutoLock lock(lock_); |
| 24 drm_device_map_[widget] = device; | 23 drm_device_map_[widget] = device; |
| 25 } | 24 } |
| 26 | 25 |
| 27 void DrmDeviceManager::RemoveDrmDevice(gfx::AcceleratedWidget widget) { | 26 void DrmDeviceManager::RemoveDrmDevice(gfx::AcceleratedWidget widget) { |
| 28 base::AutoLock lock(lock_); | 27 base::AutoLock lock(lock_); |
| 29 auto it = drm_device_map_.find(widget); | 28 auto it = drm_device_map_.find(widget); |
| 30 if (it != drm_device_map_.end()) | 29 if (it != drm_device_map_.end()) |
| 31 drm_device_map_.erase(it); | 30 drm_device_map_.erase(it); |
| 32 } | 31 } |
| 33 | 32 |
| 34 scoped_refptr<DriWrapper> DrmDeviceManager::GetDrmDevice( | 33 scoped_refptr<DrmDevice> DrmDeviceManager::GetDrmDevice( |
| 35 gfx::AcceleratedWidget widget) { | 34 gfx::AcceleratedWidget widget) { |
| 36 base::AutoLock lock(lock_); | 35 base::AutoLock lock(lock_); |
| 37 if (widget == gfx::kNullAcceleratedWidget) | 36 if (widget == gfx::kNullAcceleratedWidget) |
| 38 return primary_device_; | 37 return primary_device_; |
| 39 | 38 |
| 40 auto it = drm_device_map_.find(widget); | 39 auto it = drm_device_map_.find(widget); |
| 41 DCHECK(it != drm_device_map_.end()) | 40 DCHECK(it != drm_device_map_.end()) |
| 42 << "Attempting to get device for unknown widget " << widget; | 41 << "Attempting to get device for unknown widget " << widget; |
| 43 // If the widget isn't associated with a display (headless mode) we can | 42 // If the widget isn't associated with a display (headless mode) we can |
| 44 // allocate buffers from any controller since they will never be scanned out. | 43 // allocate buffers from any controller since they will never be scanned out. |
| 45 // Use the primary DRM device as a fallback when allocating these buffers. | 44 // Use the primary DRM device as a fallback when allocating these buffers. |
| 46 if (!it->second) | 45 if (!it->second) |
| 47 return primary_device_; | 46 return primary_device_; |
| 48 | 47 |
| 49 return it->second; | 48 return it->second; |
| 50 } | 49 } |
| 51 | 50 |
| 52 } // namespace ui | 51 } // namespace ui |
| OLD | NEW |