Skip to content

Commit

Permalink
pass alpha setting to gl context so it can choose an appropriate visu…
Browse files Browse the repository at this point in the history
…al, move get_window_handle so we can re-use it, import all ctypes attributes directly

git-svn-id: https://xpra.org/svn/Xpra/trunk@17375 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Nov 11, 2017
1 parent 29705bc commit dc1c454
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/xpra/client/gl/gtk_base/gl_drawing_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def __repr__(self):
def idle_add(self, *args, **kwargs):
glib.idle_add(*args, **kwargs)

def init_gl_config(self, _window_alpha):
self.context = GLContext()
def init_gl_config(self, window_alpha):
self.context = GLContext(window_alpha)
self.window_context = None

def is_double_buffered(self):
Expand Down
15 changes: 7 additions & 8 deletions src/xpra/platform/win32/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

import ctypes

from ctypes import WinDLL, POINTER, WINFUNCTYPE, Structure, c_ulong, c_ushort, c_ubyte, c_int, c_long, c_void_p, c_size_t
from ctypes import WinDLL, POINTER, WINFUNCTYPE, HRESULT, GetLastError, Structure, c_ulong, c_ushort, c_ubyte, c_int, c_long, c_void_p, c_size_t, c_wchar
from ctypes.wintypes import HWND, DWORD, WPARAM, LPARAM, HDC, HMONITOR, HMODULE, SHORT, ATOM, RECT, POINT
from ctypes.wintypes import HANDLE, LPCWSTR, UINT, INT, BOOL, HGDIOBJ, LONG, LPVOID, HBITMAP, LPCSTR, LPWSTR, HWINSTA, HINSTANCE
#imported from this module but not used here:
assert GetLastError

LPCTSTR = LPCSTR
LRESULT = c_long
Expand Down Expand Up @@ -57,7 +57,6 @@
DefWindowProcA = user32.DefWindowProcA
DefWindowProcW = user32.DefWindowProcW
MessageBoxA = user32.MessageBoxA
GetLastError = ctypes.GetLastError
GetSystemMetrics = user32.GetSystemMetrics
SetWindowLongW = user32.SetWindowLongW
GetWindowLongW = user32.GetWindowLongW
Expand Down Expand Up @@ -91,7 +90,7 @@
MapVirtualKeyW = user32.MapVirtualKeyW
GetAsyncKeyState = user32.GetAsyncKeyState
VkKeyScanW = user32.VkKeyScanW
VkKeyScanW.argtypes = [ctypes.c_wchar]
VkKeyScanW.argtypes = [c_wchar]
keybd_event = user32.keybd_event
GetKeyState = user32.GetKeyState
GetKeyState.restype = SHORT
Expand All @@ -100,7 +99,7 @@
GetKeyboardLayoutList.argtypes = [c_int, POINTER(HANDLE*32)]
SystemParametersInfoA = user32.SystemParametersInfoA
EnumWindows = user32.EnumWindows
EnumWindowsProc = ctypes.WINFUNCTYPE(BOOL, HWND, LPARAM)
EnumWindowsProc = WINFUNCTYPE(BOOL, HWND, LPARAM)
IsWindowVisible = user32.IsWindowVisible
GetWindowTextLengthW = user32.GetWindowTextLengthW
GetWindowTextW = user32.GetWindowTextW
Expand Down Expand Up @@ -209,7 +208,7 @@
EndPaint.restype = HDC

#wrap EnumDisplayMonitors to hide the callback function:
MonitorEnumProc = ctypes.WINFUNCTYPE(BOOL, HMONITOR, HDC, POINTER(RECT), LPARAM)
MonitorEnumProc = WINFUNCTYPE(BOOL, HMONITOR, HDC, POINTER(RECT), LPARAM)
_EnumDisplayMonitors = EnumDisplayMonitors
def EnumDisplayMonitors():
results = []
Expand Down Expand Up @@ -239,7 +238,7 @@ class WNDCLASSEX(Structure):
("hIconSm", HANDLE),
]

