-
Notifications
You must be signed in to change notification settings - Fork 6
/
chromium-114-add_qt6_linuxui_backend.patch
545 lines (520 loc) · 16.7 KB
/
chromium-114-add_qt6_linuxui_backend.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
commit 75f4b48eb71d4872ba3ac6c9fc3662a60eb4175d
Author: Tom Anderson <[email protected]>
Date: Thu Apr 27 02:21:34 2023 +0000
Add QT6 LinuxUi backend
- Enable QT6 by default on KDE6
- If QT6 load fails, fallback to QT5 (and vice versa)
- Add use_qt6 build flag for packager control
- Add --qt-version runtime flag for user control
R=thestig
Change-Id: Ib1d9f6183663ecf7b9ddfe9d7f3e3442e534ccda
Fixed: 1434754
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4475369
Commit-Queue: Thomas Anderson <[email protected]>
Reviewed-by: Lei Zhang <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1136295}
diff --git a/chrome/installer/linux/BUILD.gn b/chrome/installer/linux/BUILD.gn
index 5639b9ffc996e..3bacd3398d4a2 100644
--- a/chrome/installer/linux/BUILD.gn
+++ b/chrome/installer/linux/BUILD.gn
@@ -109,6 +109,9 @@ if (use_qt) {
# to prevent a hard dependency on QT for the package.
packaging_files += [ "$root_out_dir/libqt5_shim.so" ]
}
+if (use_qt6) {
+ packaging_files += [ "$root_out_dir/libqt6_shim.so" ]
+}
action_foreach("calculate_deb_dependencies") {
deps = [ ":installer_deps" ]
@@ -249,6 +252,12 @@ if (use_qt) {
deps = [ "//ui/qt:qt5_shim" ]
}
}
+if (use_qt6) {
+ strip_binary("strip_qt6_shim") {
+ binary_input = "$root_out_dir/libqt6_shim.so"
+ deps = [ "//ui/qt:qt6_shim" ]
+ }
+}
# This target builds all "normal" Linux installers. You must set
# is_component_build=false before building this target.
@@ -447,6 +456,12 @@ group("installer_deps") {
"//ui/qt:qt5_shim",
]
}
+ if (use_qt6) {
+ public_deps += [
+ ":strip_qt6_shim",
+ "//ui/qt:qt6_shim",
+ ]
+ }
}
# Creates .deb and .rpm (RPM for non-ChromeOS only) installer packages.
diff --git a/chrome/installer/linux/common/installer.include b/chrome/installer/linux/common/installer.include
index 8d76f1f280b01..439ef5ccb0f52 100644
--- a/chrome/installer/linux/common/installer.include
+++ b/chrome/installer/linux/common/installer.include
@@ -254,6 +254,11 @@ stage_install_common() {
strippedfile="${OUTPUTDIR}/${file}.stripped"
install -m ${SHLIB_PERMS} "${strippedfile}" "${STAGEDIR}/${INSTALLDIR}/${file}"
fi
+ if [ -f "${OUTPUTDIR}/libqt6_shim.so" ]; then
+ file="libqt6_shim.so"
+ strippedfile="${OUTPUTDIR}/${file}.stripped"
+ install -m ${SHLIB_PERMS} "${strippedfile}" "${STAGEDIR}/${INSTALLDIR}/${file}"
+ fi
# libc++
if [ -f "${OUTPUTDIR}/lib/libc++.so" ]; then
diff --git a/ui/qt/BUILD.gn b/ui/qt/BUILD.gn
index bbede00daa4d0..6a67961edc2f7 100644
--- a/ui/qt/BUILD.gn
+++ b/ui/qt/BUILD.gn
@@ -11,13 +11,6 @@ assert(use_qt)
assert(is_linux)
assert(!is_castos)
-pkg_config("qt5_config") {
- packages = [
- "Qt5Core",
- "Qt5Widgets",
- ]
-}
-
config("qt_internal_config") {
if (is_clang) {
# libstdc++ headers are incompatible with -fcomplete-member-pointers.
@@ -56,40 +49,57 @@ if (!use_sysroot) {
}
}
-shared_library("qt5_shim") {
- visibility = [
- ":qt",
- "//chrome/installer/linux:*",
- ]
-
- # Since qt_shim is a shared library even in non-component builds, it shouldn't
- # depend on any other targets since that would duplicate code between binaries
- # leading to increased size and potential issues from duplicated global state.
- no_default_deps = true
- assert_no_deps = [
- "//base",
- "//buildtools/third_party/libc++",
- ]
- deps = [ ":qt_interface" ]
-
- configs -= [ "//build/config/compiler:runtime_library" ]
- configs += [
- ":qt_internal_config",
- ":qt5_config",
- ]
+template("qt_shim") {
+ pkg_config("qt" + invoker.qt_version + "_config") {
+ packages = [
+ "Qt" + invoker.qt_version + "Core",
+ "Qt" + invoker.qt_version + "Widgets",
+ ]
+ }
- public = []
- sources = [
- "qt_shim.cc",
- "qt_shim.h",
- ]
- if (use_sysroot) {
- # This file is generated with gen_qt_shim_moc.sh on an amd64 system to
- # avoid a build-time dependency on `moc` when using the sysroot.
- sources += [ "qt_shim_moc.cc" ]
- } else {
- sources += get_target_outputs(":generate_moc")
- deps += [ ":generate_moc" ]
+ shared_library(target_name) {
+ visibility = [
+ ":qt",
+ "//chrome/installer/linux:*",
+ ]
+
+ # Since qt_shim is a shared library even in non-component builds, it shouldn't
+ # depend on any other targets since that would duplicate code between binaries
+ # leading to increased size and potential issues from duplicated global state.
+ no_default_deps = true
+ assert_no_deps = [
+ "//base",
+ "//buildtools/third_party/libc++",
+ ]
+ deps = [ ":qt_interface" ]
+
+ configs -= [ "//build/config/compiler:runtime_library" ]
+ configs += [
+ ":qt_internal_config",
+ ":qt" + invoker.qt_version + "_config",
+ ]
+
+ public = []
+ sources = [
+ "qt_shim.cc",
+ "qt_shim.h",
+ ]
+ if (use_sysroot) {
+ # This file is generated with gen_qt_shim_moc.sh on an amd64 system to
+ # avoid a build-time dependency on `moc` when using the sysroot.
+ sources += [ "qt" + invoker.qt_version + "_shim_moc.cc" ]
+ } else {
+ sources += get_target_outputs(":generate_moc")
+ deps += [ ":generate_moc" ]
+ }
+ }
+}
+qt_shim("qt5_shim") {
+ qt_version = "5"
+}
+if (use_qt6) {
+ qt_shim("qt6_shim") {
+ qt_version = "6"
}
}
@@ -100,6 +110,9 @@ component("qt") {
# qt_shim is in data_deps since we want to load it manually.
data_deps = [ ":qt5_shim" ]
+ if (use_qt6) {
+ data_deps += [ ":qt6_shim" ]
+ }
deps = [
":qt_interface",
"//base",
diff --git a/ui/qt/gen_qt_shim_moc.sh b/ui/qt/gen_qt_shim_moc.sh
index 74272d5611dab..9d02c2dfcb12f 100755
--- a/ui/qt/gen_qt_shim_moc.sh
+++ b/ui/qt/gen_qt_shim_moc.sh
@@ -6,11 +6,15 @@
set -o nounset
set -o errexit
-URL="http://archive.debian.org/debian/pool/main/q/qtbase-opensource-src"
-PACKAGE="qtbase5-dev-tools_5.3.2+dfsg-4+deb8u2_amd64.deb"
-SHA256="7703754f2c230ce6b8b6030b6c1e7e030899aa9f45a415498df04bd5ec061a76"
-SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+URL5="http://archive.debian.org/debian/pool/main/q/qtbase-opensource-src"
+PACKAGE5="qtbase5-dev-tools_5.3.2+dfsg-4+deb8u2_amd64.deb"
+SHA256_5="7703754f2c230ce6b8b6030b6c1e7e030899aa9f45a415498df04bd5ec061a76"
+
+URL6="http://archive.ubuntu.com/ubuntu/pool/universe/q/qt6-base"
+PACKAGE6="qt6-base-dev-tools_6.2.4+dfsg-2ubuntu1_amd64.deb"
+SHA256_6="8dddfc79e7743185b07c478ca0f96a4ccc13d48ecccc42f44d2578c33c7d9b8b"
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TMP_DIR=$(mktemp -d -p "$SCRIPT_DIR")
function cleanup {
rm -rf "$TMP_DIR"
@@ -18,16 +22,22 @@ function cleanup {
trap cleanup EXIT
cd "$TMP_DIR"
-wget "$URL/$PACKAGE"
-echo "$SHA256 $PACKAGE" | shasum -a 256 -c
-dpkg -x "$PACKAGE" .
-cat > ../qt_shim_moc.cc <<EOF
-// Copyright 2022 The Chromium Authors
+wget "$URL5/$PACKAGE5"
+echo "$SHA256_5 $PACKAGE5" | shasum -a 256 -c
+dpkg -x "$PACKAGE5" .
+wget "$URL6/$PACKAGE6"
+echo "$SHA256_6 $PACKAGE6" | shasum -a 256 -c
+dpkg -x "$PACKAGE6" .
+cat > ../qt5_shim_moc.cc <<EOF
+// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
EOF
cd "$SCRIPT_DIR/../.."
+cp ui/qt/qt5_shim_moc.cc ui/qt/qt6_shim_moc.cc
"$TMP_DIR/usr/lib/x86_64-linux-gnu/qt5/bin/moc" ui/qt/qt_shim.h \
- >> ui/qt/qt_shim_moc.cc
-git cl format ui/qt/qt_shim_moc.cc
+ >> ui/qt/qt5_shim_moc.cc
+"$TMP_DIR//usr/lib/qt6/libexec/moc" ui/qt/qt_shim.h \
+ >> ui/qt/qt6_shim_moc.cc
+git cl format ui/qt/qt5_shim_moc.cc ui/qt/qt6_shim_moc.cc
diff --git a/ui/qt/qt.gni b/ui/qt/qt.gni
index 27bb6375880b7..f45823270cb91 100644
--- a/ui/qt/qt.gni
+++ b/ui/qt/qt.gni
@@ -4,9 +4,17 @@
import("//build/config/chromecast_build.gni")
import("//build/config/sanitizers/sanitizers.gni")
+import("//build/config/sysroot.gni")
declare_args() {
# TODO(https://crbug.com/1424435): Allow QT in MSAN builds once QT is
# added to the instrumented libraries.
use_qt = is_linux && !is_castos && !is_msan
}
+
+declare_args() {
+ use_qt6 = use_qt && use_sysroot
+}
+
+# use_qt6 => use_qt
+assert(!use_qt6 || use_qt)
diff --git a/ui/qt/qt_shim_moc.cc b/ui/qt/qt5_shim_moc.cc
similarity index 95%
rename from ui/qt/qt_shim_moc.cc
rename to ui/qt/qt5_shim_moc.cc
index dafbfadce56ba..8f8b6b57784a8 100644
--- a/ui/qt/qt_shim_moc.cc
+++ b/ui/qt/qt5_shim_moc.cc
@@ -1,4 +1,4 @@
-// Copyright 2022 The Chromium Authors
+// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -89,26 +89,32 @@ const QMetaObject* qt::QtShim::metaObject() const {
}
void* qt::QtShim::qt_metacast(const char* _clname) {
- if (!_clname)
+ if (!_clname) {
return 0;
- if (!strcmp(_clname, qt_meta_stringdata_qt__QtShim.stringdata))
+ }
+ if (!strcmp(_clname, qt_meta_stringdata_qt__QtShim.stringdata)) {
return static_cast<void*>(const_cast<QtShim*>(this));
- if (!strcmp(_clname, "QtInterface"))
+ }
+ if (!strcmp(_clname, "QtInterface")) {
return static_cast<QtInterface*>(const_cast<QtShim*>(this));
+ }
return QObject::qt_metacast(_clname);
}
int qt::QtShim::qt_metacall(QMetaObject::Call _c, int _id, void** _a) {
_id = QObject::qt_metacall(_c, _id, _a);
- if (_id < 0)
+ if (_id < 0) {
return _id;
+ }
if (_c == QMetaObject::InvokeMetaMethod) {
- if (_id < 2)
+ if (_id < 2) {
qt_static_metacall(this, _c, _id, _a);
+ }
_id -= 2;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
- if (_id < 2)
+ if (_id < 2) {
*reinterpret_cast<int*>(_a[0]) = -1;
+ }
_id -= 2;
}
return _id;
diff --git a/ui/qt/qt6_shim_moc.cc b/ui/qt/qt6_shim_moc.cc
new file mode 100644
index 0000000000000..6d02ca317b65d
--- /dev/null
+++ b/ui/qt/qt6_shim_moc.cc
@@ -0,0 +1,143 @@
+// Copyright 2023 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/****************************************************************************
+** Meta object code from reading C++ file 'qt_shim.h'
+**
+** Created by: The Qt Meta Object Compiler version 68 (Qt 6.2.4)
+**
+** WARNING! All changes made in this file will be lost!
+*****************************************************************************/
+
+#include <QtCore/qbytearray.h>
+#include <QtCore/qmetatype.h>
+#include <memory>
+#include "ui/qt/qt_shim.h"
+#if !defined(Q_MOC_OUTPUT_REVISION)
+#error "The header file 'qt_shim.h' doesn't include <QObject>."
+#elif Q_MOC_OUTPUT_REVISION != 68
+#error "This file was generated using the moc from 6.2.4. It"
+#error "cannot be used with the include files from this version of Qt."
+#error "(The moc has changed too much.)"
+#endif
+
+QT_BEGIN_MOC_NAMESPACE
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
+struct qt_meta_stringdata_qt__QtShim_t {
+ const uint offsetsAndSize[12];
+ char stringdata0[52];
+};
+#define QT_MOC_LITERAL(ofs, len) \
+ uint(offsetof(qt_meta_stringdata_qt__QtShim_t, stringdata0) + ofs), len
+static const qt_meta_stringdata_qt__QtShim_t qt_meta_stringdata_qt__QtShim = {
+ {
+ QT_MOC_LITERAL(0, 10), // "qt::QtShim"
+ QT_MOC_LITERAL(11, 11), // "FontChanged"
+ QT_MOC_LITERAL(23, 0), // ""
+ QT_MOC_LITERAL(24, 4), // "font"
+ QT_MOC_LITERAL(29, 14), // "PaletteChanged"
+ QT_MOC_LITERAL(44, 7) // "palette"
+
+ },
+ "qt::QtShim\0FontChanged\0\0font\0"
+ "PaletteChanged\0palette"};
+#undef QT_MOC_LITERAL
+
+static const uint qt_meta_data_qt__QtShim[] = {
+
+ // content:
+ 10, // revision
+ 0, // classname
+ 0, 0, // classinfo
+ 2, 14, // methods
+ 0, 0, // properties
+ 0, 0, // enums/sets
+ 0, 0, // constructors
+ 0, // flags
+ 0, // signalCount
+
+ // slots: name, argc, parameters, tag, flags, initial metatype offsets
+ 1, 1, 26, 2, 0x08, 1 /* Private */, 4, 1, 29, 2, 0x08, 3 /* Private */,
+
+ // slots: parameters
+ QMetaType::Void, QMetaType::QFont, 3, QMetaType::Void, QMetaType::QPalette,
+ 5,
+
+ 0 // eod
+};
+
+void qt::QtShim::qt_static_metacall(QObject* _o,
+ QMetaObject::Call _c,
+ int _id,
+ void** _a) {
+ if (_c == QMetaObject::InvokeMetaMethod) {
+ auto* _t = static_cast<QtShim*>(_o);
+ (void)_t;
+ switch (_id) {
+ case 0:
+ _t->FontChanged((*reinterpret_cast<std::add_pointer_t<QFont>>(_a[1])));
+ break;
+ case 1:
+ _t->PaletteChanged(
+ (*reinterpret_cast<std::add_pointer_t<QPalette>>(_a[1])));
+ break;
+ default:;
+ }
+ }
+}
+
+const QMetaObject qt::QtShim::staticMetaObject = {
+ {QMetaObject::SuperData::link<QObject::staticMetaObject>(),
+ qt_meta_stringdata_qt__QtShim.offsetsAndSize, qt_meta_data_qt__QtShim,
+ qt_static_metacall, nullptr,
+ qt_incomplete_metaTypeArray<
+ qt_meta_stringdata_qt__QtShim_t,
+ QtPrivate::TypeAndForceComplete<QtShim, std::true_type>,
+ QtPrivate::TypeAndForceComplete<void, std::false_type>,
+ QtPrivate::TypeAndForceComplete<const QFont&, std::false_type>,
+ QtPrivate::TypeAndForceComplete<void, std::false_type>,
+ QtPrivate::TypeAndForceComplete<const QPalette&, std::false_type>
+
+ >,
+ nullptr}};
+
+const QMetaObject* qt::QtShim::metaObject() const {
+ return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject()
+ : &staticMetaObject;
+}
+
+void* qt::QtShim::qt_metacast(const char* _clname) {
+ if (!_clname) {
+ return nullptr;
+ }
+ if (!strcmp(_clname, qt_meta_stringdata_qt__QtShim.stringdata0)) {
+ return static_cast<void*>(this);
+ }
+ if (!strcmp(_clname, "QtInterface")) {
+ return static_cast<QtInterface*>(this);
+ }
+ return QObject::qt_metacast(_clname);
+}
+
+int qt::QtShim::qt_metacall(QMetaObject::Call _c, int _id, void** _a) {
+ _id = QObject::qt_metacall(_c, _id, _a);
+ if (_id < 0) {
+ return _id;
+ }
+ if (_c == QMetaObject::InvokeMetaMethod) {
+ if (_id < 2) {
+ qt_static_metacall(this, _c, _id, _a);
+ }
+ _id -= 2;
+ } else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
+ if (_id < 2) {
+ *reinterpret_cast<QMetaType*>(_a[0]) = QMetaType();
+ }
+ _id -= 2;
+ }
+ return _id;
+}
+QT_WARNING_POP
+QT_END_MOC_NAMESPACE
diff --git a/ui/qt/qt_ui.cc b/ui/qt/qt_ui.cc
index d4052b7e8bc3d..6a3b58e9f930b 100644
--- a/ui/qt/qt_ui.cc
+++ b/ui/qt/qt_ui.cc
@@ -14,7 +14,9 @@
#include "base/check.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
+#include "base/environment.h"
#include "base/memory/raw_ptr.h"
+#include "base/nix/xdg_util.h"
#include "base/notreached.h"
#include "base/path_service.h"
#include "base/time/time.h"
@@ -47,6 +49,45 @@ namespace qt {
namespace {
+const char kQtVersionFlag[] = "qt-version";
+
+void* LoadLibrary(const base::FilePath& path) {
+ return dlopen(path.value().c_str(), RTLD_NOW | RTLD_GLOBAL);
+}
+
+void* LoadLibraryOrFallback(const base::FilePath& path,
+ const char* preferred,
+ const char* fallback) {
+ if (void* library = LoadLibrary(path.Append(preferred))) {
+ return library;
+ }
+ return LoadLibrary(path.Append(fallback));
+}
+
+bool PreferQt6() {
+ auto* cmd = base::CommandLine::ForCurrentProcess();
+ if (cmd->HasSwitch(kQtVersionFlag)) {
+ std::string qt_version_string = cmd->GetSwitchValueASCII(kQtVersionFlag);
+ unsigned int qt_version = 0;
+ if (base::StringToUint(qt_version_string, &qt_version)) {
+ switch (qt_version) {
+ case 5:
+ return false;
+ case 6:
+ return true;
+ default:
+ LOG(ERROR) << "Unsupported QT version " << qt_version;
+ }
+ } else {
+ LOG(ERROR) << "Unable to parse QT version " << qt_version_string;
+ }
+ }
+
+ auto env = base::Environment::Create();
+ auto desktop = base::nix::GetDesktopEnvironment(env.get());
+ return desktop == base::nix::DESKTOP_ENVIRONMENT_KDE6;
+}
+
int QtWeightToCssWeight(int weight) {
struct {
int qt_weight;
@@ -179,8 +220,10 @@ bool QtUi::Initialize() {
base::FilePath path;
if (!base::PathService::Get(base::DIR_MODULE, &path))
return false;
- path = path.Append("libqt5_shim.so");
- void* libqt_shim = dlopen(path.value().c_str(), RTLD_NOW | RTLD_GLOBAL);
+ void* libqt_shim =
+ PreferQt6()
+ ? LoadLibraryOrFallback(path, "libqt6_shim.so", "libqt5_shim.so")
+ : LoadLibraryOrFallback(path, "libqt5_shim.so", "libqt6_shim.so");
if (!libqt_shim)
return false;
void* create_qt_interface = dlsym(libqt_shim, "CreateQtInterface");