diff options
author | matthewyuan <matthewyuan@google.com> | 2015-02-24 11:44:10 -0800 |
---|---|---|
committer | matthewyuan <matthewyuan@google.com> | 2015-02-24 19:45:43 +0000 |
commit | 7f79bcbb6621515b9198fdfaa45a90ab6abfb528 (patch) | |
tree | 9ad6363bd6d5afb09ce69813c92755b0f7235f71 /ui/ozone | |
parent | fb0b694bfe0727df54efc9d30f08777e33f927aa (diff) | |
download | chromium_src-7f79bcbb6621515b9198fdfaa45a90ab6abfb528.zip chromium_src-7f79bcbb6621515b9198fdfaa45a90ab6abfb528.tar.gz chromium_src-7f79bcbb6621515b9198fdfaa45a90ab6abfb528.tar.bz2 |
[Ozone-Dri] Gracefully handle DRM devices with no resources
DRM devices such as VGEM do not have resources, so we want to ignore
them rather than crash.
BUG=460982
Review URL: https://codereview.chromium.org/947293002
Cr-Commit-Position: refs/heads/master@{#317687}
(cherry picked from commit 3b2bde2e135f6125956bc4b526e1a6208111ae53)
Review URL: https://codereview.chromium.org/956563004
Cr-Commit-Position: refs/branch-heads/2311@{#14}
Cr-Branched-From: 09b7de5dd7254947cd4306de907274fa63373d48-refs/heads/master@{#317474}
Diffstat (limited to 'ui/ozone')
-rw-r--r-- | ui/ozone/platform/dri/dri_wrapper.cc | 27 | ||||
-rw-r--r-- | ui/ozone/platform/dri/dri_wrapper.h | 2 | ||||
-rw-r--r-- | ui/ozone/platform/dri/drm_device_generator.cc | 6 | ||||
-rw-r--r-- | ui/ozone/platform/dri/gbm_wrapper.cc | 14 | ||||
-rw-r--r-- | ui/ozone/platform/dri/gbm_wrapper.h | 2 | ||||
-rw-r--r-- | ui/ozone/platform/dri/hardware_display_plane_manager.cc | 2 | ||||
-rw-r--r-- | ui/ozone/platform/dri/native_display_delegate_dri.cc | 12 | ||||
-rw-r--r-- | ui/ozone/platform/dri/ozone_platform_dri.cc | 4 | ||||
-rw-r--r-- | ui/ozone/platform/dri/ozone_platform_gbm.cc | 10 |
9 files changed, 59 insertions, 20 deletions
diff --git a/ui/ozone/platform/dri/dri_wrapper.cc b/ui/ozone/platform/dri/dri_wrapper.cc index 9cdc994..a2b333f 100644 --- a/ui/ozone/platform/dri/dri_wrapper.cc +++ b/ui/ozone/platform/dri/dri_wrapper.cc @@ -88,6 +88,14 @@ void HandlePageFlipEventOnUI(int fd, payload->callback.Run(frame, seconds, useconds); } +bool CanQueryForResources(int fd) { + drm_mode_card_res resources; + memset(&resources, 0, sizeof(resources)); + // If there is no error getting DRM resources then assume this is a + // modesetting device. + return !drmIoctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &resources); +} + } // namespace class DriWrapper::IOWatcher @@ -163,10 +171,23 @@ DriWrapper::~DriWrapper() { watcher_->Shutdown(); } -void DriWrapper::Initialize() { +bool DriWrapper::Initialize() { + // Ignore devices that cannot perform modesetting. + if (!CanQueryForResources(file_.GetPlatformFile())) { + VLOG(2) << "Cannot query for resources for '" << device_path_.value() + << "'"; + return false; + } + plane_manager_.reset(new HardwareDisplayPlaneManagerLegacy()); - if (!plane_manager_->Initialize(this)) - LOG(ERROR) << "Failed to initialize the plane manager"; + if (!plane_manager_->Initialize(this)) { + LOG(ERROR) << "Failed to initialize the plane manager for " + << device_path_.value(); + plane_manager_.reset(); + return false; + } + + return true; } void DriWrapper::InitializeTaskRunner( diff --git a/ui/ozone/platform/dri/dri_wrapper.h b/ui/ozone/platform/dri/dri_wrapper.h index b83b7a7..d47c506 100644 --- a/ui/ozone/platform/dri/dri_wrapper.h +++ b/ui/ozone/platform/dri/dri_wrapper.h @@ -48,7 +48,7 @@ class OZONE_EXPORT DriWrapper : public base::RefCountedThreadSafe<DriWrapper> { DriWrapper(const base::FilePath& device_path, base::File file); // Open device. - virtual void Initialize(); + virtual bool Initialize(); // |task_runner| will be used to asynchronously page flip. virtual void InitializeTaskRunner( diff --git a/ui/ozone/platform/dri/drm_device_generator.cc b/ui/ozone/platform/dri/drm_device_generator.cc index 7b4a568..13985db 100644 --- a/ui/ozone/platform/dri/drm_device_generator.cc +++ b/ui/ozone/platform/dri/drm_device_generator.cc @@ -18,8 +18,10 @@ scoped_refptr<DriWrapper> DrmDeviceGenerator::CreateDevice( const base::FilePath& device_path, base::File file) { scoped_refptr<DriWrapper> drm = new DriWrapper(device_path, file.Pass()); - drm->Initialize(); - return drm; + if (drm->Initialize()) + return drm; + + return nullptr; } } // namespace ui diff --git a/ui/ozone/platform/dri/gbm_wrapper.cc b/ui/ozone/platform/dri/gbm_wrapper.cc index e75cc58..e0d1f17 100644 --- a/ui/ozone/platform/dri/gbm_wrapper.cc +++ b/ui/ozone/platform/dri/gbm_wrapper.cc @@ -21,11 +21,17 @@ GbmWrapper::~GbmWrapper() { gbm_device_destroy(device_); } -void GbmWrapper::Initialize() { - DriWrapper::Initialize(); +bool GbmWrapper::Initialize() { + if (!DriWrapper::Initialize()) + return false; + device_ = gbm_create_device(get_fd()); - if (!device_) - LOG(FATAL) << "Unable to initialize GBM"; + if (!device_) { + LOG(ERROR) << "Unable to initialize GBM"; + return false; + } + + return true; } } // namespace ui diff --git a/ui/ozone/platform/dri/gbm_wrapper.h b/ui/ozone/platform/dri/gbm_wrapper.h index 41b2b6a..3df2550 100644 --- a/ui/ozone/platform/dri/gbm_wrapper.h +++ b/ui/ozone/platform/dri/gbm_wrapper.h @@ -19,7 +19,7 @@ class GbmWrapper : public DriWrapper { gbm_device* device() const { return device_; } // DriWrapper implementation: - void Initialize() override; + bool Initialize() override; private: ~GbmWrapper() override; diff --git a/ui/ozone/platform/dri/hardware_display_plane_manager.cc b/ui/ozone/platform/dri/hardware_display_plane_manager.cc index f465e6c..2a8b7cc 100644 --- a/ui/ozone/platform/dri/hardware_display_plane_manager.cc +++ b/ui/ozone/platform/dri/hardware_display_plane_manager.cc @@ -69,7 +69,7 @@ bool HardwareDisplayPlaneManager::Initialize(DriWrapper* drm) { drm_ = drm; ScopedDrmResourcesPtr resources(drmModeGetResources(drm->get_fd())); if (!resources) { - LOG(ERROR) << "Failed to get resources."; + PLOG(ERROR) << "Failed to get resources"; return false; } diff --git a/ui/ozone/platform/dri/native_display_delegate_dri.cc b/ui/ozone/platform/dri/native_display_delegate_dri.cc index b242283..ba5d2ae 100644 --- a/ui/ozone/platform/dri/native_display_delegate_dri.cc +++ b/ui/ozone/platform/dri/native_display_delegate_dri.cc @@ -219,13 +219,17 @@ void NativeDisplayDelegateDri::AddGraphicsDevice( auto it = std::find_if(devices_.begin(), devices_.end(), FindByDevicePath(path)); if (it != devices_.end()) { - LOG(WARNING) << "Got request to add existing device '" << path.value() - << "'"; + VLOG(2) << "Got request to add existing device '" << path.value() << "'"; return; } scoped_refptr<DriWrapper> device = drm_device_generator_->CreateDevice(path, file.Pass()); + if (!device) { + VLOG(2) << "Could not initialize DRM device for '" << path.value() << "'"; + return; + } + devices_.push_back(device); if (io_task_runner_) device->InitializeTaskRunner(io_task_runner_); @@ -236,8 +240,8 @@ void NativeDisplayDelegateDri::RemoveGraphicsDevice( auto it = std::find_if(devices_.begin(), devices_.end(), FindByDevicePath(path)); if (it == devices_.end()) { - LOG(ERROR) << "Got request to remove non-existent device '" << path.value() - << "'"; + VLOG(2) << "Got request to remove non-existent device '" << path.value() + << "'"; return; } diff --git a/ui/ozone/platform/dri/ozone_platform_dri.cc b/ui/ozone/platform/dri/ozone_platform_dri.cc index 905c9f4..b01cfc1 100644 --- a/ui/ozone/platform/dri/ozone_platform_dri.cc +++ b/ui/ozone/platform/dri/ozone_platform_dri.cc @@ -91,7 +91,9 @@ class OzonePlatformDri : public OzonePlatform { display_manager_.get())); } void InitializeUI() override { - dri_->Initialize(); + if (!dri_->Initialize()) + LOG(FATAL) << "Failed to initialize primary DRM device"; + // This makes sure that simple targets that do not handle display // configuration can still use the primary display. ForceInitializationOfPrimaryDisplay(dri_, screen_manager_.get()); diff --git a/ui/ozone/platform/dri/ozone_platform_gbm.cc b/ui/ozone/platform/dri/ozone_platform_gbm.cc index fe728f0..dcfbbcb 100644 --- a/ui/ozone/platform/dri/ozone_platform_gbm.cc +++ b/ui/ozone/platform/dri/ozone_platform_gbm.cc @@ -96,8 +96,10 @@ class GbmDeviceGenerator : public DrmDeviceGenerator { scoped_refptr<DriWrapper> CreateDevice(const base::FilePath& path, base::File file) override { scoped_refptr<DriWrapper> drm = new GbmWrapper(path, file.Pass()); - drm->Initialize(); - return drm; + if (drm->Initialize()) + return drm; + + return nullptr; } private: @@ -173,7 +175,9 @@ class OzonePlatformGbm : public OzonePlatform { gl_api_loader_.reset(new GlApiLoader()); // Async page flips are supported only on surfaceless mode. gbm_ = new GbmWrapper(GetFirstDisplayCardPath()); - gbm_->Initialize(); + if (!gbm_->Initialize()) + LOG(FATAL) << "Failed to initialize primary DRM device"; + drm_device_manager_.reset(new DrmDeviceManager(gbm_)); buffer_generator_.reset(new GbmBufferGenerator()); screen_manager_.reset(new ScreenManager(buffer_generator_.get())); |