Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
273 lines (254 loc) · 13.7 KB
/
Copy pathmain.cpp
File metadata and controls
273 lines (254 loc) · 13.7 KB
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
#include "MainWindow.hpp"
#include "Utils.hpp"
#include <QApplication>
#include <QCoreApplication>
#include <QWebEngineProfile>
#include <QWebEngineCookieStore>
#include <QSettings>
#include <QDir>
#include <QIcon>
#include <QResource>
#include <QThread>
#ifdef Q_OS_WIN
#include <windows.h>
#endif
// Memoria fÃsica total del sistema en MB (0 si no se puede consultar).
static qint64 totalPhysicalRamMb()
{
#ifdef Q_OS_WIN
MEMORYSTATUSEX ms;
ms.dwLength = sizeof(ms);
if (GlobalMemoryStatusEx(&ms))
return static_cast<qint64>(ms.ullTotalPhys / (1024 * 1024));
#endif
return 0;
}
int main(int argc, char *argv[])
{
QCoreApplication::setOrganizationName("Kinetix");
QCoreApplication::setApplicationName("Kinetix");
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
QSettings rec(QDir::homePath() + QStringLiteral("/.navegador_personal/config.ini"), QSettings::IniFormat);
// ------------------------------------------------------------------
// Chromium flags.
//
// Nota de seguridad: NO se desactiva la detección de phishing ni el Safe
// Browsing. SÃ se desactiva --disable-background-networking, que impide
// que el navegador haga peticiones ocultas a Google en segundo plano;
// como consecuencia las listas de Safe Browsing no se descargan solas.
// Es una decisión de privacidad deliberada, documentada en Privacidad.
//
// Nota de rendimiento: se respetan las optimizaciones en segundo plano de
// Chromium (backgrounding y throttling de timers) y la protección contra
// inundación de IPC. Desactivarlas, como se hacÃa antes, hacÃa que las
// pestañas en segundo plano consumieran CPU constantemente y que la
// interfaz se bloqueara con páginas que abusan del IPC.
// ------------------------------------------------------------------
const qint64 ramMb = totalPhysicalRamMb();
const int cores = qMax(1, QThread::idealThreadCount());
// LÃmite de procesos de renderizado según la RAM disponible. Menos
// procesos = mucha menos memoria; las pestañas del mismo sitio se
// comparten igualmente gracias a --process-per-site.
int rendererLimit = 6;
const bool lowEndDevice = (ramMb > 0 && ramMb <= 4096);
if (ramMb > 0) {
if (ramMb <= 4096) rendererLimit = 2;
else if (ramMb <= 8192) rendererLimit = 5;
else if (ramMb <= 16384) rendererLimit = 8;
else rendererLimit = 12;
}
// Hilos de rasterizado: la mitad de los núcleos, como hace Chromium por
// defecto. Forzarlos alto en una CPU modesta empeora la fluidez.
const int rasterThreads = qBound(1, cores / 2, 4);
QStringList flags;
flags << QStringLiteral("--process-per-site")
<< QStringLiteral("--disable-component-update")
<< QStringLiteral("--disable-domain-reliability")
<< QStringLiteral("--disable-sync")
<< QStringLiteral("--disable-default-apps")
<< QStringLiteral("--disable-breakpad")
<< QStringLiteral("--no-first-run")
<< QStringLiteral("--no-default-browser-check")
<< QStringLiteral("--renderer-process-limit=%1").arg(rendererLimit)
<< QStringLiteral("--num-raster-threads=%1").arg(rasterThreads)
// Flags de rendimiento y compatibilidad Intel (Chrome/Edge equivalentes)
<< QStringLiteral("--enable-features=BackForwardCache,NetworkServiceInProcess,ParallelDownloading,Vulkan,UseSkiaRenderer,CanvasOopRasterization,SkiaGraphite")
<< QStringLiteral("--disable-features=CalculateNativeWinOcclusion,Translate,OptimizationGuideModelDownloading,InterestFeedContentSuggestions,AutofillServerCommunication,MediaRouter,GlobalMediaControls,LoadingWithMojo,SpareRendererForSitePerProcess,UseChromeOSDirectVideoDecoder")
<< QStringLiteral("--disable-background-networking")
<< QStringLiteral("--use-gl=angle")
<< QStringLiteral("--use-angle=d3d11")
<< QStringLiteral("--force-color-profile=srgb")
<< QStringLiteral("--enable-gpu-rasterization")
<< QStringLiteral("--enable-zero-copy")
<< QStringLiteral("--disable-gpu-driver-bug-workarounds");
// Modo de dispositivo de gama baja (Chromium). Reduce el tamaño del caché
// de imágenes, el número de tiles rasterizados por fotograma, los lÃmites
// de memoria y la escala de algunas texturas. En un equipo con poca RAM y
// 2 núcleos hace que las páginas pesadas carguen antes y con menos memoria.
if (lowEndDevice)
flags << QStringLiteral("--enable-low-end-device-mode");
// Decodificación de vÃdeo por hardware. Chromium la trae activada; en
// algunas gráficas Intel antiguas provoca parpadeos al reproducir vÃdeo,
// asà que se desactiva por defecto. Se puede volver a activar desde
// Configuración ▸ Rendimiento.
if (rec.value(QStringLiteral("rendimiento/video_hw"), false).toBool() == false)
flags << QStringLiteral("--disable-accelerated-video-decode");
// ------------------------------------------------------------------
// Modo gráfico. En Windows, Qt WebEngine comparte las texturas D3D11 del
// compositor de Chromium con el escenario gráfico de Qt (RHI). Si ambos
// usan dispositivos distintos, Chromium exporta su fotograma como recurso
// DXGI y Qt lo reimporta en cada fotograma ("D3D: Importing DXGI Resource
// into D3D11 Texture"). En controladores Intel antiguos esa interoperación
// produce parpadeos constantes en las páginas modernas (capas, animaciones,
// vÃdeo).
//
// KINETIX_GPU_MODE permite elegir la configuración sin recompilar:
// (vacÃo)/"softcomp" → composición final en software (quita el parpadeo,
// pero es más lento en CPUs modestas)
// "native" → composición por GPU con el backend RHI por defecto
// "opengl" → GL compartido (Qt y Chromium sobre ANGLE/D3D11)
// "d3d12" → composición por GPU con RHI D3D12
// "off" → sin aceleración (lo fuerza la configuración)
// ------------------------------------------------------------------
QString gpuMode = qEnvironmentVariable("KINETIX_GPU_MODE").trimmed().toLower();
if (gpuMode.isEmpty()) {
// Si el usuario fijo explicitamente un modo, se respeta. Si no, se
// elige el optimo segun la GPU: las graficas Intel integradas (que
// parpadean) van a software; el resto, a composicion por GPU (rapida).
if (rec.contains(QStringLiteral("rendimiento/composicion_gpu")))
gpuMode = rec.value(QStringLiteral("rendimiento/composicion_gpu"), false).toBool()
? QStringLiteral("basic") : QStringLiteral("softcomp");
else
gpuMode = hardwarePrefersSoftwareCompositing() ? QStringLiteral("softcomp")
: QStringLiteral("basic");
}
if (rec.value(QStringLiteral("recursos/gpu_acelerado"), true).toBool() == false)
gpuMode = QStringLiteral("off");
if (gpuMode == QLatin1String("off")) {
flags << QStringLiteral("--disable-gpu");
} else {
const bool wantOpenGL = (gpuMode == QLatin1String("opengl")
|| gpuMode == QLatin1String("openglbasic"));
const bool wantBasic = (gpuMode == QLatin1String("basic")
|| gpuMode == QLatin1String("openglbasic"));
if (wantOpenGL) {
// GL sobre ANGLE/D3D11 para el escenario gráfico de Qt.
qputenv("QSG_RHI_BACKEND", "opengl");
qputenv("QT_OPENGL", "angle");
qputenv("QT_ANGLE_PLATFORM", "d3d11");
}
if (wantBasic) {
// Bucle de render monohilo: evita que la composición concurrente
// muestre fotogramas parciales (parpadeo) al importar la textura.
qputenv("QSG_RENDER_LOOP", "basic");
}
if (gpuMode == QLatin1String("softcomp")) {
// Composición final en software: es el único modo sin parpadeo en
// este tipo de gráficas. Desactivar rasterizado GPU para evitar
// contradicciones (raster GPU + composición SW = copias CPU-GPU).
flags << QStringLiteral("--disable-gpu-compositing")
<< QStringLiteral("--disable-gpu-rasterization")
<< QStringLiteral("--disable-zero-copy");
// Rasterizado en software: el número de hilos sà influye, asà que
// se usan todos los núcleos disponibles en lugar de la mitad.
flags << QStringLiteral("--num-raster-threads=%1").arg(qBound(1, cores, 4));
} else {
// Modos con composición por GPU. Las superposiciones de vÃdeo
// (MPO) de las gráficas Intel antiguas son otra fuente de
// parpadeos. Se desactivan SOLO ellas: desactivar DirectComposition
// completo bloqueaba el navegador con el bucle monohilo.
flags << QStringLiteral("--disable-direct-composition-video-overlays");
}
}
const qint64 gpuMb = rec.value(QStringLiteral("recursos/memoria_gpu_mb"), 0).toLongLong();
if (gpuMb > 0)
flags << QStringLiteral("--force-gpu-mem-available-mb=%1").arg(gpuMb);
qint64 jsHeapMb = rec.value(QStringLiteral("recursos/ram_max_mb"), 0).toLongLong();
// En equipos con poca RAM (4 GB o menos) se limita el heap de V8 por
// pestaña. Asà el recolector de basura actúa antes y cada renderizador
// deja de crecer sin control, que es lo que provoca el swap y la lentitud.
if (jsHeapMb <= 0 && ramMb > 0 && ramMb <= 4096)
jsHeapMb = 256;
if (jsHeapMb > 0)
flags << QStringLiteral("--js-flags=--max-old-space-size=%1").arg(jsHeapMb);
// Diagnóstico opcional de la GPU/composición de Chromium. Con la variable
// KINETIX_GPU_LOG=<ruta> se vuelca el registro de Chromium a ese archivo,
// para poder averiguar la causa de parpadeos o errores de renderizado.
if (qEnvironmentVariableIsSet("KINETIX_GPU_LOG")) {
const QString logPath = qEnvironmentVariable("KINETIX_GPU_LOG");
if (!logPath.isEmpty())
flags << QStringLiteral("--enable-logging")
<< QStringLiteral("--log-file=%1").arg(logPath)
<< QStringLiteral("--v=1");
}
// Ganchos de diagnóstico/pruebas (permiten experimentar sin recompilar).
if (qEnvironmentVariableIsSet("KINETIX_EXTRA_FLAGS")) {
const QString extra = qEnvironmentVariable("KINETIX_EXTRA_FLAGS").trimmed();
if (!extra.isEmpty())
flags << extra;
}
if (qEnvironmentVariableIsSet("KINETIX_QSG")) {
const QString qsg = qEnvironmentVariable("KINETIX_QSG").trimmed();
if (!qsg.isEmpty())
qputenv("QSG_RHI_BACKEND", qsg.toLocal8Bit());
}
if (qEnvironmentVariableIsSet("KINETIX_RENDER_LOOP")) {
const QString loop = qEnvironmentVariable("KINETIX_RENDER_LOOP").trimmed();
if (!loop.isEmpty())
qputenv("QSG_RENDER_LOOP", loop.toLocal8Bit());
}
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", flags.join(QLatin1Char(' ')).toLocal8Bit());
QApplication app(argc, argv);
app.setApplicationName("Kinetix");
app.setApplicationDisplayName("Kinetix");
app.setApplicationVersion("1.1.1");
app.setOrganizationName("CuriosVault");
app.setOrganizationDomain("curiosvault.dev");
QIcon appIcon(QStringLiteral(":/icons/Kinetix-ico.ico"));
if (appIcon.isNull())
appIcon = QIcon(QStringLiteral(":/icons/Kinetix-ico.png"));
app.setWindowIcon(appIcon);
auto *profile = new QWebEngineProfile(QStringLiteral("Kinetix"), nullptr);
const QString storageDir = QDir::homePath() + QStringLiteral("/.navegador_personal/perfil");
QDir().mkpath(storageDir);
profile->setPersistentStoragePath(storageDir);
profile->setPersistentCookiesPolicy(QWebEngineProfile::AllowPersistentCookies);
profile->setHttpCacheType(QWebEngineProfile::DiskHttpCache);
// ------------------------------------------------------------------
// Cookies de terceros.
//
// Chromium 140 (Qt 6.11.2) bloquea las cookies de terceros por defecto.
// Esto rompe el inicio de sesión con Google en sitios como X/Twitter,
// porque el OAuth necesita leer cookies de accounts.google.com desde
// el dominio del sitio. Se permite por defecto; el usuario puede
// bloquearlas desde Configuración → Privacidad.
// ------------------------------------------------------------------
const bool blockThirdParty = rec.value(QStringLiteral("privacidad/bloquear_terceros"), false).toBool();
if (blockThirdParty) {
profile->cookieStore()->setCookieFilter(
[](const QWebEngineCookieStore::FilterRequest &request) {
return !request.thirdParty;
});
} else {
// Permitir todas las cookies, incluidas las de terceros.
profile->cookieStore()->setCookieFilter(
[](const QWebEngineCookieStore::FilterRequest &) {
return true;
});
}
qint64 cacheMb = rec.value(QStringLiteral("recursos/cache_mb"), 256).toLongLong();
// Migración: 64 MB era el valor por defecto antiguo y quedó guardado en
// las configuraciones existentes. Una caché tan pequeña obliga a volver a
// descargar recursos y ralentiza la navegación; se eleva al valor actual.
if (cacheMb == 64) {
cacheMb = 256;
rec.setValue(QStringLiteral("recursos/cache_mb"), cacheMb);
rec.sync();
}
profile->setHttpCacheMaximumSize(cacheMb * 1024 * 1024);
MainWindow w(profile);
w.show();
const int ret = app.exec();
delete profile;
return ret;
}