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 #ifndef UI_OZONE_PLATFORM_DRM_GPU_DRM_DEVICE_MANAGER_H_ | 5 #ifndef UI_OZONE_PLATFORM_DRM_GPU_DRM_DEVICE_MANAGER_H_ |
6 #define UI_OZONE_PLATFORM_DRM_GPU_DRM_DEVICE_MANAGER_H_ | 6 #define UI_OZONE_PLATFORM_DRM_GPU_DRM_DEVICE_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | |
9 | 10 |
10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | |
11 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
14 #include "base/threading/thread_checker.h" | |
12 #include "ui/gfx/native_widget_types.h" | 15 #include "ui/gfx/native_widget_types.h" |
13 #include "ui/ozone/ozone_export.h" | 16 #include "ui/ozone/ozone_export.h" |
14 | 17 |
18 namespace base { | |
19 class FilePath; | |
20 struct FileDescriptor; | |
21 class SingleThreadTaskRunner; | |
22 } | |
23 | |
15 namespace ui { | 24 namespace ui { |
16 | 25 |
17 class DrmDevice; | 26 class DrmDevice; |
27 class DrmDeviceGenerator; | |
28 | |
29 typedef std::vector<scoped_refptr<DrmDevice>> DrmDeviceVector; | |
18 | 30 |
19 // Tracks the mapping between widgets and the DRM devices used to allocate | 31 // Tracks the mapping between widgets and the DRM devices used to allocate |
20 // buffers for the window represented by the widget. | 32 // buffers for the window represented by the widget. |
33 // Note: All calls are protected by a lock since | |
34 // GetDrmDevice(gfx::AcceleratedWidget) may be called on the IO thread. | |
21 class OZONE_EXPORT DrmDeviceManager { | 35 class OZONE_EXPORT DrmDeviceManager { |
22 public: | 36 public: |
23 DrmDeviceManager(const scoped_refptr<DrmDevice>& primary_device); | 37 DrmDeviceManager(scoped_ptr<DrmDeviceGenerator> drm_device_generator); |
24 ~DrmDeviceManager(); | 38 ~DrmDeviceManager(); |
25 | 39 |
40 // The first device registered is assumed to be the primary device. | |
41 bool AddDrmDevice(const base::FilePath& path, const base::FileDescriptor& fd); | |
42 void RemoveDrmDevice(const base::FilePath& path); | |
43 | |
44 void InitializeIOTaskRunner( | |
45 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | |
46 | |
26 // Updates the device associated with |widget|. | 47 // Updates the device associated with |widget|. |
27 void UpdateDrmDevice(gfx::AcceleratedWidget widget, | 48 void UpdateDrmDevice(gfx::AcceleratedWidget widget, |
28 const scoped_refptr<DrmDevice>& device); | 49 const scoped_refptr<DrmDevice>& device); |
29 | 50 |
30 // Removes the device associated with |widget|. | 51 // Removes the device associated with |widget|. |
31 void RemoveDrmDevice(gfx::AcceleratedWidget widget); | 52 void RemoveDrmDevice(gfx::AcceleratedWidget widget); |
32 | 53 |
33 // Returns the device associated with |widget|. If there is no association | 54 // Returns the device associated with |widget|. If there is no association |
34 // returns |primary_device_|. | 55 // returns |primary_device_|. |
35 scoped_refptr<DrmDevice> GetDrmDevice(gfx::AcceleratedWidget widget); | 56 scoped_refptr<DrmDevice> GetDrmDevice(gfx::AcceleratedWidget widget); |
36 | 57 |
58 DrmDeviceVector GetDrmDevices(); | |
alexst (slow to review)
2015/04/23 13:53:43
One more nit: do you need to make a copy here or c
dnicoara
2015/04/23 14:06:11
Nope, done.
| |
59 | |
37 private: | 60 private: |
61 // With the exception of GetDrmDevice() all functions must be called on GPU | |
62 // main. | |
63 base::ThreadChecker thread_checker_; | |
64 | |
65 scoped_ptr<DrmDeviceGenerator> drm_device_generator_; | |
66 | |
67 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | |
68 | |
69 DrmDeviceVector devices_; | |
70 | |
38 std::map<gfx::AcceleratedWidget, scoped_refptr<DrmDevice>> drm_device_map_; | 71 std::map<gfx::AcceleratedWidget, scoped_refptr<DrmDevice>> drm_device_map_; |
39 | 72 |
40 // This device represents the primary graphics device and is used when: | 73 // This device represents the primary graphics device and is used when: |
41 // 1) 'widget == kNullAcceleratedWidget' when the API requesting a buffer has | 74 // 1) 'widget == kNullAcceleratedWidget' when the API requesting a buffer has |
42 // no knowledge of the surface/display it belongs to (currently this happens | 75 // no knowledge of the surface/display it belongs to (currently this happens |
43 // for video buffers), or | 76 // for video buffers), or |
44 // 2) in order to allocate buffers for unmatched surfaces (surfaces without a | 77 // 2) in order to allocate buffers for unmatched surfaces (surfaces without a |
45 // display; ie: when in headless mode). | 78 // display; ie: when in headless mode). |
46 scoped_refptr<DrmDevice> primary_device_; | 79 scoped_refptr<DrmDevice> primary_device_; |
47 | 80 |
48 // This class is accessed from the main thread and the IO thread. This lock | 81 // This class is accessed from the main thread and the IO thread. This lock |
49 // protects access to the device map. | 82 // protects access to the device map. |
50 base::Lock lock_; | 83 base::Lock lock_; |
51 | 84 |
52 DISALLOW_COPY_AND_ASSIGN(DrmDeviceManager); | 85 DISALLOW_COPY_AND_ASSIGN(DrmDeviceManager); |
53 }; | 86 }; |
54 | 87 |
55 } // namespace ui | 88 } // namespace ui |
56 | 89 |
57 #endif // UI_OZONE_PLATFORM_DRM_GPU_DRM_DEVICE_MANAGER_H_ | 90 #endif // UI_OZONE_PLATFORM_DRM_GPU_DRM_DEVICE_MANAGER_H_ |
OLD | NEW |