ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / ui / ozone / platform / dri / drm_device_manager.cc
blobd04aee024efb0e3e6a9fcc6621a7725e9d5f864d
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
3 // found in the LICENSE file.
5 #include "ui/ozone/platform/dri/drm_device_manager.h"
7 #include "ui/ozone/platform/dri/drm_device.h"
9 namespace ui {
11 DrmDeviceManager::DrmDeviceManager(
12 const scoped_refptr<DrmDevice>& primary_device)
13 : primary_device_(primary_device) {
16 DrmDeviceManager::~DrmDeviceManager() {
17 DCHECK(drm_device_map_.empty());
20 void DrmDeviceManager::UpdateDrmDevice(gfx::AcceleratedWidget widget,
21 const scoped_refptr<DrmDevice>& device) {
22 base::AutoLock lock(lock_);
23 drm_device_map_[widget] = device;
26 void DrmDeviceManager::RemoveDrmDevice(gfx::AcceleratedWidget widget) {
27 base::AutoLock lock(lock_);
28 auto it = drm_device_map_.find(widget);
29 if (it != drm_device_map_.end())
30 drm_device_map_.erase(it);
33 scoped_refptr<DrmDevice> DrmDeviceManager::GetDrmDevice(
34 gfx::AcceleratedWidget widget) {
35 base::AutoLock lock(lock_);
36 if (widget == gfx::kNullAcceleratedWidget)
37 return primary_device_;
39 auto it = drm_device_map_.find(widget);
40 DCHECK(it != drm_device_map_.end())
41 << "Attempting to get device for unknown widget " << widget;
42 // If the widget isn't associated with a display (headless mode) we can
43 // allocate buffers from any controller since they will never be scanned out.
44 // Use the primary DRM device as a fallback when allocating these buffers.
45 if (!it->second)
46 return primary_device_;
48 return it->second;
51 } // namespace ui