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/test/mock_dri_wrapper.h" | 5 #include "ui/ozone/platform/dri/test/mock_drm_device.h" |
6 | 6 |
7 #include <xf86drm.h> | 7 #include <xf86drm.h> |
8 #include <xf86drmMode.h> | 8 #include <xf86drmMode.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "third_party/skia/include/core/SkCanvas.h" | 11 #include "third_party/skia/include/core/SkCanvas.h" |
12 #include "ui/ozone/platform/dri/hardware_display_plane_manager_legacy.h" | 12 #include "ui/ozone/platform/dri/hardware_display_plane_manager_legacy.h" |
13 | 13 |
14 namespace ui { | 14 namespace ui { |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 template<class Object> Object* DrmAllocator() { | 18 template <class Object> |
| 19 Object* DrmAllocator() { |
19 return static_cast<Object*>(drmMalloc(sizeof(Object))); | 20 return static_cast<Object*>(drmMalloc(sizeof(Object))); |
20 } | 21 } |
21 | 22 |
22 class MockHardwareDisplayPlaneManager | 23 class MockHardwareDisplayPlaneManager |
23 : public HardwareDisplayPlaneManagerLegacy { | 24 : public HardwareDisplayPlaneManagerLegacy { |
24 public: | 25 public: |
25 MockHardwareDisplayPlaneManager(DriWrapper* drm, | 26 MockHardwareDisplayPlaneManager(DrmDevice* drm, |
26 std::vector<uint32_t> crtcs, | 27 std::vector<uint32_t> crtcs, |
27 size_t planes_per_crtc) { | 28 size_t planes_per_crtc) { |
28 const int kPlaneBaseId = 50; | 29 const int kPlaneBaseId = 50; |
29 drm_ = drm; | 30 drm_ = drm; |
30 crtcs_.swap(crtcs); | 31 crtcs_.swap(crtcs); |
31 for (size_t crtc_idx = 0; crtc_idx < crtcs_.size(); crtc_idx++) { | 32 for (size_t crtc_idx = 0; crtc_idx < crtcs_.size(); crtc_idx++) { |
32 for (size_t i = 0; i < planes_per_crtc; i++) { | 33 for (size_t i = 0; i < planes_per_crtc; i++) { |
33 planes_.push_back( | 34 planes_.push_back( |
34 new HardwareDisplayPlane(kPlaneBaseId + i, 1 << crtc_idx)); | 35 new HardwareDisplayPlane(kPlaneBaseId + i, 1 << crtc_idx)); |
35 } | 36 } |
36 } | 37 } |
37 } | 38 } |
38 }; | 39 }; |
39 | 40 |
40 } // namespace | 41 } // namespace |
41 | 42 |
42 MockDriWrapper::MockDriWrapper() | 43 MockDrmDevice::MockDrmDevice() |
43 : DriWrapper(base::FilePath(), base::File()), | 44 : DrmDevice(base::FilePath(), base::File()), |
44 get_crtc_call_count_(0), | 45 get_crtc_call_count_(0), |
45 set_crtc_call_count_(0), | 46 set_crtc_call_count_(0), |
46 restore_crtc_call_count_(0), | 47 restore_crtc_call_count_(0), |
47 add_framebuffer_call_count_(0), | 48 add_framebuffer_call_count_(0), |
48 remove_framebuffer_call_count_(0), | 49 remove_framebuffer_call_count_(0), |
49 page_flip_call_count_(0), | 50 page_flip_call_count_(0), |
50 overlay_flip_call_count_(0), | 51 overlay_flip_call_count_(0), |
51 set_crtc_expectation_(true), | 52 set_crtc_expectation_(true), |
52 add_framebuffer_expectation_(true), | 53 add_framebuffer_expectation_(true), |
53 page_flip_expectation_(true), | 54 page_flip_expectation_(true), |
54 create_dumb_buffer_expectation_(true), | 55 create_dumb_buffer_expectation_(true), |
55 current_framebuffer_(0) { | 56 current_framebuffer_(0) { |
56 plane_manager_.reset(new HardwareDisplayPlaneManagerLegacy()); | 57 plane_manager_.reset(new HardwareDisplayPlaneManagerLegacy()); |
57 } | 58 } |
58 | 59 |
59 MockDriWrapper::MockDriWrapper(bool use_sync_flips, | 60 MockDrmDevice::MockDrmDevice(bool use_sync_flips, |
60 std::vector<uint32_t> crtcs, | 61 std::vector<uint32_t> crtcs, |
61 size_t planes_per_crtc) | 62 size_t planes_per_crtc) |
62 : DriWrapper(base::FilePath(), base::File()), | 63 : DrmDevice(base::FilePath(), base::File()), |
63 get_crtc_call_count_(0), | 64 get_crtc_call_count_(0), |
64 set_crtc_call_count_(0), | 65 set_crtc_call_count_(0), |
65 restore_crtc_call_count_(0), | 66 restore_crtc_call_count_(0), |
66 add_framebuffer_call_count_(0), | 67 add_framebuffer_call_count_(0), |
67 remove_framebuffer_call_count_(0), | 68 remove_framebuffer_call_count_(0), |
68 page_flip_call_count_(0), | 69 page_flip_call_count_(0), |
69 overlay_flip_call_count_(0), | 70 overlay_flip_call_count_(0), |
70 overlay_clear_call_count_(0), | 71 overlay_clear_call_count_(0), |
71 set_crtc_expectation_(true), | 72 set_crtc_expectation_(true), |
72 add_framebuffer_expectation_(true), | 73 add_framebuffer_expectation_(true), |
73 page_flip_expectation_(true), | 74 page_flip_expectation_(true), |
74 create_dumb_buffer_expectation_(true), | 75 create_dumb_buffer_expectation_(true), |
75 use_sync_flips_(use_sync_flips), | 76 use_sync_flips_(use_sync_flips), |
76 current_framebuffer_(0) { | 77 current_framebuffer_(0) { |
77 plane_manager_.reset( | 78 plane_manager_.reset( |
78 new MockHardwareDisplayPlaneManager(this, crtcs, planes_per_crtc)); | 79 new MockHardwareDisplayPlaneManager(this, crtcs, planes_per_crtc)); |
79 } | 80 } |
80 | 81 |
81 MockDriWrapper::~MockDriWrapper() { | 82 MockDrmDevice::~MockDrmDevice() { |
82 } | 83 } |
83 | 84 |
84 ScopedDrmCrtcPtr MockDriWrapper::GetCrtc(uint32_t crtc_id) { | 85 ScopedDrmCrtcPtr MockDrmDevice::GetCrtc(uint32_t crtc_id) { |
85 get_crtc_call_count_++; | 86 get_crtc_call_count_++; |
86 return ScopedDrmCrtcPtr(DrmAllocator<drmModeCrtc>()); | 87 return ScopedDrmCrtcPtr(DrmAllocator<drmModeCrtc>()); |
87 } | 88 } |
88 | 89 |
89 bool MockDriWrapper::SetCrtc(uint32_t crtc_id, | 90 bool MockDrmDevice::SetCrtc(uint32_t crtc_id, |
90 uint32_t framebuffer, | 91 uint32_t framebuffer, |
91 std::vector<uint32_t> connectors, | 92 std::vector<uint32_t> connectors, |
92 drmModeModeInfo* mode) { | 93 drmModeModeInfo* mode) { |
93 current_framebuffer_ = framebuffer; | 94 current_framebuffer_ = framebuffer; |
94 set_crtc_call_count_++; | 95 set_crtc_call_count_++; |
95 return set_crtc_expectation_; | 96 return set_crtc_expectation_; |
96 } | 97 } |
97 | 98 |
98 bool MockDriWrapper::SetCrtc(drmModeCrtc* crtc, | 99 bool MockDrmDevice::SetCrtc(drmModeCrtc* crtc, |
99 std::vector<uint32_t> connectors) { | 100 std::vector<uint32_t> connectors) { |
100 restore_crtc_call_count_++; | 101 restore_crtc_call_count_++; |
101 return true; | 102 return true; |
102 } | 103 } |
103 | 104 |
104 bool MockDriWrapper::DisableCrtc(uint32_t crtc_id) { | 105 bool MockDrmDevice::DisableCrtc(uint32_t crtc_id) { |
105 current_framebuffer_ = 0; | 106 current_framebuffer_ = 0; |
106 return true; | 107 return true; |
107 } | 108 } |
108 | 109 |
109 ScopedDrmConnectorPtr MockDriWrapper::GetConnector(uint32_t connector_id) { | 110 ScopedDrmConnectorPtr MockDrmDevice::GetConnector(uint32_t connector_id) { |
110 return ScopedDrmConnectorPtr(DrmAllocator<drmModeConnector>()); | 111 return ScopedDrmConnectorPtr(DrmAllocator<drmModeConnector>()); |
111 } | 112 } |
112 | 113 |
113 bool MockDriWrapper::AddFramebuffer(uint32_t width, | 114 bool MockDrmDevice::AddFramebuffer(uint32_t width, |
114 uint32_t height, | 115 uint32_t height, |
115 uint8_t depth, | 116 uint8_t depth, |
116 uint8_t bpp, | 117 uint8_t bpp, |
117 uint32_t stride, | 118 uint32_t stride, |
118 uint32_t handle, | 119 uint32_t handle, |
119 uint32_t* framebuffer) { | 120 uint32_t* framebuffer) { |
120 add_framebuffer_call_count_++; | 121 add_framebuffer_call_count_++; |
121 *framebuffer = add_framebuffer_call_count_; | 122 *framebuffer = add_framebuffer_call_count_; |
122 return add_framebuffer_expectation_; | 123 return add_framebuffer_expectation_; |
123 } | 124 } |
124 | 125 |
125 bool MockDriWrapper::RemoveFramebuffer(uint32_t framebuffer) { | 126 bool MockDrmDevice::RemoveFramebuffer(uint32_t framebuffer) { |
126 remove_framebuffer_call_count_++; | 127 remove_framebuffer_call_count_++; |
127 return true; | 128 return true; |
128 } | 129 } |
129 | 130 |
130 ScopedDrmFramebufferPtr MockDriWrapper::GetFramebuffer(uint32_t framebuffer) { | 131 ScopedDrmFramebufferPtr MockDrmDevice::GetFramebuffer(uint32_t framebuffer) { |
131 return ScopedDrmFramebufferPtr(); | 132 return ScopedDrmFramebufferPtr(); |
132 } | 133 } |
133 | 134 |
134 bool MockDriWrapper::PageFlip(uint32_t crtc_id, | 135 bool MockDrmDevice::PageFlip(uint32_t crtc_id, |
135 uint32_t framebuffer, | 136 uint32_t framebuffer, |
136 bool is_sync, | 137 bool is_sync, |
137 const PageFlipCallback& callback) { | 138 const PageFlipCallback& callback) { |
138 page_flip_call_count_++; | 139 page_flip_call_count_++; |
139 current_framebuffer_ = framebuffer; | 140 current_framebuffer_ = framebuffer; |
140 if (page_flip_expectation_) { | 141 if (page_flip_expectation_) { |
141 if (use_sync_flips_) | 142 if (use_sync_flips_) |
142 callback.Run(0, 0, 0); | 143 callback.Run(0, 0, 0); |
143 else | 144 else |
144 callbacks_.push(callback); | 145 callbacks_.push(callback); |
145 } | 146 } |
146 | 147 |
147 return page_flip_expectation_; | 148 return page_flip_expectation_; |
148 } | 149 } |
149 | 150 |
150 bool MockDriWrapper::PageFlipOverlay(uint32_t crtc_id, | 151 bool MockDrmDevice::PageFlipOverlay(uint32_t crtc_id, |
151 uint32_t framebuffer, | 152 uint32_t framebuffer, |
152 const gfx::Rect& location, | 153 const gfx::Rect& location, |
153 const gfx::Rect& source, | 154 const gfx::Rect& source, |
154 int overlay_plane) { | 155 int overlay_plane) { |
155 if (!framebuffer) | 156 if (!framebuffer) |
156 overlay_clear_call_count_++; | 157 overlay_clear_call_count_++; |
157 overlay_flip_call_count_++; | 158 overlay_flip_call_count_++; |
158 return true; | 159 return true; |
159 } | 160 } |
160 | 161 |
161 ScopedDrmPropertyPtr MockDriWrapper::GetProperty(drmModeConnector* connector, | 162 ScopedDrmPropertyPtr MockDrmDevice::GetProperty(drmModeConnector* connector, |
162 const char* name) { | 163 const char* name) { |
163 return ScopedDrmPropertyPtr(DrmAllocator<drmModePropertyRes>()); | 164 return ScopedDrmPropertyPtr(DrmAllocator<drmModePropertyRes>()); |
164 } | 165 } |
165 | 166 |
166 bool MockDriWrapper::SetProperty(uint32_t connector_id, | 167 bool MockDrmDevice::SetProperty(uint32_t connector_id, |
167 uint32_t property_id, | 168 uint32_t property_id, |
168 uint64_t value) { | 169 uint64_t value) { |
169 return true; | 170 return true; |
170 } | 171 } |
171 | 172 |
172 bool MockDriWrapper::GetCapability(uint64_t capability, uint64_t* value) { | 173 bool MockDrmDevice::GetCapability(uint64_t capability, uint64_t* value) { |
173 return true; | 174 return true; |
174 } | 175 } |
175 | 176 |
176 ScopedDrmPropertyBlobPtr MockDriWrapper::GetPropertyBlob( | 177 ScopedDrmPropertyBlobPtr MockDrmDevice::GetPropertyBlob( |
177 drmModeConnector* connector, | 178 drmModeConnector* connector, |
178 const char* name) { | 179 const char* name) { |
179 return ScopedDrmPropertyBlobPtr(DrmAllocator<drmModePropertyBlobRes>()); | 180 return ScopedDrmPropertyBlobPtr(DrmAllocator<drmModePropertyBlobRes>()); |
180 } | 181 } |
181 | 182 |
182 bool MockDriWrapper::SetCursor(uint32_t crtc_id, | 183 bool MockDrmDevice::SetCursor(uint32_t crtc_id, |
183 uint32_t handle, | 184 uint32_t handle, |
184 const gfx::Size& size) { | 185 const gfx::Size& size) { |
185 return true; | 186 return true; |
186 } | 187 } |
187 | 188 |
188 bool MockDriWrapper::MoveCursor(uint32_t crtc_id, const gfx::Point& point) { | 189 bool MockDrmDevice::MoveCursor(uint32_t crtc_id, const gfx::Point& point) { |
189 return true; | 190 return true; |
190 } | 191 } |
191 | 192 |
192 bool MockDriWrapper::CreateDumbBuffer(const SkImageInfo& info, | 193 bool MockDrmDevice::CreateDumbBuffer(const SkImageInfo& info, |
193 uint32_t* handle, | 194 uint32_t* handle, |
194 uint32_t* stride, | 195 uint32_t* stride, |
195 void** pixels) { | 196 void** pixels) { |
196 if (!create_dumb_buffer_expectation_) | 197 if (!create_dumb_buffer_expectation_) |
197 return false; | 198 return false; |
198 | 199 |
199 *handle = 0; | 200 *handle = 0; |
200 *stride = info.minRowBytes(); | 201 *stride = info.minRowBytes(); |
201 *pixels = new char[info.getSafeSize(*stride)]; | 202 *pixels = new char[info.getSafeSize(*stride)]; |
202 buffers_.push_back( | 203 buffers_.push_back( |
203 skia::AdoptRef(SkSurface::NewRasterDirect(info, *pixels, *stride))); | 204 skia::AdoptRef(SkSurface::NewRasterDirect(info, *pixels, *stride))); |
204 buffers_.back()->getCanvas()->clear(SK_ColorBLACK); | 205 buffers_.back()->getCanvas()->clear(SK_ColorBLACK); |
205 | 206 |
206 return true; | 207 return true; |
207 } | 208 } |
208 | 209 |
209 void MockDriWrapper::DestroyDumbBuffer(const SkImageInfo& info, | 210 void MockDrmDevice::DestroyDumbBuffer(const SkImageInfo& info, |
210 uint32_t handle, | 211 uint32_t handle, |
211 uint32_t stride, | 212 uint32_t stride, |
212 void* pixels) { | 213 void* pixels) { |
213 delete[] static_cast<char*>(pixels); | 214 delete[] static_cast<char*>(pixels); |
214 } | 215 } |
215 | 216 |
216 void MockDriWrapper::RunCallbacks() { | 217 void MockDrmDevice::RunCallbacks() { |
217 while (!callbacks_.empty()) { | 218 while (!callbacks_.empty()) { |
218 PageFlipCallback callback = callbacks_.front(); | 219 PageFlipCallback callback = callbacks_.front(); |
219 callbacks_.pop(); | 220 callbacks_.pop(); |
220 callback.Run(0, 0, 0); | 221 callback.Run(0, 0, 0); |
221 } | 222 } |
222 } | 223 } |
223 | 224 |
224 } // namespace ui | 225 } // namespace ui |
OLD | NEW |