@@ -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 :
@@ -1266,6 +1241,7 @@ struct drm_source {
1266
1241
struct input_source {
1267
1242
GSource source ;
1268
1243
GPollFD pfd ;
1244
+ CogDrmPlatform * platform ;
1269
1245
};
1270
1246
1271
1247
static gboolean
@@ -1282,7 +1258,7 @@ input_source_dispatch (GSource *base, GSourceFunc callback, gpointer user_data)
1282
1258
if (source -> pfd .revents & (G_IO_ERR | G_IO_HUP ))
1283
1259
return FALSE;
1284
1260
1285
- input_process_events ( );
1261
+ input_process_events ( source -> platform );
1286
1262
source -> pfd .revents = 0 ;
1287
1263
return TRUE;
1288
1264
}
@@ -1333,6 +1309,7 @@ init_glib(CogDrmPlatform *self)
1333
1309
source -> pfd .fd = libinput_get_fd (input_data .libinput );
1334
1310
source -> pfd .events = G_IO_IN | G_IO_ERR | G_IO_HUP ;
1335
1311
source -> pfd .revents = 0 ;
1312
+ source -> platform = self ;
1336
1313
g_source_add_poll (glib_data .input_source , & source -> pfd );
1337
1314
1338
1315
g_source_set_name (glib_data .input_source , "cog: input" );
@@ -1392,7 +1369,7 @@ cog_drm_platform_setup(CogPlatform *platform, CogShell *shell, const char *param
1392
1369
return FALSE;
1393
1370
}
1394
1371
1395
- if (!init_drm ( )) {
1372
+ if (!init_drm ( self )) {
1396
1373
g_set_error_literal (error ,
1397
1374
COG_PLATFORM_WPE_ERROR ,
1398
1375
COG_PLATFORM_WPE_ERROR_INIT ,
@@ -1429,14 +1406,14 @@ cog_drm_platform_setup(CogPlatform *platform, CogShell *shell, const char *param
1429
1406
drm_data .crtc .obj_id ,
1430
1407
drm_data .connector .obj_id ,
1431
1408
drm_data .mode ,
1432
- drm_data . atomic_modesetting );
1409
+ self -> atomic_mode_setting );
1433
1410
} else {
1434
1411
self -> renderer = cog_drm_modeset_renderer_new (gbm_data .device ,
1435
1412
drm_data .plane .obj_id ,
1436
1413
drm_data .crtc .obj_id ,
1437
1414
drm_data .connector .obj_id ,
1438
1415
drm_data .mode ,
1439
- drm_data . atomic_modesetting );
1416
+ self -> atomic_mode_setting );
1440
1417
}
1441
1418
if (cog_drm_renderer_supports_rotation (self -> renderer , self -> rotation )) {
1442
1419
cog_drm_renderer_set_rotation (self -> renderer , self -> rotation );
@@ -1499,8 +1476,8 @@ cog_drm_platform_get_view_backend(CogPlatform *platform, WebKitWebView *related_
1499
1476
{
1500
1477
CogDrmPlatform * self = COG_DRM_PLATFORM (platform );
1501
1478
wpe_host_data .exportable = self -> renderer -> create_exportable (self -> renderer ,
1502
- drm_data .width / drm_data . device_scale ,
1503
- drm_data .height / drm_data . device_scale );
1479
+ drm_data .width / self -> device_scale_factor ,
1480
+ drm_data .height / self -> device_scale_factor );
1504
1481
g_assert (wpe_host_data .exportable );
1505
1482
1506
1483
wpe_view_data .backend = wpe_view_backend_exportable_fdo_get_view_backend (wpe_host_data .exportable );
@@ -1527,9 +1504,11 @@ set_target_refresh_rate(gpointer user_data)
1527
1504
static void
1528
1505
cog_drm_platform_init_web_view (CogPlatform * platform , WebKitWebView * view )
1529
1506
{
1530
- COG_DRM_PLATFORM ( platform ) -> web_view = COG_VIEW ( view );
1507
+ CogDrmPlatform * self = COG_DRM_PLATFORM ( platform );
1531
1508
1532
- wpe_view_backend_dispatch_set_device_scale_factor (wpe_view_data .backend , drm_data .device_scale );
1509
+ self -> web_view = COG_VIEW (view );
1510
+
1511
+ wpe_view_backend_dispatch_set_device_scale_factor (wpe_view_data .backend , self -> device_scale_factor );
1533
1512
1534
1513
#if HAVE_REFRESH_RATE_HANDLING
1535
1514
g_idle_add (G_SOURCE_FUNC (set_target_refresh_rate ), & wpe_view_data );
@@ -1568,6 +1547,12 @@ cog_drm_platform_set_property(GObject *object, unsigned prop_id, const GValue *v
1568
1547
}
1569
1548
break ;
1570
1549
}
1550
+ case PROP_ATOMIC_MODE_SETTING :
1551
+ self -> atomic_mode_setting = g_value_get_boolean (value );
1552
+ break ;
1553
+ case PROP_DEVICE_SCALE_FACTOR :
1554
+ self -> device_scale_factor = g_value_get_float (value );
1555
+ break ;
1571
1556
default :
1572
1557
G_OBJECT_WARN_INVALID_PROPERTY_ID (object , prop_id , pspec );
1573
1558
}
@@ -1584,6 +1569,12 @@ cog_drm_platform_get_property(GObject *object, unsigned prop_id, GValue *value,
1584
1569
case PROP_RENDERER :
1585
1570
g_value_set_string (value , self -> use_gles ? "gles" : "modeset" );
1586
1571
break ;
1572
+ case PROP_ATOMIC_MODE_SETTING :
1573
+ g_value_set_boolean (value , self -> atomic_mode_setting );
1574
+ break ;
1575
+ case PROP_DEVICE_SCALE_FACTOR :
1576
+ g_value_set_float (value , self -> device_scale_factor );
1577
+ break ;
1587
1578
default :
1588
1579
G_OBJECT_WARN_INVALID_PROPERTY_ID (object , prop_id , pspec );
1589
1580
}
@@ -1636,6 +1627,35 @@ cog_drm_platform_class_init(CogDrmPlatformClass *klass)
1636
1627
"modeset" ,
1637
1628
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS );
1638
1629
1630
+ /**
1631
+ * CogDrmPlatform:atomic-mode-setting:
1632
+ *
1633
+ * Whether to use DRM/KMS atomic mode setting.
1634
+ *
1635
+ * Even if initially enabled, if the driver reports the feature as not
1636
+ * supported the setting will be disabled automatically. Explicitly
1637
+ * disabling atomic mode setting is rarely needed, but might fix issues
1638
+ * with certain drivers.
1639
+ *
1640
+ * Since: 0.18
1641
+ */
1642
+ s_properties [PROP_ATOMIC_MODE_SETTING ] = g_param_spec_boolean ("atomic-mode-setting" ,
1643
+ "Atomic mode setting" ,
1644
+ "Use DRM/KMS atomic mode setting" ,
1645
+ TRUE,
1646
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS );
1647
+
1648
+ /**
1649
+ * CogDrmPlatform:device-scale-factor:
1650
+ *
1651
+ * Scaling factor applied to the output device.
1652
+ *
1653
+ * Since: 0.18
1654
+ */
1655
+ s_properties [PROP_DEVICE_SCALE_FACTOR ] =
1656
+ g_param_spec_float ("device-scale-factor" , "Device scale factor" , "Output device scaling factor" , 0.25f , 5.0f ,
1657
+ 1.0f , G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS );
1658
+
1639
1659
g_object_class_install_properties (object_class , N_PROPERTIES , s_properties );
1640
1660
}
1641
1661
0 commit comments