Skip to content

Commit

Permalink
#353: paint the spinners using opengl which will use a lot less CPU t…
Browse files Browse the repository at this point in the history
…ime and prevent the flickering

git-svn-id: https://xpra.org/svn/Xpra/trunk@8302 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Dec 27, 2014
1 parent 725c269 commit a34c486
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/xpra/client/client_window_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ def after_draw_refresh(success):
def spinner(self, ok):
if not self.can_have_spinner():
return
log("spinner(%s) queueing redraw")
#with normal windows, we just queue a draw request
#and let the expose event paint the spinner
w, h = self.get_size()
Expand Down
24 changes: 23 additions & 1 deletion src/xpra/client/gl/gl_window_backing_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# later version. See the file COPYING for details.

import os
import time, math

from xpra.log import Logger
log = Logger("opengl", "paint")
Expand Down Expand Up @@ -47,6 +48,7 @@ def get_fcolor(encoding):
from xpra.codecs.codec_constants import get_subsampling_divs
from xpra.client.window_backing_base import fire_paint_callbacks
from xpra.gtk_common.gtk_util import POINTER_MOTION_MASK, POINTER_MOTION_HINT_MASK
from xpra.gtk_common.gtk_spinner import cv
from xpra.client.gtk_base.gtk_window_backing_base import GTKWindowBacking
from xpra.client.gl.gtk_compat import Config_new_by_mode, MODE_DOUBLE, GLContextManager, GLDrawingArea
from xpra.client.gl.gl_check import get_DISPLAY_MODE, GL_ALPHA_SUPPORTED, CAN_DOUBLE_BUFFER, is_pyopengl_memoryview_safe
Expand All @@ -57,7 +59,7 @@ def get_fcolor(encoding):
GL_UNPACK_ROW_LENGTH, GL_UNPACK_ALIGNMENT, \
GL_TEXTURE_MAG_FILTER, GL_TEXTURE_MIN_FILTER, GL_NEAREST, \
GL_UNSIGNED_BYTE, GL_LUMINANCE, GL_LINEAR, \
GL_TEXTURE0, GL_TEXTURE1, GL_TEXTURE2, GL_QUADS, GL_LINE_LOOP, GL_COLOR_BUFFER_BIT, \
GL_TEXTURE0, GL_TEXTURE1, GL_TEXTURE2, GL_QUADS, GL_POLYGON, GL_LINE_LOOP, GL_COLOR_BUFFER_BIT, \
GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER, \
GL_DONT_CARE, GL_TRUE, GL_DEPTH_TEST, \
GL_RGB, GL_RGBA, GL_BGR, GL_BGRA, \
Expand Down Expand Up @@ -196,6 +198,7 @@ def __init__(self, wid, w, h, window_alpha):
self.debug_setup = False
self.border = None
self.paint_screen = False
self.paint_spinner = False
self.draw_needs_refresh = False
self.offscreen_fbo = None

Expand Down Expand Up @@ -480,6 +483,25 @@ def present_fbo(self, encoding, x, y, w, h):
glVertex2i(px, py)
glEnd()

if self.paint_spinner:
#add spinner:
dim = min(ww/3.0, wh/3.0, 100.0)
t = time.time()
count = int(t*4.0)
bx = ww//2
by = wh//2
for i in range(8): #8 lines
glBegin(GL_POLYGON)
c = cv.trs[count%8][i]
glColor4f(c, c, c, 1)
mi1 = math.pi*i/4-math.pi/16
mi2 = math.pi*i/4+math.pi/16
glVertex2i(int(bx+math.sin(mi1)*10), int(by+math.cos(mi1)*10))
glVertex2i(int(bx+math.sin(mi1)*dim), int(by+math.cos(mi1)*dim))
glVertex2i(int(bx+math.sin(mi2)*dim), int(by+math.cos(mi2)*dim))
glVertex2i(int(bx+math.sin(mi2)*10), int(by+math.cos(mi2)*10))
glEnd()

#if desired, paint window border
if self.border and self.border.shown:
#double size since half the line will be off-screen
Expand Down
15 changes: 5 additions & 10 deletions src/xpra/client/gl/gtk2/gl_client_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from xpra.log import Logger
log = Logger("opengl", "window")

from gtk import gdk
import gobject

from xpra.client.gtk2.gtk2_window_base import GTK2WindowBase
Expand Down Expand Up @@ -47,17 +46,13 @@ def set_alpha(self):
#rgb_formats.append("BGRX")

def spinner(self, ok):
if not self._backing.paint_screen or not self._backing._backing or not self.can_have_spinner():
b = self._backing
if not b or not b.paint_screen or not b._backing or not self.can_have_spinner():
return
w, h = self.get_size()
if ok:
self._backing.gl_expose_event(self._backing._backing, "spinner: fake event")
self.queue_draw(0, 0, w, h)
else:
self._backing.gl_expose_event(self._backing._backing, "spinner: fake event")
window = self._backing._backing.get_window()
context = window.cairo_create()
self.paint_spinner(context, gdk.Rectangle(0, 0, w, h))
b.paint_spinner = not ok
b.gl_expose_event(self._backing._backing, "spinner: fake event")
self.queue_draw(0, 0, w, h)

def do_expose_event(self, event):
log("GL do_expose_event(%s)", event)
Expand Down
1 change: 1 addition & 0 deletions src/xpra/client/ui_client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,7 @@ def check_server_echo(self, ping_sent_time):
return False
last = self._server_ok
self._server_ok = not FAKE_BROKEN_CONNECTION and self.last_ping_echoed_time>=ping_sent_time
log("check_server_echo(%s) last=%s, server_ok=%s", ping_sent_time, last, self._server_ok)
if last!=self._server_ok and not self._server_ok:
log.info("server is not responding, drawing spinners over the windows")
def timer_redraw():
Expand Down

0 comments on commit a34c486

Please sign in to comment.