#GUID = ctypes.c_ubyte * 16
#GUID = c_ubyte * 16
class GUID(Structure):
_fields_ = [
('Data1', c_ulong),
Expand Down
34 changes: 11 additions & 23 deletions src/xpra/platform/win32/gl_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,17 @@
log = Logger("opengl")

from ctypes import sizeof, byref, FormatError
from xpra.os_util import PYTHON2, PYTHON3
from xpra.client.gl.gl_check import check_PyOpenGL_support
from xpra.platform.win32.gui import get_window_handle
from xpra.platform.win32.constants import CS_OWNDC, CS_HREDRAW, CS_VREDRAW, COLOR_WINDOW, WS_OVERLAPPED, WS_SYSMENU, CW_USEDEFAULT
from xpra.platform.win32.common import (
GetDC, SwapBuffers, ChoosePixelFormat, DescribePixelFormat, SetPixelFormat, BeginPaint, EndPaint, DestroyWindow, UnregisterClassA,
GetModuleHandleA, RegisterClassExA, CreateWindowExA, DefWindowProcA, WNDPROC, WNDCLASSEX
)
from xpra.platform.win32.glwin32 import wglCreateContext, wglMakeCurrent, wglDeleteContext , PIXELFORMATDESCRIPTOR, PFD_TYPE_RGBA, PFD_DRAW_TO_WINDOW, PFD_SUPPORT_OPENGL, PFD_DOUBLEBUFFER, PFD_DEPTH_DONTCARE, PFD_MAIN_PLANE, PAINTSTRUCT
from xpra.platform.win32.glwin32 import wglCreateContext, wglMakeCurrent, wglDeleteContext , PIXELFORMATDESCRIPTOR, PFD_TYPE_RGBA, PFD_DRAW_TO_WINDOW, PFD_SUPPORT_OPENGL, PFD_DOUBLEBUFFER, PFD_DEPTH_DONTCARE, PFD_SUPPORT_COMPOSITION, PFD_MAIN_PLANE, PAINTSTRUCT

DOUBLE_BUFFERED = True

if PYTHON3:
from ctypes import CDLL, pythonapi, c_void_p, py_object
PyCapsule_GetPointer = pythonapi.PyCapsule_GetPointer
PyCapsule_GetPointer.restype = c_void_p
PyCapsule_GetPointer.argtypes = [py_object]
log("PyCapsute_GetPointer=%s", PyCapsule_GetPointer)
gdkdll = CDLL("libgdk-3-0.dll")
log("gdkdll=%s", gdkdll)


def DefWndProc(hwnd, msg, wParam, lParam):
return DefWindowProcA(hwnd, msg, wParam, lParam)
Expand Down Expand Up @@ -70,7 +61,8 @@ def __repr__(self):

class WGLContext(object):

def __init__(self):
def __init__(self, alpha=True):
self.alpha = alpha
self.hwnd = 0
self.hdc = 0
self.context = 0
Expand Down Expand Up @@ -123,13 +115,7 @@ def is_double_buffered(self):
return DOUBLE_BUFFERED #self.pixel_format_props.get("double-buffered", False)

def get_paint_context(self, gdk_window):
if PYTHON2:
hwnd = gdk_window.handle
else:
gpointer = PyCapsule_GetPointer(gdk_window.__gpointer__, None)
log("gpointer=%s", gpointer)
hwnd = gdkdll.gdk_win32_window_get_handle(gpointer)
log("hwnd=%s", hwnd)
hwnd = get_window_handle(gdk_window)
if self.hwnd!=hwnd:
#(this shouldn't happen)
#just make sure we don't keep using a context for a different handle:
Expand All @@ -144,28 +130,30 @@ def create_wgl_context(self, hwnd):
self.pixel_format_props = {}
self.hdc = GetDC(hwnd)
flags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DEPTH_DONTCARE
if self.alpha:
flags |= PFD_SUPPORT_COMPOSITION
if DOUBLE_BUFFERED:
flags |= PFD_DOUBLEBUFFER
pfd = PIXELFORMATDESCRIPTOR()
pfd.nsize = sizeof(PIXELFORMATDESCRIPTOR)
pfd.nVersion = 1
pfd.dwFlags = flags
pfd.iPixelType = PFD_TYPE_RGBA
pfd.cColorBits = bpc*3
pfd.cColorBits = bpc*(3+int(self.alpha))
pfd.cRedBits = bpc
pfd.cRedShift = 0
pfd.cGreenBits = bpc
pfd.cGreenShift = 0
pfd.cBlueBits = bpc
pfd.cBlueShift = 0
pfd.cAlphaBits = 0 #bpc
pfd.cAlphaBits = int(self.alpha)*8
pfd.cAlphaShift = 0
pfd.cAccumBits = 0
pfd.cAccumRedBits = 0
pfd.cAccumGreenBits = 0
pfd.cAccumBlueBits = 0
pfd.cAccumAlphaBits = 0
pfd.cDepthBits = bpc*3
pfd.cDepthBits = 24
pfd.cStencilBits = 2
pfd.cAuxBuffers = 0
pfd.iLayerType = PFD_MAIN_PLANE #ignored
Expand Down Expand Up @@ -200,7 +188,7 @@ def create_wgl_context(self, hwnd):
"visible-mask" : pfd.dwVisibleMask,
"double-buffered" : bool(pfd.dwFlags & PFD_DOUBLEBUFFER)
})
log("DescribePixelFormat: %s", self.pixel_format_props)
log.info("DescribePixelFormat: %s", self.pixel_format_props)
context = wglCreateContext(self.hdc)
assert context, "wglCreateContext failed"
log("wglCreateContext(%#x)=%#x", self.hdc, context)
Expand Down
1 change: 1 addition & 0 deletions src/xpra/platform/win32/glwin32.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
PFD_SWAP_COPY = 0x00000400
PFD_SWAP_LAYER_BUFFERS = 0x00000800
PFD_GENERIC_ACCELERATED = 0x00001000
PFD_SUPPORT_COMPOSITION = 0x00008000
PFD_DEPTH_DONTCARE = 0x20000000
PFD_DOUBLEBUFFER_DONTCARE = 0x40000000
PFD_STEREO_DONTCARE = 0x80000000
Expand Down
25 changes: 20 additions & 5 deletions src/xpra/platform/win32/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
GetDeviceCaps,
user32)
from xpra.util import AdHocStruct, csv, envint, envbool
from xpra.os_util import PYTHON2
from xpra.os_util import PYTHON2, PYTHON3

