cr_server.h revision 43747b1f0bc8302a238fb35e55857a5e9aa1933d
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync/* Copyright (c) 2001, Stanford University
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync * All rights reserved.
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync *
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync * See the file LICENSE.txt for information on redistributing this software.
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync */
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync
c58f1213e628a545081c70e26c6b67a841cff880vboxsync#ifndef INCLUDE_CR_SERVER_H
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync#define INCLUDE_CR_SERVER_H
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync#include "cr_spu.h"
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync#include "cr_net.h"
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync#include "cr_hash.h"
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync#include "cr_protocol.h"
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync#include "cr_glstate.h"
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync#include "spu_dispatch_table.h"
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync#include "state/cr_currentpointers.h"
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync#include <iprt/types.h>
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync#include <iprt/err.h>
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync#include <VBox/vmm/ssm.h>
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync#ifdef __cplusplus
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsyncextern "C" {
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync#endif
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync#define SHCROGL_SSM_VERSION 24
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync#define CR_MAX_WINDOWS 100
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync#define CR_MAX_CLIENTS 64
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync/*@todo must match MaxGuestMonitors from SchemaDefs.h*/
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync#define CR_MAX_GUEST_MONITORS 8
c1f4d314cb8f8b75e2d67a3553ecabd081f1e1c6vboxsync
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsynctypedef DECLCALLBACKPTR(void, PFNCRSERVERPRESENTFBO) (void *data, int32_t screenId, int32_t x, int32_t y, uint32_t w, uint32_t h);
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsynctypedef struct {
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync CRrecti imagewindow; /**< coordinates in mural space */
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync CRrectf bounds; /**< normalized coordinates in [-1,-1] x [1,1] */
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync CRrecti outputwindow; /**< coordinates in server's rendering window */
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync CRrecti clippedImagewindow; /**< imagewindow clipped to current viewport */
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync CRmatrix baseProjection; /**< pre-multiplied onto projection matrix */
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync CRrecti scissorBox; /**< passed to back-end OpenGL */
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync CRrecti viewport; /**< passed to back-end OpenGL */
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync GLuint serialNo; /**< an optimization */
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync} CRExtent;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsyncstruct BucketingInfo;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync/**
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync * Mural info
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync */
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsynctypedef struct {
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync GLuint width, height;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync GLint gX, gY; /*guest coordinates*/
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync GLint hX, hY; /*host coordinates, screenID related*/
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync int spuWindow; /*the SPU's corresponding window ID */
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync int screenId;
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync GLboolean bVisible; /*guest window is visible*/
15da024e837fd6ef1ba24564011e74a3d0cd30a5vboxsync GLboolean bUseFBO; /*redirect to FBO instead of real host window*/
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync GLint cVisibleRects; /*count of visible rects*/
15da024e837fd6ef1ba24564011e74a3d0cd30a5vboxsync GLint *pVisibleRects; /*visible rects left, top, right, bottom*/
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync
15da024e837fd6ef1ba24564011e74a3d0cd30a5vboxsync GLuint idFBO, idColorTex, idDepthStencilRB;
15da024e837fd6ef1ba24564011e74a3d0cd30a5vboxsync GLuint fboWidth, fboHeight;
15da024e837fd6ef1ba24564011e74a3d0cd30a5vboxsync} CRMuralInfo;
15da024e837fd6ef1ba24564011e74a3d0cd30a5vboxsync
15da024e837fd6ef1ba24564011e74a3d0cd30a5vboxsync/**
15da024e837fd6ef1ba24564011e74a3d0cd30a5vboxsync * A client is basically an upstream Cr Node (connected via mothership)
15da024e837fd6ef1ba24564011e74a3d0cd30a5vboxsync */
15da024e837fd6ef1ba24564011e74a3d0cd30a5vboxsynctypedef struct _crclient {
15da024e837fd6ef1ba24564011e74a3d0cd30a5vboxsync int spu_id; /**< id of the last SPU in the client's SPU chain */
15da024e837fd6ef1ba24564011e74a3d0cd30a5vboxsync CRConnection *conn; /**< network connection from the client */
15da024e837fd6ef1ba24564011e74a3d0cd30a5vboxsync int number; /**< a unique number for each client */
15da024e837fd6ef1ba24564011e74a3d0cd30a5vboxsync uint64_t pid; /*guest pid*/
15da024e837fd6ef1ba24564011e74a3d0cd30a5vboxsync GLint currentContextNumber;
15da024e837fd6ef1ba24564011e74a3d0cd30a5vboxsync CRContext *currentCtx;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync GLint currentWindow;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync CRMuralInfo *currentMural;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync GLint windowList[CR_MAX_WINDOWS];
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync GLint contextList[CR_MAX_CONTEXTS];
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync#ifdef VBOXCR_LOGFPS
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync uint64_t timeUsed;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync#endif
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync} CRClient;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsynctypedef struct _crclientnode {
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync CRClient *pClient;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync struct _crclientnode *prev, *next;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync} CRClientNode;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsynctypedef struct CRPoly_t {
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync int npoints;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync double *points;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync struct CRPoly_t *next;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync} CRPoly;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync/**
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync * There's one of these run queue entries per client
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync * The run queue is a circular, doubly-linked list of these objects.
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync */
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsynctypedef struct RunQueue_t {
15da024e837fd6ef1ba24564011e74a3d0cd30a5vboxsync CRClient *client;
15da024e837fd6ef1ba24564011e74a3d0cd30a5vboxsync int blocked;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync struct RunQueue_t *next;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync struct RunQueue_t *prev;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync} RunQueue;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsynctypedef struct {
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync GLint freeWindowID;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync GLint freeContextID;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync GLint freeClientID;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync} CRServerFreeIDsPool_t;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsynctypedef struct {
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync int32_t x, y;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync uint32_t w, h;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync uint64_t winID;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync} CRScreenInfo;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync
15da024e837fd6ef1ba24564011e74a3d0cd30a5vboxsynctypedef struct {
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync unsigned short tcpip_port;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync CRScreenInfo screen[CR_MAX_GUEST_MONITORS];
15da024e837fd6ef1ba24564011e74a3d0cd30a5vboxsync int screenCount;
15da024e837fd6ef1ba24564011e74a3d0cd30a5vboxsync
15da024e837fd6ef1ba24564011e74a3d0cd30a5vboxsync int numClients;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync CRClient *clients[CR_MAX_CLIENTS]; /**< array [numClients] */
15da024e837fd6ef1ba24564011e74a3d0cd30a5vboxsync CRClient *curClient;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync CRClientNode *pCleanupClient; /*list of clients with pending clean up*/
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync CRCurrentStatePointers current;
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync
f212e1f2b6bb160f9b7539562599a4604ca44cd2vboxsync GLboolean firstCallCreateContext;
GLboolean firstCallMakeCurrent;
GLboolean bIsInLoadingState; /* Indicates if we're in process of loading VM snapshot */
GLboolean bIsInSavingState; /* Indicates if we're in process of saving VM snapshot */
GLint currentWindow;
GLint currentNativeWindow;
CRHashTable *muralTable; /**< hash table where all murals are stored */
CRHashTable *pWindowCreateInfoTable; /**< hash table with windows creation info */
int client_spu_id;
CRServerFreeIDsPool_t idsPool;
int mtu;
int buffer_size;
char protocol[1024];
SPU *head_spu;
SPUDispatchTable dispatch;
CRNetworkPointer return_ptr;
CRNetworkPointer writeback_ptr;
CRLimitsState limits; /**< GL limits for any contexts we create */
int SpuContext; /**< Rendering context for the head SPU */
int SpuContextVisBits; /**< Context's visual attributes */
char *SpuContextDpyName; /**< Context's dpyName */
CRHashTable *contextTable; /**< hash table for rendering contexts */
CRHashTable *pContextCreateInfoTable; /**< hash table with contexts creation info */
CRContext *DummyContext; /**< used when no other bound context */
CRHashTable *programTable; /**< for vertex programs */
GLuint currentProgram;
/** configuration options */
/*@{*/
int useL2;
int ignore_papi;
unsigned int maxBarrierCount;
unsigned int clearCount;
int optimizeBucket;
int only_swap_once;
int debug_barriers;
int sharedDisplayLists;
int sharedTextureObjects;
int sharedPrograms;
int sharedWindows;
int uniqueWindows;
int localTileSpec;
int useDMX;
int overlapBlending;
int vpProjectionMatrixParameter;
const char *vpProjectionMatrixVariable;
int stereoView;
int vncMode; /* cmd line option */
/*@}*/
/** view_matrix config */
/*@{*/
GLboolean viewOverride;
CRmatrix viewMatrix[2]; /**< left and right eye */
/*@}*/
/** projection_matrix config */
/*@{*/
GLboolean projectionOverride;
CRmatrix projectionMatrix[2]; /**< left and right eye */
int currentEye;
/*@}*/
/** for warped tiles */
/*@{*/
GLfloat alignment_matrix[16], unnormalized_alignment_matrix[16];
/*@}*/
/** tile overlap/blending info - this should probably be per-mural */
/*@{*/
CRPoly **overlap_geom;
CRPoly *overlap_knockout;
float *overlap_intens;
int num_overlap_intens;
int num_overlap_levels;
/*@}*/
CRHashTable *barriers, *semaphores;
RunQueue *run_queue;
GLuint currentSerialNo;
PFNCRSERVERPRESENTFBO pfnPresentFBO;
} CRServer;
extern DECLEXPORT(void) crServerInit( int argc, char *argv[] );
extern DECLEXPORT(int) CRServerMain( int argc, char *argv[] );
extern DECLEXPORT(void) crServerServiceClients(void);
extern DECLEXPORT(void) crServerAddNewClient(void);
extern DECLEXPORT(SPU*) crServerHeadSPU(void);
extern DECLEXPORT(void) crServerSetPort(int port);
extern DECLEXPORT(GLboolean) crVBoxServerInit(void);
extern DECLEXPORT(void) crVBoxServerTearDown(void);
extern DECLEXPORT(int32_t) crVBoxServerAddClient(uint32_t u32ClientID);
extern DECLEXPORT(void) crVBoxServerRemoveClient(uint32_t u32ClientID);
extern DECLEXPORT(int32_t) crVBoxServerClientWrite(uint32_t u32ClientID, uint8_t *pBuffer, uint32_t cbBuffer);
extern DECLEXPORT(int32_t) crVBoxServerClientRead(uint32_t u32ClientID, uint8_t *pBuffer, uint32_t *pcbBuffer);
extern DECLEXPORT(int32_t) crVBoxServerClientSetVersion(uint32_t u32ClientID, uint32_t vMajor, uint32_t vMinor);
extern DECLEXPORT(int32_t) crVBoxServerClientSetPID(uint32_t u32ClientID, uint64_t pid);
extern DECLEXPORT(int32_t) crVBoxServerSaveState(PSSMHANDLE pSSM);
extern DECLEXPORT(int32_t) crVBoxServerLoadState(PSSMHANDLE pSSM, uint32_t version);
extern DECLEXPORT(int32_t) crVBoxServerSetScreenCount(int sCount);
extern DECLEXPORT(int32_t) crVBoxServerUnmapScreen(int sIndex);
extern DECLEXPORT(int32_t) crVBoxServerMapScreen(int sIndex, int32_t x, int32_t y, uint32_t w, uint32_t h, uint64_t winID);
extern DECLEXPORT(int32_t) crVBoxServerSetRootVisibleRegion(GLint cRects, GLint *pRects);
extern DECLEXPORT(void) crVBoxServerSetPresentFBOCB(PFNCRSERVERPRESENTFBO pfnPresentFBO);
#ifdef __cplusplus
}
#endif
#endif