New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
target-bsnes: Do not set the window background colour. #126
target-bsnes: Do not set the window background colour. #126
Conversation
Kawa very kindly tested this branch on Win32, and discovered that if you resize the window enough without a game loaded, eventually it forgets to paint part of the viewport: That's probably a deal-breaker. I assume the Viewport widget has an actual child-window associated with it (because it needs to be associated with a 3D rendering context), but the hiro Viewport widget itself does not have a |
Sure it's an anonying graphic glitch, but does it still appear once a game is loaded? |
Looking at the code it acts as though it's forcefully set to black always. I don't know if that's ideal but if it's meant for rendering OpenGL video I guess that makes sense. That corner at the bottom right appears to not be the viewport though. bsnes uses some layout tricks to put a canvas widget to draw the program icon. https://github.com/bsnes-emu/bsnes/blob/master/bsnes/target-bsnes/presentation/presentation.hpp#L127 The canvas and viewport classes have very different painting functions. https://github.com/bsnes-emu/bsnes/blob/master/hiro/windows/widget/canvas.cpp#L92 https://github.com/bsnes-emu/bsnes/blob/master/hiro/windows/widget/viewport.cpp#L52 I don't know Win32 enough to try and "fix" this, or even if it can be fixed. Maybe ask @jchv? As a test, maybe we could disable the bsnes icon on the window. I know it's blasphemy but it could be the easy fix here if viewport works and canvas doesn't. |
Correction: it started like that. Although resizing was smooth as silk, that gray bit was a constant. But at least a smooth constant.
No, the games look fine. |
It turns out that the grey rectangle appears on GTK+2 and GTK+3 too - I didn't see it, because I happened to have "show falling snow" enabled rather than the emulator logo. I wonder how that logo colouring is done. |
OK, after a bit of digging, here's what I've found. The main bsnes window layout looks like this:
Then where does the grey strip come from? Of course, we can just set |
Obviously you set |
If the assigned icon doesn't cover the entire allocated display area, we need to fill the gaps somehow. FIXME: Implement for Cocoa backend.
The bsnes window is mostly covered by the viewport, which is supposed to be black. When the window is resized, the hiro Viewport widget repaints itself, according to whatever hiro backend is in use. However, on some platforms that's not enough. Specifically on X11, when the user resizes a window the window manager, the X server, and the application can all have different ideas about the exact window size. The X11 protocol gives each window a "default background colour", to be used by the X server to fill the blanks after the window manager has resized the window, but before the application has been able to repaint it. Because the bsnes window is *mostly* black, bsnes sets its window background colour to black, so the flickering of X-server-drawn and application-drawn content will be less obvious. Unfortunately, it gets more complex. GTK+2 was designed around the X11 model, and so it works basically the way bsnes expects. GTK+3 was designed around the more modern compositing model, which doesn't need that "default background colour" hack, and as a result when you set the window background colour on GTK+3. that background colour is used for *everything*. Even the menu-bar, which by default draws text in a very dark grey, so you can hardly read what it says. To fix this problem, we stop setting the background of the entire window to black, and instead only set the background of the widgets in the middle of the window. Specifically, the viewport widget is always black anyway, but when no game is loaded bsnes has a Canvas widget that displays the bsnes icon. Previously, a Canvas widget would show a background colour *or* an icon, but now that an icon can have a padding color, we can use that to make sure the icon background is black, regardless of the canvas size. Fixes bsnes-emu#108.
8c32d28
to
b657435
Compare
You'd think that, wouldn't you! But no, I decided to do the HARD THING. I've modified the hiro I say I decided to do the HARD THING, but actually I wimped out in two respects:
|
Having slept on it, I am now less convinced of this approach. Given the clunkiness of GDI and who knows how difficult the Cocoa changes would be, the actual practical solution would just be to add another black |
The bsnes window is mostly covered by the viewport, which is supposed to be black. When the window is resized, the hiro Viewport widget repaints itself, according to whatever hiro backend is in use.
However, on some platforms that's not enough. Specifically on X11, when the user resizes a window the window manager, the X server, and the application can all have different ideas about the exact window size. The X11 protocol gives each window a "default background colour", to be used by the X server to fill the blanks after the window manager has resized the window, but before the application has been able to repaint it. Because the bsnes window is mostly black, bsnes sets its window background colour to black, so the flickering of X-server-drawn and application-drawn content will be less obvious.
Unfortunately, it gets more complex. GTK+2 was designed around the X11 model, and so it works basically the way bsnes expects. GTK+3 was designed around the more modern compositing model, which doesn't need that "default background colour" hack, and as a result when you set the window background colour on GTK+3. that background colour is used for everything. Even the menu-bar, which by default draws text in a very dark grey, so you can hardly read what it says.
Perhaps there is a way to both avoid flicker on GTK+2 and not break GTK+3, but until we find it, I would rather occasional flicker on GTK+2 than permanently broken GTK+3.
Fixes #108.