| 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/drm/gpu/drm_device_manager.h" | 5 #include "ui/ozone/platform/drm/gpu/drm_device_manager.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/file_descriptor_posix.h" | 9 #include "base/file_descriptor_posix.h" |
| 8 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 9 #include "ui/ozone/platform/drm/gpu/drm_device.h" | 11 #include "ui/ozone/platform/drm/gpu/drm_device.h" |
| 10 #include "ui/ozone/platform/drm/gpu/drm_device_generator.h" | 12 #include "ui/ozone/platform/drm/gpu/drm_device_generator.h" |
| 11 | 13 |
| 12 namespace ui { | 14 namespace ui { |
| 13 | 15 |
| 14 namespace { | 16 namespace { |
| 15 | 17 |
| 16 class FindByDevicePath { | 18 class FindByDevicePath { |
| 17 public: | 19 public: |
| 18 explicit FindByDevicePath(const base::FilePath& path) : path_(path) {} | 20 explicit FindByDevicePath(const base::FilePath& path) : path_(path) {} |
| 19 | 21 |
| 20 bool operator()(const scoped_refptr<DrmDevice>& device) { | 22 bool operator()(const scoped_refptr<DrmDevice>& device) { |
| 21 return device->device_path() == path_; | 23 return device->device_path() == path_; |
| 22 } | 24 } |
| 23 | 25 |
| 24 private: | 26 private: |
| 25 base::FilePath path_; | 27 base::FilePath path_; |
| 26 }; | 28 }; |
| 27 | 29 |
| 28 } // namespace | 30 } // namespace |
| 29 | 31 |
| 30 DrmDeviceManager::DrmDeviceManager( | 32 DrmDeviceManager::DrmDeviceManager( |
| 31 scoped_ptr<DrmDeviceGenerator> drm_device_generator) | 33 scoped_ptr<DrmDeviceGenerator> drm_device_generator) |
| 32 : drm_device_generator_(drm_device_generator.Pass()) { | 34 : drm_device_generator_(std::move(drm_device_generator)) {} |
| 33 } | |
| 34 | 35 |
| 35 DrmDeviceManager::~DrmDeviceManager() { | 36 DrmDeviceManager::~DrmDeviceManager() { |
| 36 DCHECK(drm_device_map_.empty()); | 37 DCHECK(drm_device_map_.empty()); |
| 37 } | 38 } |
| 38 | 39 |
| 39 bool DrmDeviceManager::AddDrmDevice(const base::FilePath& path, | 40 bool DrmDeviceManager::AddDrmDevice(const base::FilePath& path, |
| 40 const base::FileDescriptor& fd) { | 41 const base::FileDescriptor& fd) { |
| 41 base::File file(fd.fd); | 42 base::File file(fd.fd); |
| 42 auto it = | 43 auto it = |
| 43 std::find_if(devices_.begin(), devices_.end(), FindByDevicePath(path)); | 44 std::find_if(devices_.begin(), devices_.end(), FindByDevicePath(path)); |
| 44 if (it != devices_.end()) { | 45 if (it != devices_.end()) { |
| 45 VLOG(2) << "Got request to add existing device: " << path.value(); | 46 VLOG(2) << "Got request to add existing device: " << path.value(); |
| 46 return false; | 47 return false; |
| 47 } | 48 } |
| 48 | 49 |
| 49 scoped_refptr<DrmDevice> device = | 50 scoped_refptr<DrmDevice> device = drm_device_generator_->CreateDevice( |
| 50 drm_device_generator_->CreateDevice(path, file.Pass(), !primary_device_); | 51 path, std::move(file), !primary_device_); |
| 51 if (!device) { | 52 if (!device) { |
| 52 LOG(ERROR) << "Could not initialize DRM device for " << path.value(); | 53 LOG(ERROR) << "Could not initialize DRM device for " << path.value(); |
| 53 return false; | 54 return false; |
| 54 } | 55 } |
| 55 | 56 |
| 56 if (!primary_device_) | 57 if (!primary_device_) |
| 57 primary_device_ = device; | 58 primary_device_ = device; |
| 58 | 59 |
| 59 devices_.push_back(device); | 60 devices_.push_back(device); |
| 60 return true; | 61 return true; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 return primary_device_; | 99 return primary_device_; |
| 99 | 100 |
| 100 return it->second; | 101 return it->second; |
| 101 } | 102 } |
| 102 | 103 |
| 103 const DrmDeviceVector& DrmDeviceManager::GetDrmDevices() const { | 104 const DrmDeviceVector& DrmDeviceManager::GetDrmDevices() const { |
| 104 return devices_; | 105 return devices_; |
| 105 } | 106 } |
| 106 | 107 |
| 107 } // namespace ui | 108 } // namespace ui |
| OLD | NEW |