CONSOLE_EVENT_LISTENER = envbool("XPRA_CONSOLE_EVENT_LISTENER", True)
USE_NATIVE_TRAY = envbool("XPRA_USE_NATIVE_TRAY", True)
Expand All @@ -42,6 +42,16 @@
from ctypes import WinDLL, CFUNCTYPE, c_int, POINTER, Structure, byref, sizeof
from ctypes.wintypes import HWND, DWORD, WPARAM, LPARAM, MSG, WCHAR, POINT, RECT

if PYTHON3:
from ctypes import CDLL, pythonapi, c_void_p, py_object
PyCapsule_GetPointer = pythonapi.PyCapsule_GetPointer
PyCapsule_GetPointer.restype = c_void_p
PyCapsule_GetPointer.argtypes = [py_object]
log("PyCapsute_GetPointer=%s", PyCapsule_GetPointer)
gdkdll = CDLL("libgdk-3-0.dll")
log("gdkdll=%s", gdkdll)


shell32 = WinDLL("shell32", use_last_error=True)
try:
from xpra.platform.win32.propsys import set_window_group #@UnresolvedImport
Expand Down Expand Up @@ -217,10 +227,13 @@ def get_window_handle(window):
gdk_window = window.get_window()
except:
pass
try:
if PYTHON2:
return gdk_window.handle
except:
return None
gpointer = PyCapsule_GetPointer(gdk_window.__gpointer__, None)
log("gpointer=%#x", gpointer)
hwnd = gdkdll.gdk_win32_window_get_handle(gpointer)
log("hwnd=%#x", hwnd)
return hwnd


def get_session_type():
Expand Down Expand Up @@ -258,8 +271,10 @@ def win32_propsys_set_group_leader(self, leader):
return
try:
log("win32_propsys_set_group_leader(%s)", leader)
lhandle = leader.handle
lhandle = get_window_handle(leader)
assert lhandle
except:
log("win32_propsys_set_group_leader(%s)", leader, exc_info=True)
log.warn("Warning: no window handle for %s", leader)
log.warn(" cannot set window grouping attribute")
return
Expand Down
12 changes: 7 additions & 5 deletions src/xpra/platform/xposix/gl_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,16 @@ def __repr__(self):

class GLXContext(object):

def __init__(self):
def __init__(self, alpha=True):
display = display_get_default()
screen = display.get_default_screen()
bpc = 8
attrs = c_attrs({
GLX.GLX_RGBA : True,
GLX.GLX_RED_SIZE : 8,
GLX.GLX_GREEN_SIZE : 8,
GLX.GLX_BLUE_SIZE : 8,
GLX.GLX_RED_SIZE : bpc,
GLX.GLX_GREEN_SIZE : bpc,
GLX.GLX_BLUE_SIZE : bpc,
GLX.GLX_ALPHA_SIZE : int(alpha)*bpc,
GLX.GLX_DOUBLEBUFFER : int(DOUBLE_BUFFERED),
})
self.props = {}
Expand All @@ -86,7 +88,7 @@ def getconfig(attrib):
assert GLX.glXQueryVersion(self.xdisplay, byref(major), byref(minor))
log("found GLX version %i.%i", major.value, minor.value)
self.props["GLX"] = (major.value, minor.value)
self.bit_depth = getconfig(GLX.GLX_RED_SIZE) + getconfig(GLX.GLX_GREEN_SIZE) + getconfig(GLX.GLX_BLUE_SIZE)
self.bit_depth = getconfig(GLX.GLX_RED_SIZE) + getconfig(GLX.GLX_GREEN_SIZE) + getconfig(GLX.GLX_BLUE_SIZE) + getconfig(GLX.GLX_ALPHA_SIZE)
self.props["depth"] = self.bit_depth
self.props["has-depth-buffer"] = getconfig(GLX.GLX_DEPTH_SIZE)>0
self.props["has-stencil-buffer"] = getconfig(GLX.GLX_STENCIL_SIZE)>0
Expand Down

0 comments on commit dc1c454

Please sign in to comment.