Move initial window blanking to before showing the window

This commit is contained in:
Kovid Goyal 2019-02-25 15:07:03 +05:30
parent b7b1a1f1c6
commit 01ed1e1604
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 20 additions and 11 deletions

View File

@ -115,6 +115,11 @@ show_mouse_cursor(GLFWwindow *w) {
static int min_width = 100, min_height = 100; static int min_width = 100, min_height = 100;
void
blank_os_window(OSWindow *w) {
blank_canvas(w->is_semi_transparent ? w->background_opacity : 1.0f);
}
static void static void
framebuffer_size_callback(GLFWwindow *w, int width, int height) { framebuffer_size_callback(GLFWwindow *w, int width, int height) {
if (!set_callback_window(w)) return; if (!set_callback_window(w)) return;
@ -516,6 +521,15 @@ create_os_window(PyObject UNUSED *self, PyObject *args) {
GLFWwindow *glfw_window = glfwCreateWindow(width, height, title, NULL, temp_window); GLFWwindow *glfw_window = glfwCreateWindow(width, height, title, NULL, temp_window);
glfwDestroyWindow(temp_window); temp_window = NULL; glfwDestroyWindow(temp_window); temp_window = NULL;
if (glfw_window == NULL) { PyErr_SetString(PyExc_ValueError, "Failed to create GLFWwindow"); return NULL; } if (glfw_window == NULL) { PyErr_SetString(PyExc_ValueError, "Failed to create GLFWwindow"); return NULL; }
glfwMakeContextCurrent(glfw_window);
if (is_first_window) {
gl_init();
}
bool is_semi_transparent = glfwGetWindowAttrib(glfw_window, GLFW_TRANSPARENT_FRAMEBUFFER);
// blank the window once so that there is no initial flash of color
// changing, in case the background color is not black
blank_canvas(is_semi_transparent ? OPT(background_opacity) : 1.0f);
glfwSwapBuffers(glfw_window);
if (!global_state.is_wayland) { if (!global_state.is_wayland) {
PyObject *pret = PyObject_CallFunction(pre_show_callback, "N", native_window_handle(glfw_window)); PyObject *pret = PyObject_CallFunction(pre_show_callback, "N", native_window_handle(glfw_window));
if (pret == NULL) return NULL; if (pret == NULL) return NULL;
@ -523,10 +537,8 @@ create_os_window(PyObject UNUSED *self, PyObject *args) {
if (x != -1 && y != -1) glfwSetWindowPos(glfw_window, x, y); if (x != -1 && y != -1) glfwSetWindowPos(glfw_window, x, y);
glfwShowWindow(glfw_window); glfwShowWindow(glfw_window);
} }
glfwMakeContextCurrent(glfw_window);
if (is_first_window) { if (is_first_window) {
gl_init(); PyObject *ret = PyObject_CallFunction(load_programs, "O", is_semi_transparent ? Py_True : Py_False);
PyObject *ret = PyObject_CallFunction(load_programs, "i", glfwGetWindowAttrib(glfw_window, GLFW_TRANSPARENT_FRAMEBUFFER));
if (ret == NULL) return NULL; if (ret == NULL) return NULL;
Py_DECREF(ret); Py_DECREF(ret);
#ifdef __APPLE__ #ifdef __APPLE__
@ -591,7 +603,7 @@ create_os_window(PyObject UNUSED *self, PyObject *args) {
w->is_focused = true; w->is_focused = true;
w->cursor_blink_zero_time = now; w->cursor_blink_zero_time = now;
w->last_mouse_activity_at = now; w->last_mouse_activity_at = now;
w->is_semi_transparent = glfwGetWindowAttrib(w->handle, GLFW_TRANSPARENT_FRAMEBUFFER); w->is_semi_transparent = is_semi_transparent;
if (want_semi_transparent && !w->is_semi_transparent) { if (want_semi_transparent && !w->is_semi_transparent) {
static bool warned = false; static bool warned = false;
if (!warned) { if (!warned) {
@ -599,10 +611,6 @@ create_os_window(PyObject UNUSED *self, PyObject *args) {
warned = true; warned = true;
} }
} }
// blank the window once so that there is no initial flash of color
// changing, in case the background color is not black
blank_os_window(w);
swap_window_buffers(w);
return PyLong_FromUnsignedLongLong(w->id); return PyLong_FromUnsignedLongLong(w->id);
} }

View File

@ -429,9 +429,9 @@ set_cell_uniforms(float current_inactive_text_alpha) {
} }
void void
blank_os_window(OSWindow *os_window) { blank_canvas(float background_opacity) {
#define C(shift) (((GLfloat)((OPT(background) >> shift) & 0xFF)) / 255.0f) #define C(shift) (((GLfloat)((OPT(background) >> shift) & 0xFF)) / 255.0f)
glClearColor(C(16), C(8), C(0), os_window->is_semi_transparent ? os_window->background_opacity : 1.0f); glClearColor(C(16), C(8), C(0), background_opacity);
#undef C #undef C
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
} }

View File

@ -203,6 +203,7 @@ void update_surface_size(int, int, uint32_t);
void free_texture(uint32_t*); void free_texture(uint32_t*);
void send_image_to_gpu(uint32_t*, const void*, int32_t, int32_t, bool, bool); void send_image_to_gpu(uint32_t*, const void*, int32_t, int32_t, bool, bool);
void send_sprite_to_gpu(FONTS_DATA_HANDLE fg, unsigned int, unsigned int, unsigned int, pixel*); void send_sprite_to_gpu(FONTS_DATA_HANDLE fg, unsigned int, unsigned int, unsigned int, pixel*);
void blank_canvas(float);
void blank_os_window(OSWindow *); void blank_os_window(OSWindow *);
void set_titlebar_color(OSWindow *w, color_type color); void set_titlebar_color(OSWindow *w, color_type color);
FONTS_DATA_HANDLE load_fonts_data(double, double, double); FONTS_DATA_HANDLE load_fonts_data(double, double, double);

View File

@ -55,7 +55,7 @@ def calculate_gl_geometry(window_geometry, viewport_width, viewport_height, cell
return ScreenGeometry(xstart, ystart, window_geometry.xnum, window_geometry.ynum, dx, dy) return ScreenGeometry(xstart, ystart, window_geometry.xnum, window_geometry.ynum, dx, dy)
def load_shader_programs(semi_transparent=0): def load_shader_programs(semi_transparent=False):
compile_program(BLIT_PROGRAM, *load_shaders('blit')) compile_program(BLIT_PROGRAM, *load_shaders('blit'))
v, f = load_shaders('cell') v, f = load_shaders('cell')