summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/window.c65
1 files changed, 54 insertions, 11 deletions
diff --git a/src/ui/window.c b/src/ui/window.c
index 80493845..543a0b88 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -272,7 +272,7 @@ static float displayScale_Window_(const iWindow *d) {
272 if (envDpi > 0) { 272 if (envDpi > 0) {
273 return ((float) envDpi) / baseDPI_Window; 273 return ((float) envDpi) / baseDPI_Window;
274 } 274 }
275 fprintf(stderr, "[Window] WARNING: failed to parse LAGRANGE_OVERRIDE_DPI='%s', " 275 fprintf(stderr, "[window] WARNING: failed to parse LAGRANGE_OVERRIDE_DPI='%s', "
276 "ignoring it\n", LAGRANGE_OVERRIDE_DPI); 276 "ignoring it\n", LAGRANGE_OVERRIDE_DPI);
277 /* To avoid showing the warning multiple times, overwrite 277 /* To avoid showing the warning multiple times, overwrite
278 LAGRANGE_OVERRIDE_DPI with the empty string. */ 278 LAGRANGE_OVERRIDE_DPI with the empty string. */
@@ -378,13 +378,35 @@ iBool create_Window_(iWindow *d, iRect rect, uint32_t flags) {
378 /* We are drawing a custom frame so hide the default one. */ 378 /* We are drawing a custom frame so hide the default one. */
379 flags |= SDL_WINDOW_BORDERLESS; 379 flags |= SDL_WINDOW_BORDERLESS;
380 } 380 }
381#endif 381#endif
382 } 382 }
383#if 0
383 if (SDL_CreateWindowAndRenderer( 384 if (SDL_CreateWindowAndRenderer(
384 width_Rect(rect), height_Rect(rect), flags, &d->win, &d->render)) { 385 width_Rect(rect), height_Rect(rect), flags, &d->win, &d->render)) {
385 return iFalse; 386 return iFalse;
386 } 387 }
387#if defined (LAGRANGE_ENABLE_CUSTOM_FRAME) 388#endif
389 const iBool setPos = left_Rect(rect) >= 0 || top_Rect(rect) >= 0;
390 d->win = SDL_CreateWindow("",
391 setPos ? left_Rect(rect) : SDL_WINDOWPOS_CENTERED,
392 setPos ? top_Rect(rect) : SDL_WINDOWPOS_CENTERED,
393 width_Rect(rect),
394 height_Rect(rect),
395 flags);
396 if (!d->win) {
397 fprintf(stderr, "[window] failed to create window: %s\n", SDL_GetError());
398 exit(-3);
399 }
400 d->render = SDL_CreateRenderer(
401 d->win,
402 -1,
403 (forceSoftwareRender_App() ? SDL_RENDERER_SOFTWARE : SDL_RENDERER_ACCELERATED) |
404 SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE);
405 if (!d->render) {
406 fprintf(stderr, "[window] failed to create renderer: %s\n", SDL_GetError());
407 exit(-4);
408 }
409#if defined(LAGRANGE_ENABLE_CUSTOM_FRAME)
388 if (type_Window(d) == main_WindowType && prefs_App()->customFrame) { 410 if (type_Window(d) == main_WindowType && prefs_App()->customFrame) {
389 /* Register a handler for window hit testing (drag, resize). */ 411 /* Register a handler for window hit testing (drag, resize). */
390 SDL_SetWindowHitTest(d->win, hitTest_MainWindow_, d); 412 SDL_SetWindowHitTest(d->win, hitTest_MainWindow_, d);
@@ -434,15 +456,27 @@ void init_Window(iWindow *d, enum iWindowType type, iRect rect, uint32_t flags)
434 if (forceSoftwareRender_App() || !create_Window_(d, rect, flags)) { 456 if (forceSoftwareRender_App() || !create_Window_(d, rect, flags)) {
435 /* No luck, maybe software only? This should always work as long as there is a display. */ 457 /* No luck, maybe software only? This should always work as long as there is a display. */
436 SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software"); 458 SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software");
437 if (!create_Window_(d, rect, 0)) { 459 flags &= ~SDL_WINDOW_OPENGL;
460 start_PerfTimer(create_Window_);
461 if (!create_Window_(d, rect, flags)) {
438 fprintf(stderr, "Error when creating window: %s\n", SDL_GetError()); 462 fprintf(stderr, "Error when creating window: %s\n", SDL_GetError());
439 exit(-2); 463 exit(-2);
440 } 464 }
465 stop_PerfTimer(create_Window_);
441 } 466 }
442 if (left_Rect(rect) >= 0 || top_Rect(rect) >= 0) { 467// start_PerfTimer(setPos);
443 SDL_SetWindowPosition(d->win, left_Rect(rect), top_Rect(rect)); 468// if (left_Rect(rect) >= 0 || top_Rect(rect) >= 0) {
444 } 469// SDL_SetWindowPosition(d->win, left_Rect(rect), top_Rect(rect));
470// }
471// stop_PerfTimer(setPos);
445 SDL_GetRendererOutputSize(d->render, &d->size.x, &d->size.y); 472 SDL_GetRendererOutputSize(d->render, &d->size.x, &d->size.y);
473 /* Renderer info. */ {
474 SDL_RendererInfo info;
475 SDL_GetRendererInfo(d->render, &info);
476 printf("[window] renderer: %s%s\n",
477 info.name,
478 info.flags & SDL_RENDERER_ACCELERATED ? " (accelerated)" : "");
479 }
446 drawBlank_Window_(d); 480 drawBlank_Window_(d);
447 d->pixelRatio = pixelRatio_Window_(d); /* point/pixel conversion */ 481 d->pixelRatio = pixelRatio_Window_(d); /* point/pixel conversion */
448 d->displayScale = displayScale_Window_(d); 482 d->displayScale = displayScale_Window_(d);
@@ -485,10 +519,16 @@ void init_MainWindow(iMainWindow *d, iRect rect) {
485 uint32_t flags = 0; 519 uint32_t flags = 0;
486#if defined (iPlatformAppleDesktop) 520#if defined (iPlatformAppleDesktop)
487 SDL_SetHint(SDL_HINT_RENDER_DRIVER, shouldDefaultToMetalRenderer_MacOS() ? "metal" : "opengl"); 521 SDL_SetHint(SDL_HINT_RENDER_DRIVER, shouldDefaultToMetalRenderer_MacOS() ? "metal" : "opengl");
522 if (shouldDefaultToMetalRenderer_MacOS()) {
523 flags |= SDL_WINDOW_METAL;
524 }
488#elif defined (iPlatformAppleMobile) 525#elif defined (iPlatformAppleMobile)
489 SDL_SetHint(SDL_HINT_RENDER_DRIVER, "metal"); 526 SDL_SetHint(SDL_HINT_RENDER_DRIVER, "metal");
527 flags |= SDL_WINDOW_METAL;
490#else 528#else
491 flags |= SDL_WINDOW_OPENGL; 529 if (!forceSoftwareRender_App()) {
530 flags |= SDL_WINDOW_OPENGL;
531 }
492#endif 532#endif
493 SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1"); 533 SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1");
494 init_Window(&d->base, main_WindowType, rect, flags); 534 init_Window(&d->base, main_WindowType, rect, flags);
@@ -512,9 +552,6 @@ void init_MainWindow(iMainWindow *d, iRect rect) {
512 SDL_RendererInfo info; 552 SDL_RendererInfo info;
513 SDL_GetRendererInfo(d->base.render, &info); 553 SDL_GetRendererInfo(d->base.render, &info);
514 isOpenGLRenderer_ = !iCmpStr(info.name, "opengl"); 554 isOpenGLRenderer_ = !iCmpStr(info.name, "opengl");
515 printf("[window] renderer: %s%s\n",
516 info.name,
517 info.flags & SDL_RENDERER_ACCELERATED ? " (accelerated)" : "");
518#if !defined(NDEBUG) 555#if !defined(NDEBUG)
519 printf("[window] max texture size: %d x %d\n", 556 printf("[window] max texture size: %d x %d\n",
520 info.max_texture_width, 557 info.max_texture_width,
@@ -1592,6 +1629,10 @@ int snap_MainWindow(const iMainWindow *d) {
1592/*----------------------------------------------------------------------------------------------*/ 1629/*----------------------------------------------------------------------------------------------*/
1593 1630
1594iWindow *newPopup_Window(iInt2 screenPos, iWidget *rootWidget) { 1631iWindow *newPopup_Window(iInt2 screenPos, iWidget *rootWidget) {
1632 start_PerfTimer(newPopup_Window);
1633 iPerfTimer pt; init_PerfTimer(&pt);
1634 const iBool oldSw = forceSoftwareRender_App();
1635 setForceSoftwareRender_App(iTrue);
1595 iWindow *win = 1636 iWindow *win =
1596 new_Window(popup_WindowType, 1637 new_Window(popup_WindowType,
1597 (iRect){ screenPos, divf_I2(rootWidget->rect.size, get_Window()->pixelRatio) }, 1638 (iRect){ screenPos, divf_I2(rootWidget->rect.size, get_Window()->pixelRatio) },
@@ -1610,5 +1651,7 @@ iWindow *newPopup_Window(iInt2 screenPos, iWidget *rootWidget) {
1610 root->widget = rootWidget; 1651 root->widget = rootWidget;
1611 root->window = win; 1652 root->window = win;
1612 setRoot_Widget(rootWidget, root); 1653 setRoot_Widget(rootWidget, root);
1654 setForceSoftwareRender_App(oldSw);
1655 stop_PerfTimer(newPopup_Window);
1613 return win; 1656 return win;
1614} 1657}