OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/screen_manager.h" | 5 #include "ui/ozone/platform/dri/screen_manager.h" |
6 | 6 |
7 #include <xf86drmMode.h> | 7 #include <xf86drmMode.h> |
8 | 8 |
9 #include "ui/gfx/geometry/point.h" | 9 #include "ui/gfx/geometry/point.h" |
10 #include "ui/gfx/geometry/rect.h" | 10 #include "ui/gfx/geometry/rect.h" |
11 #include "ui/gfx/geometry/size.h" | 11 #include "ui/gfx/geometry/size.h" |
12 #include "ui/ozone/platform/dri/dri_util.h" | 12 #include "ui/ozone/platform/dri/dri_util.h" |
13 #include "ui/ozone/platform/dri/hardware_display_controller.h" | 13 #include "ui/ozone/platform/dri/hardware_display_controller.h" |
14 #include "ui/ozone/platform/dri/scanout_surface.h" | 14 #include "ui/ozone/platform/dri/scanout_buffer.h" |
15 | 15 |
16 namespace ui { | 16 namespace ui { |
17 | 17 |
18 ScreenManager::ScreenManager( | 18 ScreenManager::ScreenManager( |
19 DriWrapper* dri, ScanoutSurfaceGenerator* surface_generator) | 19 DriWrapper* dri, ScanoutBufferGenerator* buffer_generator) |
20 : dri_(dri), surface_generator_(surface_generator), last_added_widget_(0) { | 20 : dri_(dri), buffer_generator_(buffer_generator), last_added_widget_(0) { |
21 } | 21 } |
22 | 22 |
23 ScreenManager::~ScreenManager() { | 23 ScreenManager::~ScreenManager() { |
24 STLDeleteContainerPairSecondPointers( | 24 STLDeleteContainerPairSecondPointers( |
25 controllers_.begin(), controllers_.end()); | 25 controllers_.begin(), controllers_.end()); |
26 } | 26 } |
27 | 27 |
28 void ScreenManager::RemoveDisplayController(uint32_t crtc, uint32_t connector) { | 28 void ScreenManager::RemoveDisplayController(uint32_t crtc, uint32_t connector) { |
29 HardwareDisplayControllerMap::iterator it = | 29 HardwareDisplayControllerMap::iterator it = |
30 FindDisplayController(crtc, connector); | 30 FindDisplayController(crtc, connector); |
31 if (it != controllers_.end()) { | 31 if (it != controllers_.end()) { |
32 delete it->second; | 32 delete it->second; |
33 controllers_.erase(it); | 33 controllers_.erase(it); |
34 } | 34 } |
35 } | 35 } |
36 | 36 |
37 bool ScreenManager::ConfigureDisplayController(uint32_t crtc, | 37 bool ScreenManager::ConfigureDisplayController(uint32_t crtc, |
38 uint32_t connector, | 38 uint32_t connector, |
39 const drmModeModeInfo& mode) { | 39 const drmModeModeInfo& mode) { |
40 HardwareDisplayControllerMap::iterator it = | 40 HardwareDisplayControllerMap::iterator it = |
41 FindDisplayController(crtc, connector); | 41 FindDisplayController(crtc, connector); |
42 HardwareDisplayController* controller = NULL; | 42 HardwareDisplayController* controller = NULL; |
43 if (it != controllers_.end()) { | 43 if (it != controllers_.end()) { |
44 if (SameMode(mode, it->second->get_mode())) | 44 if (SameMode(mode, it->second->get_mode())) |
45 return it->second->Enable(); | 45 return it->second->Enable(); |
46 | 46 |
47 controller = it->second; | 47 controller = it->second; |
48 controller->UnbindSurfaceFromController(); | |
49 } | 48 } |
50 | 49 |
51 if (it == controllers_.end()) { | 50 if (it == controllers_.end()) { |
52 controller = new HardwareDisplayController(dri_, connector, crtc); | 51 controller = new HardwareDisplayController(dri_, connector, crtc); |
53 controllers_.insert(std::make_pair(++last_added_widget_, controller)); | 52 controllers_.insert(std::make_pair(++last_added_widget_, controller)); |
54 } | 53 } |
55 | 54 |
56 // Create a surface suitable for the current controller. | 55 // Create a surface suitable for the current controller. |
57 scoped_ptr<ScanoutSurface> surface( | 56 scoped_refptr<ScanoutBuffer> buffer = |
58 surface_generator_->Create(gfx::Size(mode.hdisplay, mode.vdisplay))); | 57 buffer_generator_->Create(gfx::Size(mode.hdisplay, mode.vdisplay)); |
59 | 58 |
60 if (!surface->Initialize()) { | 59 if (!buffer) { |
61 LOG(ERROR) << "Failed to initialize surface"; | 60 LOG(ERROR) << "Failed to create scanout buffer"; |
62 return false; | 61 return false; |
63 } | 62 } |
64 | 63 |
65 // Bind the surface to the controller. This will register the backing buffers | 64 if (!controller->Modeset(OverlayPlane(buffer), mode)) { |
66 // with the hardware CRTC such that we can show the buffers and performs the | 65 LOG(ERROR) << "Failed to modeset controller"; |
67 // initial modeset. The controller takes ownership of the surface. | |
68 if (!controller->BindSurfaceToController(surface.Pass(), mode)) { | |
69 LOG(ERROR) << "Failed to bind surface to controller"; | |
70 return false; | 66 return false; |
71 } | 67 } |
72 | 68 |
73 return true; | 69 return true; |
74 } | 70 } |
75 | 71 |
76 bool ScreenManager::DisableDisplayController(uint32_t crtc, | 72 bool ScreenManager::DisableDisplayController(uint32_t crtc, |
77 uint32_t connector) { | 73 uint32_t connector) { |
78 HardwareDisplayControllerMap::iterator it = | 74 HardwareDisplayControllerMap::iterator it = |
79 FindDisplayController(crtc, connector); | 75 FindDisplayController(crtc, connector); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 dri_->SetProperty(displays[0]->connector()->connector_id, | 121 dri_->SetProperty(displays[0]->connector()->connector_id, |
126 dpms->prop_id, | 122 dpms->prop_id, |
127 DRM_MODE_DPMS_ON); | 123 DRM_MODE_DPMS_ON); |
128 | 124 |
129 ConfigureDisplayController(displays[0]->crtc()->crtc_id, | 125 ConfigureDisplayController(displays[0]->crtc()->crtc_id, |
130 displays[0]->connector()->connector_id, | 126 displays[0]->connector()->connector_id, |
131 displays[0]->connector()->modes[0]); | 127 displays[0]->connector()->modes[0]); |
132 } | 128 } |
133 | 129 |
134 } // namespace ui | 130 } // namespace ui |
OLD | NEW |