Skip to content

Commit a11c581

Browse files
committed
drm: Convert settings into CogDrmPlatform properties
Turn the settings for atomic mode setting and the device scale factor into properties of the CogDrmPlatform class. This allows using cog_apply_properties_from_key_file() to automatically apply the settings from the configuration file. In the future it may be possible to also pass properties when creating an object with cog_platform_new(), and/or via the "params" argument of cog_platform_setup(), and always using the same mechanism (object properties) regardless of where the values come from.
1 parent 68fc208 commit a11c581

File tree

1 file changed

+76
-57
lines changed

1 file changed

+76
-57
lines changed

platform/drm/cog-platform-drm.c

Lines changed: 76 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,16 @@ struct _CogDrmPlatform {
8080
CogGLRendererRotation rotation;
8181
GList *rotatable_input_devices;
8282
bool use_gles;
83+
gboolean atomic_mode_setting;
84+
float device_scale_factor;
8385
};
8486

8587
enum {
8688
PROP_0,
8789
PROP_ROTATION,
8890
PROP_RENDERER,
91+
PROP_ATOMIC_MODE_SETTING,
92+
PROP_DEVICE_SCALE_FACTOR,
8993
N_PROPERTIES,
9094
};
9195

@@ -127,9 +131,7 @@ static struct {
127131
uint32_t width;
128132
uint32_t height;
129133
uint32_t refresh;
130-
double device_scale;
131134

132-
bool atomic_modesetting;
133135
bool mode_set;
134136
} drm_data = {
135137
.fd = -1,
@@ -156,8 +158,6 @@ static struct {
156158
.width = 0,
157159
.height = 0,
158160
.refresh = 0,
159-
.device_scale = 1.0,
160-
.atomic_modesetting = true,
161161
.mode_set = false,
162162
};
163163

@@ -237,43 +237,11 @@ static struct {
237237
static void
238238
init_config(CogDrmPlatform *self, CogShell *shell, const char *params_string)
239239
{
240-
drm_data.device_scale = cog_shell_get_device_scale_factor (shell);
241-
g_debug ("init_config: overriding device_scale value, using %.2f from shell",
242-
drm_data.device_scale);
243-
244-
GKeyFile *key_file = cog_shell_get_config_file (shell);
245-
240+
GKeyFile *key_file = cog_shell_get_config_file(shell);
246241
if (key_file) {
247-
{
248-
g_autoptr(GError) lookup_error = NULL;
249-
250-
gboolean value = g_key_file_get_boolean(key_file, "drm", "disable-atomic-modesetting", &lookup_error);
251-
if (!lookup_error) {
252-
drm_data.atomic_modesetting = !value;
253-
g_debug("init_config: atomic modesetting reconfigured to value '%s'",
254-
drm_data.atomic_modesetting ? "true" : "false");
255-
}
256-
}
257-
258-
{
259-
g_autoptr(GError) lookup_error = NULL;
260-
261-
gdouble value = g_key_file_get_double(key_file, "drm", "device-scale-factor", &lookup_error);
262-
if (!lookup_error) {
263-
drm_data.device_scale = value;
264-
g_debug("init_config: overriding device_scale value, using %.2f from config", drm_data.device_scale);
265-
}
266-
}
267-
268-
{
269-
g_autofree char *value = g_key_file_get_string(key_file, "drm", "renderer", NULL);
270-
if (g_strcmp0(value, "gles") == 0)
271-
self->use_gles = true;
272-
else if (g_strcmp0(value, "modeset") != 0)
273-
self->use_gles = false;
274-
else if (value)
275-
g_warning("Invalid renderer '%s', using default.", value);
276-
}
242+
g_autoptr(GError) error = NULL;
243+
if (!cog_apply_properties_from_key_file(G_OBJECT(self), key_file, "drm", &error))
244+
g_warning("Reading config file: %s", error->message);
277245
}
278246

279247
if (params_string) {
@@ -308,6 +276,13 @@ init_config(CogDrmPlatform *self, CogShell *shell, const char *params_string)
308276
}
309277
}
310278
}
279+
280+
float device_scale_factor = cog_shell_get_device_scale_factor(shell);
281+
if (device_scale_factor >= 0.2f) {
282+
g_debug("%s: Overriding CogDrmPlatform<%p>.device-scale-factor = <%.2f> from shell", __func__, self,
283+
device_scale_factor);
284+
self->device_scale_factor = device_scale_factor;
285+
}
311286
}
312287

313288
static void
@@ -352,7 +327,7 @@ check_drm(void)
352327
}
353328

