/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86mergedfb.h  Exp $ */

/*
 * Copyright (c) 1998-2003 by The XFree86 Project, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Except as contained in this notice, the name of the copyright holder(s)
 * and author(s) shall not be used in advertising or otherwise to promote
 * the sale, use or other dealings in this Software without prior written
 * authorization from the copyright holder(s) and author(s).
 */

#ifndef _XF86MERGEDFB_H_
#define _XF86MERGEDFB_H_

#include "xf86str.h"

				/* Psuedo Xinerama support */
#define NEED_REPLIES  		/* ? */
#define EXTENSION_PROC_ARGS void *
#include "extnsionst.h"  	/* required */
#include "panoramiXproto.h"  	/* required */
#define MERGEDFB_XINERAMA_MAJOR_VERSION  1
#define MERGEDFB_XINERAMA_MINOR_VERSION  1

/* Relative merge position */
typedef enum {
   mergedfbLeftOf,
   mergedfbRightOf,
   mergedfbAbove,
   mergedfbBelow,
   mergedfbClone
} MergedFBScrn2Rel;


typedef struct {
    /* merged fb stuff, also covers clone modes */
    MergedFBScrn2Rel	CRT2Position;
    char *		CRT2HSync;
    char *		CRT2VRefresh;
    char *		MetaModes;
    ScrnInfoPtr		CRT2pScrn;
    DisplayModePtr	CRT1Modes;
    DisplayModePtr	CRT1CurrentMode;
    int			CRT1frameX0;
    int			CRT1frameY0;
    int			CRT1frameX1;
    int			CRT1frameY1;
    /* psuedo xinerama support for mergedfb */
    int			maxCRT1_X1, maxCRT1_X2, maxCRT1_Y1, maxCRT1_Y2;
    int			maxCRT2_X1, maxCRT2_X2, maxCRT2_Y1, maxCRT2_Y2;
    int			maxClone_X1, maxClone_X2, maxClone_Y1, maxClone_Y2;
    Bool		UseMergedFBXinerama;
    Bool		CRT2IsScrn0;
    ExtensionEntry 	*XineramaExtEntry;
    int			MergedFBXineramaVX, MergedFBXineramaVY;
    Bool		AtLeastOneNonClone;

} MergedFBInfoRec, *MergedFBInfoPtr; 

#define SDMPTR(x) ((MergedDisplayModePtr)(x->currentMode->Private))
#define CDMPTR    ((MergedDisplayModePtr)(pScrn->CurrentLayout.mode->Private))

#define BOUND(test,low,hi) { \
    if(test < low) test = low; \
    if(test > hi) test = hi; }

#define REBOUND(low,hi,test) { \
    if(test < low) { \
        hi += test-low; \
        low = test; } \
    if(test > hi) { \
        low += test-hi; \
        hi = test; } }

typedef struct _MergedDisplayModeRec {
    DisplayModePtr CRT1;
    DisplayModePtr CRT2;
    RADEONScrn2Rel    CRT2Position;
} MergedDisplayModeRec, *MergedDisplayModePtr;

typedef struct _region {
    int x0,x1,y0,y1;
} region;

typedef struct _MergedFBXineramaData {
    int x;
    int y;
    int width;
    int height;
} MergedFBXineramaData;

/*
int xf86MergedFBProcXineramaQueryVersion(ClientPtr client);
int xf86MergedFBProcXineramaGetState(ClientPtr client);
int xf86MergedFBProcXineramaGetScreenCount(ClientPtr client);
int xf86MergedFBProcXineramaGetScreenSize(ClientPtr client);
int xf86MergedFBProcXineramaIsActive(ClientPtr client);
int xf86MergedFBProcXineramaQueryScreens(ClientPtr client);
int xf86MergedFBSProcXineramaDispatch(ClientPtr client);
*/

void xf86MergedFBFreeInfoRec(ScrnInfoPtr pScrn, MergedFBInfoPtr info);

DisplayModePtr
xf86MergedFBGenerateModeList(ScrnInfoPtr pScrn, MergedFBInfoPtr info, 
		    char* str, DisplayModePtr i, DisplayModePtr j,
		    MergedFBScrn2Rel srel);
void
xf86MergedFBXineramaExtensionInit(ScrnInfoPtr pScrn, MergedFBInfoPtr info);
void
xf86MergedFBMergePointerMovedHelper(int scrnIndex, MergedFBInfoPtr info, 
		    int x, int y);
void
xf86MergedFBAdjustFrameMergedHelper(int scrnIndex, MergedFBInfoPtr info, 
		    int x, int y, int flags);
ScrnInfoPtr xf86MergedFBGetCRT2ScrnPtr(MergedFBInfoPtr info);
MergedFBScrn2Rel xf86MergedFBGetCRT2Position(MergedFBInfoPtr info);


#endif  /* _XF86MERGEDFB_H_ */

