steamcompmgr.cpp: rise

This commit is contained in:
Pierre-Loup A. Griffais 2020-01-22 21:50:01 -08:00
parent 74143121cd
commit 1830b53c2e
8 changed files with 106 additions and 79 deletions

View file

@ -46,7 +46,7 @@ libftoff_dep = liftoff_proj.get_variable('liftoff')
executable( executable(
'gamescope', 'gamescope',
'src/steamcompmgr.c', 'src/steamcompmgr.cpp',
'src/main.cpp', 'src/main.cpp',
'src/wlserver.c', 'src/wlserver.c',
'src/drm.cpp', 'src/drm.cpp',

View file

@ -343,10 +343,10 @@ struct funcinfo_t
static std::unordered_map< pid_t, std::unordered_map< const char *, funcinfo_t > > g_hotfuncs; static std::unordered_map< pid_t, std::unordered_map< const char *, funcinfo_t > > g_hotfuncs;
#endif // __cplusplus #endif // __cplusplus
// static pid_t gpuvis_gettid() static pid_t gpuvis_gettid()
// { {
// return ( pid_t )syscall( SYS_gettid ); return ( pid_t )syscall( SYS_gettid );
// } }
static int exec_tracecmd( const char *cmd ) static int exec_tracecmd( const char *cmd )
{ {

View file

@ -7,7 +7,7 @@
#include <unistd.h> #include <unistd.h>
#include "wlserver.h" #include "wlserver.h"
#include "steamcompmgr.h" #include "steamcompmgr.hpp"
#include "main.hpp" #include "main.hpp"
#include "drm.hpp" #include "drm.hpp"

View file

@ -5,7 +5,7 @@
#include "rendervulkan.hpp" #include "rendervulkan.hpp"
#include "main.hpp" #include "main.hpp"
#include "steamcompmgr.h" #include "steamcompmgr.hpp"
#include "composite.h" #include "composite.h"

View file

@ -53,12 +53,11 @@
#include <X11/extensions/shape.h> #include <X11/extensions/shape.h>
#include <X11/extensions/xf86vmode.h> #include <X11/extensions/xf86vmode.h>
#define C_SIDE
#include "main.hpp" #include "main.hpp"
#include "wlserver.h" #include "wlserver.h"
#include "drm.hpp" #include "drm.hpp"
#include "rendervulkan.hpp" #include "rendervulkan.hpp"
#include "steamcompmgr.hpp"
#define GPUVIS_TRACE_IMPLEMENTATION #define GPUVIS_TRACE_IMPLEMENTATION
#include "gpuvis_trace_utils.h" #include "gpuvis_trace_utils.h"
@ -116,11 +115,10 @@ static int damage_event, damage_error;
static int composite_event, composite_error; static int composite_event, composite_error;
static int render_event, render_error; static int render_event, render_error;
static int xshape_event, xshape_error; static int xshape_event, xshape_error;
static int xfixes_event, xfixes_error;
static Bool synchronize; static Bool synchronize;
static int composite_opcode; static int composite_opcode;
int currentOutputWidth, currentOutputHeight; uint32_t currentOutputWidth, currentOutputHeight;
static Window currentFocusWindow; static Window currentFocusWindow;
static Window currentOverlayWindow; static Window currentOverlayWindow;
@ -240,7 +238,7 @@ discard_ignore (Display *dpy, unsigned long sequence)
static void static void
set_ignore (Display *dpy, unsigned long sequence) set_ignore (Display *dpy, unsigned long sequence)
{ {
ignore *i = malloc (sizeof (ignore)); ignore *i = (ignore *)malloc (sizeof (ignore));
if (!i) if (!i)
return; return;
i->sequence = sequence; i->sequence = sequence;
@ -530,7 +528,7 @@ paint_cursor ( Display *dpy, win *w, struct Composite_t *pComposite, struct Vulk
static void static void
paint_window (Display *dpy, win *w, struct Composite_t *pComposite, struct VulkanPipeline_t *pPipeline, Bool notificationMode) paint_window (Display *dpy, win *w, struct Composite_t *pComposite, struct VulkanPipeline_t *pPipeline, Bool notificationMode)
{ {
int sourceWidth, sourceHeight; uint32_t sourceWidth, sourceHeight;
int drawXOffset = 0, drawYOffset = 0; int drawXOffset = 0, drawYOffset = 0;
float currentScaleRatio = 1.0; float currentScaleRatio = 1.0;
@ -917,7 +915,7 @@ determine_and_apply_focus (Display *dpy)
// a choice between two windows we always prefer the non-override redirect one. // a choice between two windows we always prefer the non-override redirect one.
Bool windowIsOverrideRedirect = w->a.override_redirect && !w->ignoreOverrideRedirect; Bool windowIsOverrideRedirect = w->a.override_redirect && !w->ignoreOverrideRedirect;
if (w->gameID && w->a.map_state == IsViewable && w->a.class == InputOutput && if (w->gameID && w->a.map_state == IsViewable && w->a.c_class == InputOutput &&
(w->damage_sequence >= maxDamageSequence) && (w->damage_sequence >= maxDamageSequence) &&
(!windowIsOverrideRedirect || !usingOverrideRedirectWindow)) (!windowIsOverrideRedirect || !usingOverrideRedirectWindow))
{ {
@ -1006,8 +1004,8 @@ determine_and_apply_focus (Display *dpy)
XResizeWindow(dpy, focus->id, root_width, root_height); XResizeWindow(dpy, focus->id, root_width, root_height);
} }
else if (!focus->isFullscreen && focus->sizeHintsSpecified && else if (!focus->isFullscreen && focus->sizeHintsSpecified &&
(focus->a.width != focus->requestedWidth || ((unsigned)focus->a.width != focus->requestedWidth ||
focus->a.height != focus->requestedHeight)) (unsigned)focus->a.height != focus->requestedHeight))
{ {
XResizeWindow(dpy, focus->id, focus->requestedWidth, focus->requestedHeight); XResizeWindow(dpy, focus->id, focus->requestedWidth, focus->requestedHeight);
} }
@ -1193,10 +1191,10 @@ unmap_win (Display *dpy, Window id, Bool fade)
static void static void
add_win (Display *dpy, Window id, Window prev, unsigned long sequence) add_win (Display *dpy, Window id, Window prev, unsigned long sequence)
{ {
win *new = malloc (sizeof (win)); win *new_win = (win*)malloc (sizeof (win));
win **p; win **p;
if (!new) if (!new_win)
return; return;
if (prev) if (prev)
{ {
@ -1206,58 +1204,58 @@ add_win (Display *dpy, Window id, Window prev, unsigned long sequence)
} }
else else
p = &list; p = &list;
new->id = id; new_win->id = id;
set_ignore (dpy, NextRequest (dpy)); set_ignore (dpy, NextRequest (dpy));
if (!XGetWindowAttributes (dpy, id, &new->a)) if (!XGetWindowAttributes (dpy, id, &new_win->a))
{ {
free (new); free (new_win);
return; return;
} }
new->damaged = 0; new_win->damaged = 0;
new->validContents = False; new_win->validContents = False;
new->committed = False; new_win->committed = False;
new->fb_id = 0; new_win->fb_id = 0;
new->vulkanTex = 0; new_win->vulkanTex = 0;
new->damage_sequence = 0; new_win->damage_sequence = 0;
new->map_sequence = 0; new_win->map_sequence = 0;
if (new->a.class == InputOnly) if (new_win->a.c_class == InputOnly)
new->damage = None; new_win->damage = None;
else else
{ {
new->damage = XDamageCreate (dpy, id, XDamageReportRawRectangles); new_win->damage = XDamageCreate (dpy, id, XDamageReportRawRectangles);
} }
new->opacity = TRANSLUCENT; new_win->opacity = TRANSLUCENT;
new->isOverlay = False; new_win->isOverlay = False;
new->isSteam = False; new_win->isSteam = False;
if ( steamMode == True ) if ( steamMode == True )
{ {
new->gameID = 0; new_win->gameID = 0;
} }
else else
{ {
new->gameID = id; new_win->gameID = id;
} }
new->isFullscreen = False; new_win->isFullscreen = False;
new->isHidden = False; new_win->isHidden = False;
new->sizeHintsSpecified = False; new_win->sizeHintsSpecified = False;
new->requestedWidth = 0; new_win->requestedWidth = 0;
new->requestedHeight = 0; new_win->requestedHeight = 0;
new->nudged = False; new_win->nudged = False;
new->ignoreOverrideRedirect = False; new_win->ignoreOverrideRedirect = False;
new->mouseMoved = False; new_win->mouseMoved = False;
new->WLsurfaceID = 0; new_win->WLsurfaceID = 0;
new->wlrsurface = NULL; new_win->wlrsurface = NULL;
new->dmabuf_attribs_valid = False; new_win->dmabuf_attribs_valid = False;
new->next = *p; new_win->next = *p;
*p = new; *p = new_win;
if (new->a.map_state == IsViewable) if (new_win->a.map_state == IsViewable)
map_win (dpy, id, sequence); map_win (dpy, id, sequence);
focusDirty = True; focusDirty = True;
@ -1437,26 +1435,19 @@ damage_win (Display *dpy, XDamageNotifyEvent *de)
} }
static void static void
handle_wl_surface_id(Display *dpy, win *w, long surfaceID) handle_wl_surface_id(win *w, long surfaceID)
{ {
struct wlr_surface *surface = NULL; struct wlr_surface *surface = NULL;
wlserver_lock(); wlserver_lock();
struct wl_resource *resource = wl_client_get_object(wlserver.wlr.xwayland->client, surfaceID); surface = wlserver_get_surface( surfaceID );
if (resource) {
surface = wlr_surface_from_resource(resource);
}
else
{
w->WLsurfaceID = surfaceID;
wlserver_unlock();
return;
}
if (!wlr_surface_set_role(surface, &xwayland_surface_role, w, NULL, 0)) if ( surface == NULL )
{ {
fprintf (stderr, "Failed to set xwayland surface role"); // We'll retry next time
w->WLsurfaceID = surfaceID;
wlserver_unlock(); wlserver_unlock();
return; return;
} }
@ -1632,7 +1623,7 @@ void check_new_wayland_res(void)
struct timespec now; struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now); clock_gettime(CLOCK_MONOTONIC, &now);
wlserver_lock(); wlserver_lock();
wlr_surface_send_frame_done(w->wlrsurface, &now); wlserver_send_frame_done(w->wlrsurface, &now);
wlserver_unlock(); wlserver_unlock();
} }
@ -1658,7 +1649,6 @@ steamcompmgr_main (int argc, char **argv)
Window root_return, parent_return; Window root_return, parent_return;
Window *children; Window *children;
unsigned int nchildren; unsigned int nchildren;
int i;
int composite_major, composite_minor; int composite_major, composite_minor;
int o; int o;
int readyPipeFD = -1; int readyPipeFD = -1;
@ -1695,7 +1685,7 @@ steamcompmgr_main (int argc, char **argv)
} }
} }
dpy = XOpenDisplay (wlserver.wlr.xwayland->display_name); dpy = XOpenDisplay ( wlserver_get_nested_display() );
if (!dpy) if (!dpy)
{ {
fprintf (stderr, "Can't open display\n"); fprintf (stderr, "Can't open display\n");
@ -1801,7 +1791,7 @@ steamcompmgr_main (int argc, char **argv)
XShapeSelectInput (dpy, root, ShapeNotifyMask); XShapeSelectInput (dpy, root, ShapeNotifyMask);
XFixesSelectCursorInput(dpy, root, XFixesDisplayCursorNotifyMask); XFixesSelectCursorInput(dpy, root, XFixesDisplayCursorNotifyMask);
XQueryTree (dpy, root, &root_return, &parent_return, &children, &nchildren); XQueryTree (dpy, root, &root_return, &parent_return, &children, &nchildren);
for (i = 0; i < nchildren; i++) for (uint32_t i = 0; i < nchildren; i++)
add_win (dpy, children[i], i ? children[i-1] : None, 0); add_win (dpy, children[i], i ? children[i-1] : None, 0);
XFree (children); XFree (children);
@ -1822,7 +1812,7 @@ steamcompmgr_main (int argc, char **argv)
if ( readyPipeFD != -1 ) if ( readyPipeFD != -1 )
{ {
dprintf( readyPipeFD, "%s\n", wlserver.wlr.xwayland->display_name ); dprintf( readyPipeFD, "%s\n", wlserver_get_nested_display() );
close( readyPipeFD ); close( readyPipeFD );
readyPipeFD = -1; readyPipeFD = -1;
} }
@ -2038,11 +2028,11 @@ steamcompmgr_main (int argc, char **argv)
{ {
if (ev.xclient.message_type == WLSurfaceIDAtom) if (ev.xclient.message_type == WLSurfaceIDAtom)
{ {
handle_wl_surface_id(dpy, w, ev.xclient.data.l[0]); handle_wl_surface_id( w, ev.xclient.data.l[0]);
} }
else else
{ {
if (ev.xclient.data.l[1] == fullscreenAtom) if ((unsigned)ev.xclient.data.l[1] == fullscreenAtom)
{ {
w->isFullscreen = ev.xclient.data.l[0]; w->isFullscreen = ev.xclient.data.l[0];
@ -2114,7 +2104,7 @@ steamcompmgr_main (int argc, char **argv)
{ {
if ( w->wlrsurface == NULL && w->WLsurfaceID != 0 ) if ( w->wlrsurface == NULL && w->WLsurfaceID != 0 )
{ {
handle_wl_surface_id( dpy, w, w->WLsurfaceID ); handle_wl_surface_id( w, w->WLsurfaceID );
if ( w->wlrsurface != NULL ) if ( w->wlrsurface != NULL )
{ {
@ -2182,7 +2172,7 @@ steamcompmgr_main (int argc, char **argv)
{ {
// Acknowledge commit once. // Acknowledge commit once.
wlserver_lock(); wlserver_lock();
wlr_surface_send_frame_done(w->wlrsurface, &now); wlserver_send_frame_done(w->wlrsurface, &now);
wlserver_unlock(); wlserver_unlock();
w->committed = False; w->committed = False;

View file

@ -2,8 +2,8 @@
extern "C" { extern "C" {
#endif #endif
extern int currentOutputWidth; extern uint32_t currentOutputWidth;
extern int currentOutputHeight; extern uint32_t currentOutputHeight;
unsigned int get_time_in_milliseconds(void); unsigned int get_time_in_milliseconds(void);

View file

@ -26,7 +26,7 @@
#define C_SIDE #define C_SIDE
#include "steamcompmgr.h" #include "steamcompmgr.hpp"
#include "wlserver.h" #include "wlserver.h"
#include "drm.hpp" #include "drm.hpp"
#include "main.hpp" #include "main.hpp"
@ -65,6 +65,8 @@ void nudge_steamcompmgr(void)
XFlush( g_XWLDpy ); XFlush( g_XWLDpy );
} }
const struct wlr_surface_role xwayland_surface_role;
void xwayland_surface_role_commit(struct wlr_surface *wlr_surface) { void xwayland_surface_role_commit(struct wlr_surface *wlr_surface) {
assert(wlr_surface->role == &xwayland_surface_role); assert(wlr_surface->role == &xwayland_surface_role);
@ -552,3 +554,35 @@ void wlserver_mousewheel( int x, int y, uint32_t time )
} }
wlr_seat_pointer_notify_frame( wlserver.wlr.seat ); wlr_seat_pointer_notify_frame( wlserver.wlr.seat );
} }
void wlserver_send_frame_done( struct wlr_surface *surf, const struct timespec *when )
{
wlr_surface_send_frame_done( surf, when );
}
struct wlr_surface *wlserver_get_surface( long surfaceID )
{
struct wlr_surface *ret = NULL;
struct wl_resource *resource = wl_client_get_object(wlserver.wlr.xwayland->client, surfaceID);
if (resource) {
ret = wlr_surface_from_resource(resource);
}
else
{
return NULL;
}
if ( !wlr_surface_set_role(ret, &xwayland_surface_role, NULL, NULL, 0 ) )
{
fprintf (stderr, "Failed to set xwayland surface role");
return NULL;
}
return ret;
}
const char *wlserver_get_nested_display( void )
{
return wlserver.wlr.xwayland->display_name;
}

View file

@ -70,8 +70,6 @@ extern struct wlserver_t wlserver;
extern "C" { extern "C" {
#endif #endif
extern const struct wlr_surface_role xwayland_surface_role;
void xwayland_surface_role_commit(struct wlr_surface *wlr_surface); void xwayland_surface_role_commit(struct wlr_surface *wlr_surface);
int wlserver_init( int argc, char **argv, bool bIsNested ); int wlserver_init( int argc, char **argv, bool bIsNested );
@ -91,6 +89,11 @@ void wlserver_mousemotion( int x, int y, uint32_t time );
void wlserver_mousebutton( int button, bool press, uint32_t time ); void wlserver_mousebutton( int button, bool press, uint32_t time );
void wlserver_mousewheel( int x, int y, uint32_t time ); void wlserver_mousewheel( int x, int y, uint32_t time );
void wlserver_send_frame_done( struct wlr_surface *surf, const struct timespec *when );
struct wlr_surface *wlserver_get_surface( long surfaceID );
const char *wlserver_get_nested_display( void );
#ifndef C_SIDE #ifndef C_SIDE
} }
#endif #endif