@@ -80,12 +80,16 @@ struct _CogDrmPlatform {
80
80
CogGLRendererRotation rotation ;
81
81
GList * rotatable_input_devices ;
82
82
bool use_gles ;
83
+ gboolean atomic_mode_setting ;
84
+ float device_scale_factor ;
83
85
};
84
86
85
87
enum {
86
88
PROP_0 ,
87
89
PROP_ROTATION ,
88
90
PROP_RENDERER ,
91
+ PROP_ATOMIC_MODE_SETTING ,
92
+ PROP_DEVICE_SCALE_FACTOR ,
89
93
N_PROPERTIES ,
90
94
};
91
95
@@ -127,9 +131,7 @@ static struct {
127
131
uint32_t width ;
128
132
uint32_t height ;
129
133
uint32_t refresh ;
130
- double device_scale ;
131
134
132
- bool atomic_modesetting ;
133
135
bool mode_set ;
134
136
} drm_data = {
135
137
.fd = -1 ,
@@ -156,8 +158,6 @@ static struct {
156
158
.width = 0 ,
157
159
.height = 0 ,
158
160
.refresh = 0 ,
159
- .device_scale = 1.0 ,
160
- .atomic_modesetting = true,
161
161
.mode_set = false,
162
162
};
163
163
@@ -237,43 +237,11 @@ static struct {
237
237
static void
238
238
init_config (CogDrmPlatform * self , CogShell * shell , const char * params_string )
239
239
{
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 );
246
241
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 );
277
245
}
278
246
279
247
if (params_string ) {
@@ -308,6 +276,13 @@ init_config(CogDrmPlatform *self, CogShell *shell, const char *params_string)
308
276
}
309
277
}
310
278
}
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
+ }
311
286
}
312
287
313
288
static void
@@ -352,7 +327,7 @@ check_drm(void)
352
327
}
353
328
354
329
static gboolean
355
- init_drm (void )
330
+ init_drm (CogDrmPlatform * self )
356
331
{
357
332
drmDevice * devices [64 ];
358
333
memset (devices , 0 , sizeof (* devices ) * 64 );
@@ -399,10 +374,10 @@ init_drm(void)
399
374
if (!drm_data .base_resources )
400
375
return FALSE;
401
376
402
- if (drm_data . atomic_modesetting ) {
377
+ if (self -> atomic_mode_setting ) {
403
378
int ret = drmSetClientCap (drm_data .fd , DRM_CLIENT_CAP_ATOMIC , 1 );
404
379
if (ret ) {
405
- drm_data . atomic_modesetting = false;
380
+ self -> atomic_mode_setting = false;
406
381
g_debug ("init_drm: atomic mode not usable, falling back to non-atomic mode" );
407
382
}
408
383
}
@@ -920,7 +895,7 @@ input_handle_pointer_smooth_scroll_event(struct libinput_event_pointer *pointer_
920
895
}
921
896
#else
922
897
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 )
924
899
{
925
900
struct wpe_input_axis_2d_event event = {
926
901
.base .type = wpe_input_axis_event_type_mask_2d ,
@@ -948,8 +923,8 @@ input_handle_pointer_axis_event(struct libinput_event_pointer *pointer_event)
948
923
libinput_event_pointer_get_axis_value (pointer_event , LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL );
949
924
}
950
925
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 ;
953
928
954
929
wpe_view_backend_dispatch_axis_event (wpe_view_data .backend , & event .base );
955
930
}
@@ -1029,7 +1004,7 @@ input_handle_device_removed(struct libinput_device *device)
1029
1004
}
1030
1005
1031
1006
static void
1032
- input_process_events ( void )
1007
+ input_process_events ( CogDrmPlatform * self )
1033
1008
{
1034
1009
g_assert (input_data .libinput );
1035
1010
libinput_dispatch (input_data .libinput );
@@ -1144,7 +1119,7 @@ input_process_events (void)
1144
1119
break ;
1145
1120
#else
1146
1121
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 ));
1148
1123
break ;
1149
1124
#endif /* LIBINPUT_CHECK_VERSION(1, 19, 0) */
1150
1125
default :
@@ -1221,6 +1196,7 @@ struct drm_source {
1221
1196
struct input_source {
1222
1197
GSource source ;
1223
1198
GPollFD pfd ;
1199
+ CogDrmPlatform * platform ;
1224
1200
};
1225
1201
1226
1202
static gboolean
@@ -1237,7 +1213,7 @@ input_source_dispatch (GSource *base, GSourceFunc callback, gpointer user_data)
1237
1213
if (source -> pfd .revents & (G_IO_ERR | G_IO_HUP ))
1238
1214
return FALSE;
1239
1215
1240
- input_process_events ( );
1216
+ input_process_events ( source -> platform );
1241
1217
source -> pfd .revents = 0 ;
1242
1218
return TRUE;
1243
1219
}
@@ -1275,7 +1251,7 @@ clear_glib (void)
1275
1251
}
1276
1252
1277
1253
static gboolean
1278
- init_glib ( void )
1254
+ init_glib ( CogDrmPlatform * self )
1279
1255
{
1280
1256
static GSourceFuncs input_source_funcs = {
1281
1257
.check = input_source_check ,
@@ -1293,6 +1269,7 @@ init_glib (void)
1293
1269
source -> pfd .fd = libinput_get_fd (input_data .libinput );
1294
1270
source -> pfd .events = G_IO_IN | G_IO_ERR | G_IO_HUP ;
1295
1271
source -> pfd .revents = 0 ;
1272
+ source -> platform = self ;
1296
1273
g_source_add_poll (glib_data .input_source , & source -> pfd );
1297
1274
1298
1275
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
1351
1328
return FALSE;
1352
1329
}
1353
1330
1354
- if (!init_drm ( )) {
1331
+ if (!init_drm ( self )) {
1355
1332
g_set_error_literal (error ,
1356
1333
COG_PLATFORM_WPE_ERROR ,
1357
1334
COG_PLATFORM_WPE_ERROR_INIT ,
@@ -1388,14 +1365,14 @@ cog_drm_platform_setup(CogPlatform *platform, CogShell *shell, const char *param
1388
1365
drm_data .crtc .obj_id ,
1389
1366
drm_data .connector .obj_id ,
1390
1367
drm_data .mode ,
1391
- drm_data . atomic_modesetting );
1368
+ self -> atomic_mode_setting );
1392
1369
} else {
1393
1370
self -> renderer = cog_drm_modeset_renderer_new (gbm_data .device ,
1394
1371
drm_data .plane .obj_id ,
1395
1372
drm_data .crtc .obj_id ,
1396
1373
drm_data .connector .obj_id ,
1397
1374
drm_data .mode ,
1398
- drm_data . atomic_modesetting );
1375
+ self -> atomic_mode_setting );
1399
1376
}
1400
1377
if (cog_drm_renderer_supports_rotation (self -> renderer , self -> rotation )) {
1401
1378
cog_drm_renderer_set_rotation (self -> renderer , self -> rotation );
@@ -1413,7 +1390,7 @@ cog_drm_platform_setup(CogPlatform *platform, CogShell *shell, const char *param
1413
1390
return FALSE;
1414
1391
}
1415
1392
1416
- if (!init_glib ( )) {
1393
+ if (!init_glib ( self )) {
1417
1394
g_set_error_literal (error ,
1418
1395
COG_PLATFORM_WPE_ERROR ,
1419
1396
COG_PLATFORM_WPE_ERROR_INIT ,
@@ -1458,8 +1435,8 @@ cog_drm_platform_get_view_backend(CogPlatform *platform, WebKitWebView *related_
1458
1435
{
1459
1436
CogDrmPlatform * self = COG_DRM_PLATFORM (platform );
1460
1437
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 );
1463
1440
g_assert (wpe_host_data .exportable );
1464
1441
1465
1442
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)
1486
1463
static void
1487
1464
cog_drm_platform_init_web_view (CogPlatform * platform , WebKitWebView * view )
1488
1465
{
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 );
1490
1468
1491
1469
#if HAVE_REFRESH_RATE_HANDLING
1492
1470
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
1525
1503
}
1526
1504
break ;
1527
1505
}
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 ;
1528
1512
default :
1529
1513
G_OBJECT_WARN_INVALID_PROPERTY_ID (object , prop_id , pspec );
1530
1514
}
@@ -1541,6 +1525,12 @@ cog_drm_platform_get_property(GObject *object, unsigned prop_id, GValue *value,
1541
1525
case PROP_RENDERER :
1542
1526
g_value_set_string (value , self -> use_gles ? "gles" : "modeset" );
1543
1527
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 ;
1544
1534
default :
1545
1535
G_OBJECT_WARN_INVALID_PROPERTY_ID (object , prop_id , pspec );
1546
1536
}
@@ -1593,6 +1583,35 @@ cog_drm_platform_class_init(CogDrmPlatformClass *klass)
1593
1583
"modeset" ,
1594
1584
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS );
1595
1585
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
+
1596
1615
g_object_class_install_properties (object_class , N_PROPERTIES , s_properties );
1597
1616
}
1598
1617
0 commit comments