@@ -81,12 +81,16 @@ struct _CogDrmPlatform {
81
81
CogGLRendererRotation rotation ;
82
82
GList * rotatable_input_devices ;
83
83
bool use_gles ;
84
+ gboolean atomic_mode_setting ;
85
+ float device_scale_factor ;
84
86
};
85
87
86
88
enum {
87
89
PROP_0 ,
88
90
PROP_ROTATION ,
89
91
PROP_RENDERER ,
92
+ PROP_ATOMIC_MODE_SETTING ,
93
+ PROP_DEVICE_SCALE_FACTOR ,
90
94
N_PROPERTIES ,
91
95
};
92
96
@@ -128,9 +132,7 @@ static struct {
128
132
uint32_t width ;
129
133
uint32_t height ;
130
134
uint32_t refresh ;
131
- double device_scale ;
132
135
133
- bool atomic_modesetting ;
134
136
bool mode_set ;
135
137
} drm_data = {
136
138
.fd = -1 ,
@@ -157,8 +159,6 @@ static struct {
157
159
.width = 0 ,
158
160
.height = 0 ,
159
161
.refresh = 0 ,
160
- .device_scale = 1.0 ,
161
- .atomic_modesetting = true,
162
162
.mode_set = false,
163
163
};
164
164
@@ -238,43 +238,11 @@ static struct {
238
238
static void
239
239
init_config (CogDrmPlatform * self , CogShell * shell , const char * params_string )
240
240
{
241
- drm_data .device_scale = cog_shell_get_device_scale_factor (shell );
242
- g_debug ("init_config: overriding device_scale value, using %.2f from shell" ,
243
- drm_data .device_scale );
244
-
245
- GKeyFile * key_file = cog_shell_get_config_file (shell );
246
-
241
+ GKeyFile * key_file = cog_shell_get_config_file (shell );
247
242
if (key_file ) {
248
- {
249
- g_autoptr (GError ) lookup_error = NULL ;
250
-
251
- gboolean value = g_key_file_get_boolean (key_file , "drm" , "disable-atomic-modesetting" , & lookup_error );
252
- if (!lookup_error ) {
253
- drm_data .atomic_modesetting = !value ;
254
- g_debug ("init_config: atomic modesetting reconfigured to value '%s'" ,
255
- drm_data .atomic_modesetting ? "true" : "false" );
256
- }
257
- }
258
-
259
- {
260
- g_autoptr (GError ) lookup_error = NULL ;
261
-
262
- gdouble value = g_key_file_get_double (key_file , "drm" , "device-scale-factor" , & lookup_error );
263
- if (!lookup_error ) {
264
- drm_data .device_scale = value ;
265
- g_debug ("init_config: overriding device_scale value, using %.2f from config" , drm_data .device_scale );
266
- }
267
- }
268
-
269
- {
270
- g_autofree char * value = g_key_file_get_string (key_file , "drm" , "renderer" , NULL );
271
- if (g_strcmp0 (value , "gles" ) == 0 )
272
- self -> use_gles = true;
273
- else if (g_strcmp0 (value , "modeset" ) != 0 )
274
- self -> use_gles = false;
275
- else if (value )
276
- g_warning ("Invalid renderer '%s', using default." , value );
277
- }
243
+ g_autoptr (GError ) error = NULL ;
244
+ if (!cog_apply_properties_from_key_file (G_OBJECT (self ), key_file , "drm" , & error ))
245
+ g_warning ("Reading config file: %s" , error -> message );
278
246
}
279
247
280
248
if (params_string ) {
@@ -309,6 +277,13 @@ init_config(CogDrmPlatform *self, CogShell *shell, const char *params_string)
309
277
}
310
278
}
311
279
}
280
+
281
+ float device_scale_factor = cog_shell_get_device_scale_factor (shell );
282
+ if (device_scale_factor >= 0.2f ) {
283
+ g_debug ("%s: Overriding CogDrmPlatform<%p>.device-scale-factor = <%.2f> from shell" , __func__ , self ,
284
+ device_scale_factor );
285
+ self -> device_scale_factor = device_scale_factor ;
286
+ }
312
287
}
313
288
314
289
static void
@@ -368,7 +343,7 @@ find_crtc_for_encoder(const drmModeRes *resources, const drmModeEncoder *encoder
368
343
}
369
344
370
345
static gboolean
371
- init_drm (void )
346
+ init_drm (CogDrmPlatform * self )
372
347
{
373
348
drmDevice * devices [64 ];
374
349
memset (devices , 0 , sizeof (* devices ) * 64 );
@@ -415,10 +390,10 @@ init_drm(void)
415
390
if (!drm_data .base_resources )
416
391
return FALSE;
417
392
418
- if (drm_data . atomic_modesetting ) {
393
+ if (self -> atomic_mode_setting ) {
419
394
int ret = drmSetClientCap (drm_data .fd , DRM_CLIENT_CAP_ATOMIC , 1 );
420
395
if (ret ) {
421
- drm_data . atomic_modesetting = false;
396
+ self -> atomic_mode_setting = false;
422
397
g_debug ("init_drm: atomic mode not usable, falling back to non-atomic mode" );
423
398
}
424
399
}
@@ -963,7 +938,7 @@ input_handle_pointer_smooth_scroll_event(struct libinput_event_pointer *pointer_
963
938
}
964
939
#else
965
940
static void
966
- input_handle_pointer_axis_event (struct libinput_event_pointer * pointer_event )
941
+ input_handle_pointer_axis_event (CogDrmPlatform * self , struct libinput_event_pointer * pointer_event )
967
942
{
968
943
struct wpe_input_axis_2d_event event = {
969
944
.base .type = wpe_input_axis_event_type_mask_2d ,
@@ -991,8 +966,8 @@ input_handle_pointer_axis_event(struct libinput_event_pointer *pointer_event)
991
966
libinput_event_pointer_get_axis_value (pointer_event , LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL );
992
967
}
993
968
994
- event .x_axis *= drm_data . device_scale ;
995
- event .y_axis *= drm_data . device_scale ;
969
+ event .x_axis *= self -> device_scale_factor ;
970
+ event .y_axis *= self -> device_scale_factor ;
996
971
997
972
wpe_view_backend_dispatch_axis_event (wpe_view_data .backend , & event .base );
998
973
}
@@ -1072,7 +1047,7 @@ input_handle_device_removed(struct libinput_device *device)
1072
1047
}
1073
1048
1074
1049
static void
1075
- input_process_events ( void )
1050
+ input_process_events ( CogDrmPlatform * self )
1076
1051
{
1077
1052
g_assert (input_data .libinput );
1078
1053
@@ -1189,7 +1164,7 @@ input_process_events (void)
1189
1164
break ;
1190
1165
#else
1191
1166
case LIBINPUT_EVENT_POINTER_AXIS :
1192
- input_handle_pointer_axis_event (libinput_event_get_pointer_event (event ));
1167
+ input_handle_pointer_axis_event (self , libinput_event_get_pointer_event (event ));
1193
1168
break ;
1194
1169
#endif /* LIBINPUT_CHECK_VERSION(1, 19, 0) */
1195
1170
default :
@@ -1282,6 +1257,7 @@ struct drm_source {
1282
1257
struct input_source {
1283
1258
GSource source ;
1284
1259
GPollFD pfd ;
1260
+ CogDrmPlatform * platform ;
1285
1261
};
1286
1262
1287
1263
static gboolean
@@ -1298,7 +1274,7 @@ input_source_dispatch (GSource *base, GSourceFunc callback, gpointer user_data)
1298
1274
if (source -> pfd .revents & (G_IO_ERR | G_IO_HUP ))
1299
1275
return FALSE;
1300
1276
1301
- input_process_events ( );
1277
+ input_process_events ( source -> platform );
1302
1278
source -> pfd .revents = 0 ;
1303
1279
return TRUE;
1304
1280
}
@@ -1349,6 +1325,7 @@ init_glib(CogDrmPlatform *self)
1349
1325
source -> pfd .fd = libinput_get_fd (input_data .libinput );
1350
1326
source -> pfd .events = G_IO_IN | G_IO_ERR | G_IO_HUP ;
1351
1327
source -> pfd .revents = 0 ;
1328
+ source -> platform = self ;
1352
1329
g_source_add_poll (glib_data .input_source , & source -> pfd );
1353
1330
1354
1331
g_source_set_name (glib_data .input_source , "cog: input" );
@@ -1408,7 +1385,7 @@ cog_drm_platform_setup(CogPlatform *platform, CogShell *shell, const char *param
1408
1385
return FALSE;
1409
1386
}
1410
1387
1411
- if (!init_drm ( )) {
1388
+ if (!init_drm ( self )) {
1412
1389
g_set_error_literal (error ,
1413
1390
COG_PLATFORM_WPE_ERROR ,
1414
1391
COG_PLATFORM_WPE_ERROR_INIT ,
@@ -1445,14 +1422,14 @@ cog_drm_platform_setup(CogPlatform *platform, CogShell *shell, const char *param
1445
1422
drm_data .crtc .obj_id ,
1446
1423
drm_data .connector .obj_id ,
1447
1424
drm_data .mode ,
1448
- drm_data . atomic_modesetting );
1425
+ self -> atomic_mode_setting );
1449
1426
} else {
1450
1427
self -> renderer = cog_drm_modeset_renderer_new (gbm_data .device ,
1451
1428
drm_data .plane .obj_id ,
1452
1429
drm_data .crtc .obj_id ,
1453
1430
drm_data .connector .obj_id ,
1454
1431
drm_data .mode ,
1455
- drm_data . atomic_modesetting );
1432
+ self -> atomic_mode_setting );
1456
1433
}
1457
1434
if (cog_drm_renderer_supports_rotation (self -> renderer , self -> rotation )) {
1458
1435
cog_drm_renderer_set_rotation (self -> renderer , self -> rotation );
@@ -1515,8 +1492,8 @@ cog_drm_platform_get_view_backend(CogPlatform *platform, WebKitWebView *related_
1515
1492
{
1516
1493
CogDrmPlatform * self = COG_DRM_PLATFORM (platform );
1517
1494
wpe_host_data .exportable = self -> renderer -> create_exportable (self -> renderer ,
1518
- drm_data .width / drm_data . device_scale ,
1519
- drm_data .height / drm_data . device_scale );
1495
+ drm_data .width / self -> device_scale_factor ,
1496
+ drm_data .height / self -> device_scale_factor );
1520
1497
g_assert (wpe_host_data .exportable );
1521
1498
1522
1499
wpe_view_data .backend = wpe_view_backend_exportable_fdo_get_view_backend (wpe_host_data .exportable );
@@ -1543,9 +1520,11 @@ set_target_refresh_rate(gpointer user_data)
1543
1520
static void
1544
1521
cog_drm_platform_init_web_view (CogPlatform * platform , WebKitWebView * view )
1545
1522
{
1546
- COG_DRM_PLATFORM ( platform ) -> web_view = COG_VIEW ( view );
1523
+ CogDrmPlatform * self = COG_DRM_PLATFORM ( platform );
1547
1524
1548
- wpe_view_backend_dispatch_set_device_scale_factor (wpe_view_data .backend , drm_data .device_scale );
1525
+ self -> web_view = COG_VIEW (view );
1526
+
1527
+ wpe_view_backend_dispatch_set_device_scale_factor (wpe_view_data .backend , self -> device_scale_factor );
1549
1528
1550
1529
#if HAVE_REFRESH_RATE_HANDLING
1551
1530
g_idle_add (G_SOURCE_FUNC (set_target_refresh_rate ), & wpe_view_data );
@@ -1584,6 +1563,12 @@ cog_drm_platform_set_property(GObject *object, unsigned prop_id, const GValue *v
1584
1563
}
1585
1564
break ;
1586
1565
}
1566
+ case PROP_ATOMIC_MODE_SETTING :
1567
+ self -> atomic_mode_setting = g_value_get_boolean (value );
1568
+ break ;
1569
+ case PROP_DEVICE_SCALE_FACTOR :
1570
+ self -> device_scale_factor = g_value_get_float (value );
1571
+ break ;
1587
1572
default :
1588
1573
G_OBJECT_WARN_INVALID_PROPERTY_ID (object , prop_id , pspec );
1589
1574
}
@@ -1600,6 +1585,12 @@ cog_drm_platform_get_property(GObject *object, unsigned prop_id, GValue *value,
1600
1585
case PROP_RENDERER :
1601
1586
g_value_set_string (value , self -> use_gles ? "gles" : "modeset" );
1602
1587
break ;
1588
+ case PROP_ATOMIC_MODE_SETTING :
1589
+ g_value_set_boolean (value , self -> atomic_mode_setting );
1590
+ break ;
1591
+ case PROP_DEVICE_SCALE_FACTOR :
1592
+ g_value_set_float (value , self -> device_scale_factor );
1593
+ break ;
1603
1594
default :
1604
1595
G_OBJECT_WARN_INVALID_PROPERTY_ID (object , prop_id , pspec );
1605
1596
}
@@ -1652,6 +1643,35 @@ cog_drm_platform_class_init(CogDrmPlatformClass *klass)
1652
1643
"modeset" ,
1653
1644
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS );
1654
1645
1646
+ /**
1647
+ * CogDrmPlatform:atomic-mode-setting:
1648
+ *
1649
+ * Whether to use DRM/KMS atomic mode setting.
1650
+ *
1651
+ * Even if initially enabled, if the driver reports the feature as not
1652
+ * supported the setting will be disabled automatically. Explicitly
1653
+ * disabling atomic mode setting is rarely needed, but might fix issues
1654
+ * with certain drivers.
1655
+ *
1656
+ * Since: 0.18
1657
+ */
1658
+ s_properties [PROP_ATOMIC_MODE_SETTING ] = g_param_spec_boolean ("atomic-mode-setting" ,
1659
+ "Atomic mode setting" ,
1660
+ "Use DRM/KMS atomic mode setting" ,
1661
+ TRUE,
1662
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS );
1663
+
1664
+ /**
1665
+ * CogDrmPlatform:device-scale-factor:
1666
+ *
1667
+ * Scaling factor applied to the output device.
1668
+ *
1669
+ * Since: 0.18
1670
+ */
1671
+ s_properties [PROP_DEVICE_SCALE_FACTOR ] =
1672
+ g_param_spec_float ("device-scale-factor" , "Device scale factor" , "Output device scaling factor" , 0.25f , 5.0f ,
1673
+ 1.0f , G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS );
1674
+
1655
1675
g_object_class_install_properties (object_class , N_PROPERTIES , s_properties );
1656
1676
}
1657
1677
0 commit comments