Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: ui/ozone/platform/drm/test/mock_drm_device.cc

Issue 1285183008: Ozone integration. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: add missing license header Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/ozone/platform/drm/test/mock_drm_device.h ('k') | ui/ozone/platform/egltest/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/ozone/platform/drm/test/mock_drm_device.h"
6
7 #include <xf86drm.h>
8 #include <xf86drmMode.h>
9
10 #include "base/logging.h"
11 #include "third_party/skia/include/core/SkCanvas.h"
12 #include "ui/ozone/platform/drm/gpu/hardware_display_plane_manager_legacy.h"
13
14 namespace ui {
15
16 namespace {
17
18 template <class Object>
19 Object* DrmAllocator() {
20 return static_cast<Object*>(drmMalloc(sizeof(Object)));
21 }
22
23 class MockHardwareDisplayPlaneManager
24 : public HardwareDisplayPlaneManagerLegacy {
25 public:
26 MockHardwareDisplayPlaneManager(DrmDevice* drm,
27 std::vector<uint32_t> crtcs,
28 size_t planes_per_crtc) {
29 const int kPlaneBaseId = 50;
30 drm_ = drm;
31 crtcs_.swap(crtcs);
32 for (size_t crtc_idx = 0; crtc_idx < crtcs_.size(); crtc_idx++) {
33 for (size_t i = 0; i < planes_per_crtc; i++) {
34 planes_.push_back(
35 new HardwareDisplayPlane(kPlaneBaseId + i, 1 << crtc_idx));
36 }
37 }
38 }
39 };
40
41 } // namespace
42
43 MockDrmDevice::MockDrmDevice()
44 : DrmDevice(base::FilePath(), base::File()),
45 get_crtc_call_count_(0),
46 set_crtc_call_count_(0),
47 restore_crtc_call_count_(0),
48 add_framebuffer_call_count_(0),
49 remove_framebuffer_call_count_(0),
50 page_flip_call_count_(0),
51 overlay_flip_call_count_(0),
52 overlay_clear_call_count_(0),
53 allocate_buffer_count_(0),
54 set_crtc_expectation_(true),
55 add_framebuffer_expectation_(true),
56 page_flip_expectation_(true),
57 create_dumb_buffer_expectation_(true),
58 current_framebuffer_(0) {
59 plane_manager_.reset(new HardwareDisplayPlaneManagerLegacy());
60 }
61
62 MockDrmDevice::MockDrmDevice(bool use_sync_flips,
63 std::vector<uint32_t> crtcs,
64 size_t planes_per_crtc)
65 : DrmDevice(base::FilePath(), base::File()),
66 get_crtc_call_count_(0),
67 set_crtc_call_count_(0),
68 restore_crtc_call_count_(0),
69 add_framebuffer_call_count_(0),
70 remove_framebuffer_call_count_(0),
71 page_flip_call_count_(0),
72 overlay_flip_call_count_(0),
73 overlay_clear_call_count_(0),
74 allocate_buffer_count_(0),
75 set_crtc_expectation_(true),
76 add_framebuffer_expectation_(true),
77 page_flip_expectation_(true),
78 create_dumb_buffer_expectation_(true),
79 use_sync_flips_(use_sync_flips),
80 current_framebuffer_(0) {
81 plane_manager_.reset(
82 new MockHardwareDisplayPlaneManager(this, crtcs, planes_per_crtc));
83 }
84
85 MockDrmDevice::~MockDrmDevice() {
86 }
87
88 ScopedDrmCrtcPtr MockDrmDevice::GetCrtc(uint32_t crtc_id) {
89 get_crtc_call_count_++;
90 return ScopedDrmCrtcPtr(DrmAllocator<drmModeCrtc>());
91 }
92
93 bool MockDrmDevice::SetCrtc(uint32_t crtc_id,
94 uint32_t framebuffer,
95 std::vector<uint32_t> connectors,
96 drmModeModeInfo* mode) {
97 current_framebuffer_ = framebuffer;
98 set_crtc_call_count_++;
99 return set_crtc_expectation_;
100 }
101
102 bool MockDrmDevice::SetCrtc(drmModeCrtc* crtc,
103 std::vector<uint32_t> connectors) {
104 restore_crtc_call_count_++;
105 return true;
106 }
107
108 bool MockDrmDevice::DisableCrtc(uint32_t crtc_id) {
109 current_framebuffer_ = 0;
110 return true;
111 }
112
113 ScopedDrmConnectorPtr MockDrmDevice::GetConnector(uint32_t connector_id) {
114 return ScopedDrmConnectorPtr(DrmAllocator<drmModeConnector>());
115 }
116
117 bool MockDrmDevice::AddFramebuffer(uint32_t width,
118 uint32_t height,
119 uint8_t depth,
120 uint8_t bpp,
121 uint32_t stride,
122 uint32_t handle,
123 uint32_t* framebuffer) {
124 add_framebuffer_call_count_++;
125 *framebuffer = add_framebuffer_call_count_;
126 return add_framebuffer_expectation_;
127 }
128
129 bool MockDrmDevice::RemoveFramebuffer(uint32_t framebuffer) {
130 remove_framebuffer_call_count_++;
131 return true;
132 }
133
134 ScopedDrmFramebufferPtr MockDrmDevice::GetFramebuffer(uint32_t framebuffer) {
135 return ScopedDrmFramebufferPtr();
136 }
137
138 bool MockDrmDevice::PageFlip(uint32_t crtc_id,
139 uint32_t framebuffer,
140 bool is_sync,
141 const PageFlipCallback& callback) {
142 page_flip_call_count_++;
143 current_framebuffer_ = framebuffer;
144 if (page_flip_expectation_) {
145 if (use_sync_flips_)
146 callback.Run(0, 0, 0);
147 else
148 callbacks_.push(callback);
149 }
150
151 return page_flip_expectation_;
152 }
153
154 bool MockDrmDevice::PageFlipOverlay(uint32_t crtc_id,
155 uint32_t framebuffer,
156 const gfx::Rect& location,
157 const gfx::Rect& source,
158 int overlay_plane) {
159 if (!framebuffer)
160 overlay_clear_call_count_++;
161 overlay_flip_call_count_++;
162 return true;
163 }
164
165 ScopedDrmPropertyPtr MockDrmDevice::GetProperty(drmModeConnector* connector,
166 const char* name) {
167 return ScopedDrmPropertyPtr(DrmAllocator<drmModePropertyRes>());
168 }
169
170 bool MockDrmDevice::SetProperty(uint32_t connector_id,
171 uint32_t property_id,
172 uint64_t value) {
173 return true;
174 }
175
176 bool MockDrmDevice::GetCapability(uint64_t capability, uint64_t* value) {
177 return true;
178 }
179
180 ScopedDrmPropertyBlobPtr MockDrmDevice::GetPropertyBlob(
181 drmModeConnector* connector,
182 const char* name) {
183 return ScopedDrmPropertyBlobPtr(DrmAllocator<drmModePropertyBlobRes>());
184 }
185
186 bool MockDrmDevice::SetCursor(uint32_t crtc_id,
187 uint32_t handle,
188 const gfx::Size& size) {
189 crtc_cursor_map_[crtc_id] = handle;
190 return true;
191 }
192
193 bool MockDrmDevice::MoveCursor(uint32_t crtc_id, const gfx::Point& point) {
194 return true;
195 }
196
197 bool MockDrmDevice::CreateDumbBuffer(const SkImageInfo& info,
198 uint32_t* handle,
199 uint32_t* stride) {
200 if (!create_dumb_buffer_expectation_)
201 return false;
202
203 *handle = allocate_buffer_count_++;
204 *stride = info.minRowBytes();
205 void* pixels = new char[info.getSafeSize(*stride)];
206 buffers_.push_back(
207 skia::AdoptRef(SkSurface::NewRasterDirect(info, pixels, *stride)));
208 buffers_[*handle]->getCanvas()->clear(SK_ColorBLACK);
209
210 return true;
211 }
212
213 bool MockDrmDevice::DestroyDumbBuffer(uint32_t handle) {
214 if (handle >= buffers_.size() || !buffers_[handle])
215 return false;
216
217 buffers_[handle].clear();
218 return true;
219 }
220
221 bool MockDrmDevice::MapDumbBuffer(uint32_t handle, size_t size, void** pixels) {
222 if (handle >= buffers_.size() || !buffers_[handle])
223 return false;
224
225 *pixels = const_cast<void*>(buffers_[handle]->peekPixels(nullptr, nullptr));
226 return true;
227 }
228
229 bool MockDrmDevice::UnmapDumbBuffer(void* pixels, size_t size) {
230 return true;
231 }
232
233 bool MockDrmDevice::CloseBufferHandle(uint32_t handle) {
234 return true;
235 }
236
237 bool MockDrmDevice::CommitProperties(drmModePropertySet* properties,
238 uint32_t flags,
239 bool is_sync,
240 bool test_only,
241 const PageFlipCallback& callback) {
242 return false;
243 }
244
245 bool MockDrmDevice::SetGammaRamp(uint32_t crtc_id,
246 const std::vector<GammaRampRGBEntry>& lut) {
247 return true;
248 }
249
250 bool MockDrmDevice::SetCapability(uint64_t capability, uint64_t value) {
251 return false;
252 }
253
254 void MockDrmDevice::RunCallbacks() {
255 while (!callbacks_.empty()) {
256 PageFlipCallback callback = callbacks_.front();
257 callbacks_.pop();
258 callback.Run(0, 0, 0);
259 }
260 }
261
262 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/drm/test/mock_drm_device.h ('k') | ui/ozone/platform/egltest/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698