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(
'gamescope',
'src/steamcompmgr.c',
'src/steamcompmgr.cpp',
'src/main.cpp',
'src/wlserver.c',
'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;
#endif // __cplusplus
// static pid_t gpuvis_gettid()
// {
// return ( pid_t )syscall( SYS_gettid );
// }
static pid_t gpuvis_gettid()
{
return ( pid_t )syscall( SYS_gettid );
}
static int exec_tracecmd( const char *cmd )
{

View file

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

View file

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

View file

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

View file

@ -2,9 +2,9 @@
extern "C" {
#endif
extern int currentOutputWidth;
extern int currentOutputHeight;
extern uint32_t currentOutputWidth;
extern uint32_t currentOutputHeight;
unsigned int get_time_in_milliseconds(void);
int steamcompmgr_main(int argc, char **argv);

View file

@ -26,7 +26,7 @@
#define C_SIDE
#include "steamcompmgr.h"
#include "steamcompmgr.hpp"
#include "wlserver.h"
#include "drm.hpp"
#include "main.hpp"
@ -65,6 +65,8 @@ void nudge_steamcompmgr(void)
XFlush( g_XWLDpy );
}
const struct wlr_surface_role xwayland_surface_role;
void xwayland_surface_role_commit(struct wlr_surface *wlr_surface) {
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 );
}
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" {
#endif
extern const struct wlr_surface_role xwayland_surface_role;
void xwayland_surface_role_commit(struct wlr_surface *wlr_surface);
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_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
}
#endif