@@ -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,7 +132,6 @@ static struct {
128
132
uint32_t width ;
129
133
uint32_t height ;
130
134
uint32_t refresh ;
131
- double device_scale ;
132
135
133
136
bool atomic_modesetting ;
134
137
bool addfb2_modifiers ;
@@ -158,8 +161,6 @@ static struct {
158
161
.width = 0 ,
159
162
.height = 0 ,
160
163
.refresh = 0 ,
161
- .device_scale = 1.0 ,
162
- .atomic_modesetting = true,
163
164
.mode_set = false,
164
165
};
165
166
@@ -239,43 +240,11 @@ static struct {
239
240
static void
240
241
init_config (CogDrmPlatform * self , CogShell * shell , const char * params_string )
241
242
{
242
- drm_data .device_scale = cog_shell_get_device_scale_factor (shell );
243
- g_debug ("init_config: overriding device_scale value, using %.2f from shell" ,
244
- drm_data .device_scale );
245
-
246
- GKeyFile * key_file = cog_shell_get_config_file (shell );
247
-
243
+ GKeyFile * key_file = cog_shell_get_config_file (shell );
248
244
if (key_file ) {
249
- {
250
- g_autoptr (GError ) lookup_error = NULL ;
251
-
252
- gboolean value = g_key_file_get_boolean (key_file , "drm" , "disable-atomic-modesetting" , & lookup_error );
253
- if (!lookup_error ) {
254
- drm_data .atomic_modesetting = !value ;
255
- g_debug ("init_config: atomic modesetting reconfigured to value '%s'" ,
256
- drm_data .atomic_modesetting ? "true" : "false" );
257
- }
258
- }
259
-
260
- {
261
- g_autoptr (GError ) lookup_error = NULL ;
262
-
263
- gdouble value = g_key_file_get_double (key_file , "drm" , "device-scale-factor" , & lookup_error );
264
- if (!lookup_error ) {
265
- drm_data .device_scale = value ;
266
- g_debug ("init_config: overriding device_scale value, using %.2f from config" , drm_data .device_scale );
267
- }
268
- }
269
-
270
- {
271
- g_autofree char * value = g_key_file_get_string (key_file , "drm" , "renderer" , NULL );
272
- if (g_strcmp0 (value , "gles" ) == 0 )
273
- self -> use_gles = true;
274
- else if (g_strcmp0 (value , "modeset" ) != 0 )
275
- self -> use_gles = false;
276
- else if (value )
277
- g_warning ("Invalid renderer '%s', using default." , value );
278
- }
245
+ g_autoptr (GError ) error = NULL ;
246
+ if (!cog_apply_properties_from_key_file (G_OBJECT (self ), key_file , "drm" , & error ))
247
+ g_warning ("Reading config file: %s" , error -> message );
279
248
}
280
249
281
250
if (params_string ) {
@@ -310,6 +279,13 @@ init_config(CogDrmPlatform *self, CogShell *shell, const char *params_string)
310
279
}
311
280
}
312
281
}
282
+
283
+ float device_scale_factor = cog_shell_get_device_scale_factor (shell );
284
+ if (device_scale_factor >= 0.2f ) {
285
+ g_debug ("%s: Overriding CogDrmPlatform<%p>.device-scale-factor = <%.2f> from shell" , __func__ , self ,
286
+ device_scale_factor );
287
+ self -> device_scale_factor = device_scale_factor ;
288
+ }
313
289
}
314
290
315
291
static void
@@ -369,7 +345,7 @@ find_crtc_for_encoder(const drmModeRes *resources, const drmModeEncoder *encoder
369
345
}
370
346
371
347
static gboolean
372
- init_drm (void )
348
+ init_drm (CogDrmPlatform * self )
373
349
{
374
350
drmDevice * devices [64 ];
375
351
memset (devices , 0 , sizeof (* devices ) * 64 );
@@ -416,10 +392,10 @@ init_drm(void)
416
392
if (!drm_data .base_resources )
417
393
return FALSE;
418
394
419
- if (drm_data . atomic_modesetting ) {
395
+ if (self -> atomic_mode_setting ) {
420
396
int ret = drmSetClientCap (drm_data .fd , DRM_CLIENT_CAP_ATOMIC , 1 );
421
397
if (ret ) {
422
- drm_data . atomic_modesetting = false;
398
+ self -> atomic_mode_setting = false;
423
399
g_debug ("init_drm: atomic mode not usable, falling back to non-atomic mode" );
424
400
}
425
401
}
@@ -964,7 +940,7 @@ input_handle_pointer_smooth_scroll_event(struct libinput_event_pointer *pointer_
964
940
}
965
941
#else
966
942
static void
967
- input_handle_pointer_axis_event (struct libinput_event_pointer * pointer_event )
943
+ input_handle_pointer_axis_event (CogDrmPlatform * self , struct libinput_event_pointer * pointer_event )
968
944
{
969
945
struct wpe_input_axis_2d_event event = {
970
946
.base .type = wpe_input_axis_event_type_mask_2d ,
@@ -992,8 +968,8 @@ input_handle_pointer_axis_event(struct libinput_event_pointer *pointer_event)
992
968
libinput_event_pointer_get_axis_value (pointer_event , LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL );
993
969
}
994
970
995
- event .x_axis *= drm_data . device_scale ;
996
- event .y_axis *= drm_data . device_scale ;
971
+ event .x_axis *= self -> device_scale_factor ;
972
+ event .y_axis *= self -> device_scale_factor ;
997
973
998
974
wpe_view_backend_dispatch_axis_event (wpe_view_data .backend , & event .base );
999
975
}
@@ -1073,7 +1049,7 @@ input_handle_device_removed(struct libinput_device *device)
1073
1049
}
1074
1050
1075
1051
static void
1076
- input_process_events ( void )
1052
+ input_process_events ( CogDrmPlatform * self )
1077
1053
{
1078
1054
g_assert (input_data .libinput );
1079
1055
@@ -1190,7 +1166,7 @@ input_process_events (void)
1190
1166
break ;
1191
1167
#else
1192
1168
case LIBINPUT_EVENT_POINTER_AXIS :
1193
- input_handle_pointer_axis_event (libinput_event_get_pointer_event (event ));
1169
+ input_handle_pointer_axis_event (self , libinput_event_get_pointer_event (event ));
1194
1170
break ;
1195
1171
#endif /* LIBINPUT_CHECK_VERSION(1, 19, 0) */
1196
1172
default :
@@ -1283,6 +1259,7 @@ struct drm_source {
1283
1259
struct input_source {
1284
1260
GSource source ;
1285
1261
GPollFD pfd ;
1262
+ CogDrmPlatform * platform ;
1286
1263
};
1287
1264
1288
1265
static gboolean
@@ -1299,7 +1276,7 @@ input_source_dispatch (GSource *base, GSourceFunc callback, gpointer user_data)
1299
1276
if (source -> pfd .revents & (G_IO_ERR | G_IO_HUP ))
1300
1277
return FALSE;
1301
1278
1302
- input_process_events ( );
1279
+ input_process_events ( source -> platform );
1303
1280
source -> pfd .revents = 0 ;
1304
1281
return TRUE;
1305
1282
}
@@ -1356,6 +1333,7 @@ init_glib(CogDrmPlatform *self)
1356
1333
source -> pfd .fd = libinput_get_fd (input_data .libinput );
1357
1334
source -> pfd .events = G_IO_IN | G_IO_ERR | G_IO_HUP ;
1358
1335
source -> pfd .revents = 0 ;
1336
+ source -> platform = self ;
1359
1337
g_source_add_poll (glib_data .input_source , & source -> pfd );
1360
1338
1361
1339
g_source_set_name (glib_data .input_source , "cog: input" );
@@ -1416,7 +1394,7 @@ cog_drm_platform_setup(CogPlatform *platform, CogShell *shell, const char *param
1416
1394
return FALSE;
1417
1395
}
1418
1396
1419
- if (!init_drm ( )) {
1397
+ if (!init_drm ( self )) {
1420
1398
g_set_error_literal (error ,
1421
1399
COG_PLATFORM_WPE_ERROR ,
1422
1400
COG_PLATFORM_WPE_ERROR_INIT ,
@@ -1453,14 +1431,14 @@ cog_drm_platform_setup(CogPlatform *platform, CogShell *shell, const char *param
1453
1431
drm_data .crtc .obj_id ,
1454
1432
drm_data .connector .obj_id ,
1455
1433
drm_data .mode ,
1456
- drm_data . atomic_modesetting );
1434
+ self -> atomic_mode_setting );
1457
1435
} else {
1458
1436
self -> renderer = cog_drm_modeset_renderer_new (gbm_data .device ,
1459
1437
drm_data .plane .obj_id ,
1460
1438
drm_data .crtc .obj_id ,
1461
1439
drm_data .connector .obj_id ,
1462
1440
drm_data .mode ,
1463
- drm_data . atomic_modesetting );
1441
+ self -> atomic_mode_setting );
1464
1442
}
1465
1443
if (cog_drm_renderer_supports_rotation (self -> renderer , self -> rotation )) {
1466
1444
cog_drm_renderer_set_rotation (self -> renderer , self -> rotation );
@@ -1523,8 +1501,8 @@ cog_drm_platform_get_view_backend(CogPlatform *platform, WebKitWebView *related_
1523
1501
{
1524
1502
CogDrmPlatform * self = COG_DRM_PLATFORM (platform );
1525
1503
wpe_host_data .exportable = self -> renderer -> create_exportable (self -> renderer ,
1526
- drm_data .width / drm_data . device_scale ,
1527
- drm_data .height / drm_data . device_scale );
1504
+ drm_data .width / self -> device_scale_factor ,
1505
+ drm_data .height / self -> device_scale_factor );
1528
1506
g_assert (wpe_host_data .exportable );
1529
1507
1530
1508
wpe_view_data .backend = wpe_view_backend_exportable_fdo_get_view_backend (wpe_host_data .exportable );
@@ -1551,9 +1529,11 @@ set_target_refresh_rate(gpointer user_data)
1551
1529
static void
1552
1530
cog_drm_platform_init_web_view (CogPlatform * platform , WebKitWebView * view )
1553
1531
{
1554
- COG_DRM_PLATFORM ( platform ) -> web_view = COG_VIEW ( view );
1532
+ CogDrmPlatform * self = COG_DRM_PLATFORM ( platform );
1555
1533
1556
- wpe_view_backend_dispatch_set_device_scale_factor (wpe_view_data .backend , drm_data .device_scale );
1534
+ self -> web_view = COG_VIEW (view );
1535
+
1536
+ wpe_view_backend_dispatch_set_device_scale_factor (wpe_view_data .backend , self -> device_scale_factor );
1557
1537
1558
1538
#if HAVE_REFRESH_RATE_HANDLING
1559
1539
g_idle_add (G_SOURCE_FUNC (set_target_refresh_rate ), & wpe_view_data );
@@ -1592,6 +1572,12 @@ cog_drm_platform_set_property(GObject *object, unsigned prop_id, const GValue *v
1592
1572
}
1593
1573
break ;
1594
1574
}
1575
+ case PROP_ATOMIC_MODE_SETTING :
1576
+ self -> atomic_mode_setting = g_value_get_boolean (value );
1577
+ break ;
1578
+ case PROP_DEVICE_SCALE_FACTOR :
1579
+ self -> device_scale_factor = g_value_get_float (value );
1580
+ break ;
1595
1581
default :
1596
1582
G_OBJECT_WARN_INVALID_PROPERTY_ID (object , prop_id , pspec );
1597
1583
}
@@ -1608,6 +1594,12 @@ cog_drm_platform_get_property(GObject *object, unsigned prop_id, GValue *value,
1608
1594
case PROP_RENDERER :
1609
1595
g_value_set_string (value , self -> use_gles ? "gles" : "modeset" );
1610
1596
break ;
1597
+ case PROP_ATOMIC_MODE_SETTING :
1598
+ g_value_set_boolean (value , self -> atomic_mode_setting );
1599
+ break ;
1600
+ case PROP_DEVICE_SCALE_FACTOR :
1601
+ g_value_set_float (value , self -> device_scale_factor );
1602
+ break ;
1611
1603
default :
1612
1604
G_OBJECT_WARN_INVALID_PROPERTY_ID (object , prop_id , pspec );
1613
1605
}
@@ -1660,6 +1652,35 @@ cog_drm_platform_class_init(CogDrmPlatformClass *klass)
1660
1652
"modeset" ,
1661
1653
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS );
1662
1654
1655
+ /**
1656
+ * CogDrmPlatform:atomic-mode-setting:
1657
+ *
1658
+ * Whether to use DRM/KMS atomic mode setting.
1659
+ *
1660
+ * Even if initially enabled, if the driver reports the feature as not
1661
+ * supported the setting will be disabled automatically. Explicitly
1662
+ * disabling atomic mode setting is rarely needed, but might fix issues
1663
+ * with certain drivers.
1664
+ *
1665
+ * Since: 0.18
1666
+ */
1667
+ s_properties [PROP_ATOMIC_MODE_SETTING ] = g_param_spec_boolean ("atomic-mode-setting" ,
1668
+ "Atomic mode setting" ,
1669
+ "Use DRM/KMS atomic mode setting" ,
1670
+ TRUE,
1671
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS );
1672
+
1673
+ /**
1674
+ * CogDrmPlatform:device-scale-factor:
1675
+ *
1676
+ * Scaling factor applied to the output device.
1677
+ *
1678
+ * Since: 0.18
1679
+ */
1680
+ s_properties [PROP_DEVICE_SCALE_FACTOR ] =
1681
+ g_param_spec_float ("device-scale-factor" , "Device scale factor" , "Output device scaling factor" , 0.25f , 5.0f ,
1682
+ 1.0f , G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS );
1683
+
1663
1684
g_object_class_install_properties (object_class , N_PROPERTIES , s_properties );
1664
1685
}
1665
1686
0 commit comments