Skip to content

Commit 12d41f3

Browse files
author
Mai-Matsuura
authored
Fix DRM related processing of eglstream. (#75)
1 parent 178dc6f commit 12d41f3

File tree

2 files changed

+51
-132
lines changed

2 files changed

+51
-132
lines changed

src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.cc

Lines changed: 45 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ NativeWindowDrmEglstream::~NativeWindowDrmEglstream() {
4848
drmModeDestroyPropertyBlob(drm_device_, drm_property_blob_);
4949
}
5050

51-
if (drm_fb_) {
52-
drmModeRmFB(drm_device_, drm_fb_);
53-
}
54-
5551
close(drm_device_);
5652
}
5753

@@ -184,80 +180,65 @@ bool NativeWindowDrmEglstream::AssignAtomicRequest(drmModeAtomicReqPtr atomic) {
184180
return false;
185181
}
186182

187-
if (!CreateFb()) {
183+
// Set the crtc mode and activate.
184+
NativeWindowDrmEglstream::DrmProperty crtc_table[] = {
185+
{"MODE_ID", drm_property_blob_},
186+
{"ACTIVE", 1},
187+
};
188+
if (!AssignAtomicPropertyValue(atomic, drm_crtc_->crtc_id,
189+
DRM_MODE_OBJECT_CRTC, crtc_table)) {
188190
return false;
189191
}
190192

191-
NativeWindowDrmEglstream::DrmPropertyIds property_ids = {0};
192-
GetPropertyIds(property_ids);
193-
drmModeAtomicAddProperty(atomic, drm_crtc_->crtc_id,
194-
property_ids.crtc.mode_id, drm_property_blob_);
195-
drmModeAtomicAddProperty(atomic, drm_crtc_->crtc_id, property_ids.crtc.active,
196-
1);
197-
drmModeAtomicAddProperty(atomic, drm_connector_id_,
198-
property_ids.connector.crtc_id, drm_crtc_->crtc_id);
199-
drmModeAtomicAddProperty(atomic, drm_plane_id_, property_ids.plane.src_x, 0);
200-
drmModeAtomicAddProperty(atomic, drm_plane_id_, property_ids.plane.src_y, 0);
201-
drmModeAtomicAddProperty(atomic, drm_plane_id_, property_ids.plane.src_w,
202-
drm_mode_info_.hdisplay << 16);
203-
drmModeAtomicAddProperty(atomic, drm_plane_id_, property_ids.plane.src_h,
204-
drm_mode_info_.vdisplay << 16);
205-
drmModeAtomicAddProperty(atomic, drm_plane_id_, property_ids.plane.crtc_x, 0);
206-
drmModeAtomicAddProperty(atomic, drm_plane_id_, property_ids.plane.crtc_y, 0);
207-
drmModeAtomicAddProperty(atomic, drm_plane_id_, property_ids.plane.crtc_w,
208-
drm_mode_info_.hdisplay);
209-
drmModeAtomicAddProperty(atomic, drm_plane_id_, property_ids.plane.crtc_h,
210-
drm_mode_info_.vdisplay);
211-
drmModeAtomicAddProperty(atomic, drm_plane_id_, property_ids.plane.fb_id,
212-
drm_fb_);
213-
drmModeAtomicAddProperty(atomic, drm_plane_id_, property_ids.plane.crtc_id,
214-
drm_crtc_->crtc_id);
215-
return true;
216-
}
217-
218-
void NativeWindowDrmEglstream::GetPropertyIds(
219-
NativeWindowDrmEglstream::DrmPropertyIds& property_ids) {
220-
struct DrmPropertyAddress crtc_table[] = {
221-
{"MODE_ID", &property_ids.crtc.mode_id},
222-
{"ACTIVE", &property_ids.crtc.active},
223-
};
224-
struct DrmPropertyAddress plane_table[] = {
225-
{"SRC_X", &property_ids.plane.src_x},
226-
{"SRC_Y", &property_ids.plane.src_y},
227-
{"SRC_W", &property_ids.plane.src_w},
228-
{"SRC_H", &property_ids.plane.src_h},
229-
{"CRTC_X", &property_ids.plane.crtc_x},
230-
{"CRTC_Y", &property_ids.plane.crtc_y},
231-
{"CRTC_W", &property_ids.plane.crtc_w},
232-
{"CRTC_H", &property_ids.plane.crtc_h},
233-
{"FB_ID", &property_ids.plane.fb_id},
234-
{"CRTC_ID", &property_ids.plane.crtc_id},
235-
{"CRTC_ID", &property_ids.connector.crtc_id},
193+
// Set the connector.
194+
NativeWindowDrmEglstream::DrmProperty connector_table[] = {
195+
{"CRTC_ID", drm_crtc_->crtc_id},
236196
};
237-
struct DrmPropertyAddress connector_table[] = {
238-
{"CRTC_ID", &property_ids.connector.crtc_id},
197+
if (!AssignAtomicPropertyValue(atomic, drm_connector_id_,
198+
DRM_MODE_OBJECT_CONNECTOR, connector_table)) {
199+
return false;
200+
}
201+
202+
// Set the plane source position, plane destination position, and crtc to
203+
// connect plane.
204+
NativeWindowDrmEglstream::DrmProperty plane_table[] = {
205+
{"SRC_X", 0},
206+
{"SRC_Y", 0},
207+
{"SRC_W", static_cast<uint64_t>(drm_mode_info_.hdisplay << 16)},
208+
{"SRC_H", static_cast<uint64_t>(drm_mode_info_.vdisplay << 16)},
209+
{"CRTC_X", 0},
210+
{"CRTC_Y", 0},
211+
{"CRTC_W", static_cast<uint64_t>(drm_mode_info_.hdisplay)},
212+
{"CRTC_H", static_cast<uint64_t>(drm_mode_info_.vdisplay)},
213+
{"CRTC_ID", drm_crtc_->crtc_id},
239214
};
215+
if (!AssignAtomicPropertyValue(atomic, drm_plane_id_, DRM_MODE_OBJECT_PLANE,
216+
plane_table)) {
217+
return false;
218+
}
240219

241-
GetPropertyAddress(drm_crtc_->crtc_id, DRM_MODE_OBJECT_CRTC, crtc_table,
242-
sizeof(crtc_table) / sizeof(DrmPropertyAddress));
243-
GetPropertyAddress(drm_plane_id_, DRM_MODE_OBJECT_PLANE, plane_table,
244-
sizeof(plane_table) / sizeof(DrmPropertyAddress));
245-
GetPropertyAddress(drm_connector_id_, DRM_MODE_OBJECT_CONNECTOR,
246-
connector_table,
247-
sizeof(connector_table) / sizeof(DrmPropertyAddress));
220+
return true;
248221
}
249222

250-
void NativeWindowDrmEglstream::GetPropertyAddress(
251-
uint32_t id, uint32_t type,
252-
NativeWindowDrmEglstream::DrmPropertyAddress* table, size_t length) {
223+
template <size_t N>
224+
bool NativeWindowDrmEglstream::AssignAtomicPropertyValue(
225+
drmModeAtomicReqPtr atomic, uint32_t id, uint32_t type,
226+
NativeWindowDrmEglstream::DrmProperty (&table)[N]) {
253227
auto properties = drmModeObjectGetProperties(drm_device_, id, type);
254228
if (properties) {
255229
for (uint32_t i = 0; i < properties->count_props; i++) {
256230
auto property = drmModeGetProperty(drm_device_, properties->props[i]);
257231
if (property) {
258-
for (uint32_t j = 0; j < length; j++) {
232+
for (uint32_t j = 0; j < N; j++) {
259233
if (std::strcmp(table[j].name, property->name) == 0) {
260-
*(table[j].ptr) = property->prop_id;
234+
if (drmModeAtomicAddProperty(atomic, id, property->prop_id,
235+
table[j].value) < 0) {
236+
LINUXES_LOG(ERROR)
237+
<< "Failed to add " << table[j].name << " property";
238+
drmModeFreeProperty(property);
239+
drmModeFreeObjectProperties(properties);
240+
return false;
241+
}
261242
break;
262243
}
263244
}
@@ -266,41 +247,6 @@ void NativeWindowDrmEglstream::GetPropertyAddress(
266247
}
267248
drmModeFreeObjectProperties(properties);
268249
}
269-
}
270-
271-
bool NativeWindowDrmEglstream::CreateFb() {
272-
struct drm_mode_create_dumb create_dump = {0};
273-
create_dump.width = drm_mode_info_.hdisplay;
274-
create_dump.height = drm_mode_info_.vdisplay;
275-
create_dump.bpp = 32;
276-
if (drmIoctl(drm_device_, DRM_IOCTL_MODE_CREATE_DUMB, &create_dump) != 0) {
277-
LINUXES_LOG(ERROR) << "Failed to create dumb buffer";
278-
return false;
279-
}
280-
281-
if (drmModeAddFB(drm_device_, drm_mode_info_.hdisplay,
282-
drm_mode_info_.vdisplay, 24, 32, create_dump.pitch,
283-
create_dump.handle, &drm_fb_) != 0) {
284-
LINUXES_LOG(ERROR) << "Failed to add a framebuffer";
285-
return false;
286-
}
287-
288-
struct drm_mode_map_dumb map_dump = {0};
289-
map_dump.handle = create_dump.handle;
290-
if (drmIoctl(drm_device_, DRM_IOCTL_MODE_MAP_DUMB, &map_dump) != 0) {
291-
LINUXES_LOG(ERROR) << "Failed to map dumb buffer";
292-
return false;
293-
}
294-
295-
auto map =
296-
static_cast<uint8_t*>(mmap(0, create_dump.size, PROT_READ | PROT_WRITE,
297-
MAP_SHARED, drm_device_, map_dump.offset));
298-
if (map == MAP_FAILED) {
299-
LINUXES_LOG(ERROR) << "Failed to mmap fb";
300-
return false;
301-
}
302-
303-
memset(map, 0, create_dump.size);
304250
return true;
305251
}
306252

src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.h

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -39,33 +39,9 @@ class NativeWindowDrmEglstream
3939
uint32_t PlaneId() { return drm_plane_id_; }
4040

4141
private:
42-
struct DrmPropertyIds {
43-
struct {
44-
uint32_t mode_id;
45-
uint32_t active;
46-
} crtc;
47-
48-
struct {
49-
uint32_t src_x;
50-
uint32_t src_y;
51-
uint32_t src_w;
52-
uint32_t src_h;
53-
uint32_t crtc_x;
54-
uint32_t crtc_y;
55-
uint32_t crtc_w;
56-
uint32_t crtc_h;
57-
uint32_t fb_id;
58-
uint32_t crtc_id;
59-
} plane;
60-
61-
struct {
62-
uint32_t crtc_id;
63-
} connector;
64-
};
65-
66-
struct DrmPropertyAddress {
42+
struct DrmProperty {
6743
const char* name;
68-
uint32_t* ptr;
44+
uint64_t value;
6945
};
7046

7147
bool ConfigureDisplayAdditional();
@@ -78,16 +54,13 @@ class NativeWindowDrmEglstream
7854

7955
bool AssignAtomicRequest(drmModeAtomicReqPtr atomic);
8056

81-
void GetPropertyIds(DrmPropertyIds& property_ids);
82-
83-
void GetPropertyAddress(uint32_t id, uint32_t type, DrmPropertyAddress* table,
84-
size_t length);
85-
86-
bool CreateFb();
57+
template <size_t N>
58+
bool AssignAtomicPropertyValue(
59+
drmModeAtomicReqPtr atomic, uint32_t id, uint32_t type,
60+
NativeWindowDrmEglstream::DrmProperty (&table)[N]);
8761

8862
uint32_t drm_plane_id_;
8963
uint32_t drm_property_blob_ = 0;
90-
uint32_t drm_fb_ = 0;
9164
};
9265

9366
} // namespace flutter

0 commit comments

Comments
 (0)