354329
static gboolean
355-
init_drm(void)
330+
init_drm(CogDrmPlatform *self)
356331
{
357332
drmDevice *devices[64];
358333
memset(devices, 0, sizeof(*devices) * 64);
@@ -399,10 +374,10 @@ init_drm(void)
399374
if (!drm_data.base_resources)
400375
return FALSE;
401376

402-
if (drm_data.atomic_modesetting) {
377+
if (self->atomic_mode_setting) {
403378
int ret = drmSetClientCap (drm_data.fd, DRM_CLIENT_CAP_ATOMIC, 1);
404379
if (ret) {
405-
drm_data.atomic_modesetting = false;
380+
self->atomic_mode_setting = false;
406381
g_debug ("init_drm: atomic mode not usable, falling back to non-atomic mode");
407382
}
408383
}
@@ -920,7 +895,7 @@ input_handle_pointer_smooth_scroll_event(struct libinput_event_pointer *pointer_
920895
}
921896
#else
922897
static void
923-
input_handle_pointer_axis_event(struct libinput_event_pointer *pointer_event)
898+
input_handle_pointer_axis_event(CogDrmPlatform *self, struct libinput_event_pointer *pointer_event)
924899
{
925900
struct wpe_input_axis_2d_event event = {
926901
.base.type = wpe_input_axis_event_type_mask_2d,
@@ -948,8 +923,8 @@ input_handle_pointer_axis_event(struct libinput_event_pointer *pointer_event)
948923
libinput_event_pointer_get_axis_value(pointer_event, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
949924
}
950925

951-
event.x_axis *= drm_data.device_scale;
952-
event.y_axis *= drm_data.device_scale;
926+
event.x_axis *= self->device_scale_factor;
927+
event.y_axis *= self->device_scale_factor;
953928

954929
wpe_view_backend_dispatch_axis_event(wpe_view_data.backend, &event.base);
955930
}
@@ -1029,7 +1004,7 @@ input_handle_device_removed(struct libinput_device *device)
10291004
}
10301005

10311006
static void
1032-
input_process_events (void)
1007+
input_process_events(CogDrmPlatform *self)
10331008
{
10341009
g_assert (input_data.libinput);
10351010
libinput_dispatch (input_data.libinput);
@@ -1144,7 +1119,7 @@ input_process_events (void)
11441119
break;
11451120
#else
11461121
case LIBINPUT_EVENT_POINTER_AXIS:
1147-
input_handle_pointer_axis_event(libinput_event_get_pointer_event(event));
1122+
input_handle_pointer_axis_event(self, libinput_event_get_pointer_event(event));
11481123
break;
11491124
#endif /* LIBINPUT_CHECK_VERSION(1, 19, 0) */
11501125
default:
@@ -1221,6 +1196,7 @@ struct drm_source {
12211196
struct input_source {
12221197
GSource source;
12231198
GPollFD pfd;
1199+
CogDrmPlatform *platform;
12241200
};
12251201

12261202
static gboolean
@@ -1237,7 +1213,7 @@ input_source_dispatch (GSource *base, GSourceFunc callback, gpointer user_data)
12371213
if (source->pfd.revents & (G_IO_ERR | G_IO_HUP))
12381214
return FALSE;
12391215

1240-
input_process_events ();
1216+
input_process_events(source->platform);
12411217
source->pfd.revents = 0;
12421218
return TRUE;
12431219
}
@@ -1275,7 +1251,7 @@ clear_glib (void)
12751251
}
12761252

12771253
static gboolean
1278-
init_glib (void)
1254+
init_glib(CogDrmPlatform *self)
12791255
{
12801256
static GSourceFuncs input_source_funcs = {
12811257
.check = input_source_check,
@@ -1293,6 +1269,7 @@ init_glib (void)
12931269
source->pfd.fd = libinput_get_fd (input_data.libinput);
12941270
source->pfd.events = G_IO_IN | G_IO_ERR | G_IO_HUP;
12951271
source->pfd.revents = 0;
1272+
source->platform = self;
12961273
g_source_add_poll (glib_data.input_source, &source->pfd);
12971274

12981275
g_source_set_name (glib_data.input_source, "cog: input");
@@ -1351,7 +1328,7 @@ cog_drm_platform_setup(CogPlatform *platform, CogShell *shell, const char *param
13511328
return FALSE;
13521329
}
13531330

1354-
if (!init_drm ()) {
1331+
if (!init_drm(self)) {
13551332
g_set_error_literal (error,
13561333
COG_PLATFORM_WPE_ERROR,
13571334
COG_PLATFORM_WPE_ERROR_INIT,
@@ -1388,14 +1365,14 @@ cog_drm_platform_setup(CogPlatform *platform, CogShell *shell, const char *param
13881365
drm_data.crtc.obj_id,
13891366
drm_data.connector.obj_id,
13901367
drm_data.mode,
1391-
drm_data.atomic_modesetting);
1368+
self->atomic_mode_setting);
13921369
} else {
13931370
self->renderer = cog_drm_modeset_renderer_new(gbm_data.device,
13941371
drm_data.plane.obj_id,
13951372
drm_data.crtc.obj_id,
13961373
drm_data.connector.obj_id,
13971374
drm_data.mode,
1398-
drm_data.atomic_modesetting);
1375+
self->atomic_mode_setting);
13991376
}
14001377
if (cog_drm_renderer_supports_rotation(self->renderer, self->rotation)) {
14011378
cog_drm_renderer_set_rotation(self->renderer, self->rotation);
@@ -1413,7 +1390,7 @@ cog_drm_platform_setup(CogPlatform *platform, CogShell *shell, const char *param
14131390
return FALSE;
14141391
}
14151392

1416-
if (!init_glib ()) {
1393+
if (!init_glib(self)) {
14171394
g_set_error_literal (error,
14181395
COG_PLATFORM_WPE_ERROR,
14191396
COG_PLATFORM_WPE_ERROR_INIT,
@@ -1458,8 +1435,8 @@ cog_drm_platform_get_view_backend(CogPlatform *platform, WebKitWebView *related_
14581435
{
14591436
CogDrmPlatform *self = COG_DRM_PLATFORM(platform);
14601437
wpe_host_data.exportable = self->renderer->create_exportable(self->renderer,
1461-
drm_data.width / drm_data.device_scale,
1462-
drm_data.height / drm_data.device_scale);
1438+
drm_data.width / self->device_scale_factor,
1439+
drm_data.height / self->device_scale_factor);
14631440
g_assert (wpe_host_data.exportable);
14641441

14651442
wpe_view_data.backend = wpe_view_backend_exportable_fdo_get_view_backend (wpe_host_data.exportable);
@@ -1486,7 +1463,8 @@ set_target_refresh_rate(gpointer user_data)
14861463
static void
14871464
cog_drm_platform_init_web_view(CogPlatform *platform, WebKitWebView *view)
14881465
{
1489-
wpe_view_backend_dispatch_set_device_scale_factor(wpe_view_data.backend, drm_data.device_scale);
1466+
CogDrmPlatform *self = COG_DRM_PLATFORM(platform);
1467+
wpe_view_backend_dispatch_set_device_scale_factor(wpe_view_data.backend, self->device_scale_factor);
14901468

14911469
#if HAVE_REFRESH_RATE_HANDLING
14921470
g_idle_add(G_SOURCE_FUNC(set_target_refresh_rate), &wpe_view_data);
@@ -1525,6 +1503,12 @@ cog_drm_platform_set_property(GObject *object, unsigned prop_id, const GValue *v
15251503
}
15261504
break;
15271505
}
1506+
case PROP_ATOMIC_MODE_SETTING:
1507+
self->atomic_mode_setting = g_value_get_boolean(value);
1508+
break;
1509+
case PROP_DEVICE_SCALE_FACTOR:
1510+
self->device_scale_factor = g_value_get_float(value);
1511+
break;
15281512
default:
15291513
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
15301514
}
@@ -1541,6 +1525,12 @@ cog_drm_platform_get_property(GObject *object, unsigned prop_id, GValue *value,
15411525
case PROP_RENDERER:
15421526
g_value_set_string(value, self->use_gles ? "gles" : "modeset");
15431527
break;
1528+
case PROP_ATOMIC_MODE_SETTING:
1529+
g_value_set_boolean(value, self->atomic_mode_setting);
1530+
break;
1531+
case PROP_DEVICE_SCALE_FACTOR:
1532+
g_value_set_float(value, self->device_scale_factor);
1533+
break;
15441534
default:
15451535
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
15461536
}
@@ -1593,6 +1583,35 @@ cog_drm_platform_class_init(CogDrmPlatformClass *klass)
15931583
"modeset",
15941584
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
15951585

1586+
/**
1587+
* CogDrmPlatform:atomic-mode-setting:
1588+
*
1589+
* Whether to use DRM/KMS atomic mode setting.
1590+
*
1591+
* Even if initially enabled, if the driver reports the feature as not
1592+
* supported the setting will be disabled automatically. Explicitly
1593+
* disabling atomic mode setting is rarely needed, but might fix issues
1594+
* with certain drivers.
1595+
*
1596+
* Since: 0.18
1597+
*/
1598+
s_properties[PROP_ATOMIC_MODE_SETTING] = g_param_spec_boolean("atomic-mode-setting",
1599+
"Atomic mode setting",
1600+
"Use DRM/KMS atomic mode setting",
1601+
TRUE,
1602+
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1603+
1604+
/**
1605+
* CogDrmPlatform:device-scale-factor:
1606+
*
1607+
* Scaling factor applied to the output device.
1608+
*
1609+
* Since: 0.18
1610+
*/
1611+
s_properties[PROP_DEVICE_SCALE_FACTOR] =
1612+
g_param_spec_float("device-scale-factor", "Device scale factor", "Output device scaling factor", 0.25f, 5.0f,
1613+
1.0f, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1614+
15961615
g_object_class_install_properties(object_class, N_PROPERTIES, s_properties);
15971616
}
15981617

0 commit comments

Comments
 (0)