⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wince_ws.c

📁 Lido PXA270平台开发板的最新BSP,包括源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/**************************************************************************
 Name         : wince_ws.c
 Title        : Wince Window system implementatoin
 Author       : PowerVR
 Created      : December 2003

 Copyright    : 2003 by Imaginationc Technologies Limited. All rights reserved.
              : No part of this software, either material or conceptual 
              : may be copied or distributed, transmitted, transcribed,
              : stored in a retrieval system or translated into any 
              : human or computer language in any form by any means,
              : electronic, mechanical, manual or other-wise, or 
              : disclosed to third parties without the express written
              : permission of Imagination Technologies Limited, Unit 8, HomePark
              : Industrial Estate, King's Langley, Hertfordshire,
              : WD4 8LZ, U.K.

 Description  : Wince Window system implementation

 Platform     : WinCE
 Version	  : $Revision: 1.52 $
 Modifications	: 
 $Log: wince_ws.c $
*******************************************************************************/
#define MODULE_ID MODID_WINCEWS

#ifdef KHRONOSEGL
#include <windows.h>

#include "cfg-core.h"
#include "ogles_types.h"
#include "servicesglue.h"
#include "ws.h"
#include "wsglue.h"
#include "eglglue.h"
#include "osglue.h"
#include "egl_internal.h"
#include "drvegl.h"
#include "srv.h"
#include "mbx12ddef.h"
#include "tls.h"
#include "modid.h"
#include "debug.h"
#include "drvescape.h"
#include "pvrdispconfig.h"
#include "misc.h"


/* Local Function Declarations */

ATOM MyRegisterClass(HINSTANCE hInstance);
LRESULT CALLBACK ShadowWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
IMG_UINT32 SetupShadowWindow(KEGL_SURFACE *surface);

void RotateWindowCoordinates(struct ws_native_window_tag *psWindow);
LRESULT CALLBACK	KEGLWndProc(HWND hWnd , UINT Msg, WPARAM wParam, LPARAM lParam);
IMG_BOOL DoClipping (NativeWindowType NativeWindow,KEGL_SURFACE *psSurface);
PWSREGION SubtractRects(PWSREGION psRegion, WSRECT *psRect);
PWSREGION CreateRect(WSRECT *psRect, PWSREGION psNext);
void FreeRegions(PWSREGION psRegion);
BOOL RegionsIdentical(PWSREGION psRegionA, PWSREGION psRegionB);
IMG_BOOL DoBlit (PVRSRV_QUEUE_INFO *psQueue,PVRSRV_SURF *psSrc,PVRSRV_SURF *psDest,IMG_INT32 srcXpos,IMG_INT32 srcYpos,IMG_INT32 Width, IMG_INT32 Height,IMG_INT32 DestXpos,IMG_INT32 DestYpos);
IMG_BOOL DoClippedBlits(PVRSRV_SURF sDestSurface, KEGL_SURFACE *psSourceSurface);
PLISTITEM CreateListItem(IMG_UINT32 ui32Item, PLISTITEM psNext);
void FreeItems(PLISTITEM psItem);

IMG_BOOL IsSecondaryExternalFullScreen();
IMG_UINT32 GetExternalRotationAngle();

/*   Function defined in Khronos_egl.c */
extern KEGL_SURFACE * _FindWindowSurface (KEGL_DISPLAY *pDpy, NativeWindowType window);


#define BETWEEN(a,b,c) ((a<=b)&&(b<=c))


#define MBX1_MINIMUM_RENDER_TARGET_ALIGNMENT	(4096)

/*
<function>
   FUNCTION:   WS_GetDisplayCount ()
   PURPOSE:    Query the number of displays provided by the window system.
   PARAMETERS: None.
   RETURNS:    Number of displays.
</function>
 */
EGLint
WS_GetDisplayCount (void)
{
	return 1;
}

/*
<function>
   FUNCTION:   WS_GetDisplay ()
   PURPOSE:    Find the EGLDisplay from a NativeDisplayType.
   PARAMETERS: In:  nativeDpy - Native display handle.
   RETURNS:    EGL display associated with the native handle or NULL.
</function>
 */
EGLDisplay 
WS_GetDisplay (NativeDisplayType nativeDpy)
{
	return 1;
}

/*
<function>
   FUNCTION:   WS_Open ()
   PURPOSE:

   Open the window system for a specified display. The common EGL provides
   a base configuration for the window system to derive a set of supported
   configurations. 
   PARAMETERS: In:  dpy - EGL display.
               In:  base_cfg - Base configuration.
   RETURNS:    EGL_TRUE - Success.
               EGL_FALSE - Failure.
</function>
 */
EGLint
WS_Open (GLESSysContext *psService_context, KEGL_DISPLAY *dpy)
{
	PVRSRV_PRIMARY_SURF_INFO sPrimaryInfo;

	//assert(dpy!=IMG_NULL);
	dpy->ws.psService_context = psService_context;

	if(PVRSRVQueryPrimary(&psService_context->sDisplay, &sPrimaryInfo) != PVRSRV_OK)
		return EGL_BAD_ALLOC;

	if (PVRSRVAcquirePrimary (&psService_context->sDisplay, 
								PVRSRV_MEMFLG_RENDERABLE, 
								sPrimaryInfo.ui32PixelWidth, 
								sPrimaryInfo.ui32PixelHeight, 
								sPrimaryInfo.ePixelFormat,
								&dpy->ws.psPrimary_surface)!=PVRSRV_OK)
	{
		return EGL_BAD_ALLOC;
	}

	return EGL_SUCCESS;
}

/*
<function>
   FUNCTION:   WS_Close
   PURPOSE:    Close the window system for a specified display.
   PARAMETERS: In:  dpy - EGL display.
   RETURNS:    None
</function>
 */
void
WS_Close (KEGL_DISPLAY *dpy)
{
	MONITORINFO sMInfo;
	HMONITOR hMonitor;

	KEGL_SURFACE * psSurface;
	psSurface=dpy->pHeadSurface;
	// restore everyones WndProc
	while(psSurface)
	{
		if((psSurface->type==EGL_SURFACE_WINDOW)&&(psSurface->isDeleting))
		{	
			IMG_UINT32 ui32NumSurfaces = psSurface->u.window.ws.ui8BackBuffers + 1;
			IMG_UINT32 ui32CurrentDisplaySurface = 
				(psSurface->u.window.ws.ui32NextDisplaySurface + ui32NumSurfaces - 1) % ui32NumSurfaces;

			PVRSRVFlushQueue(psSurface->psQueueInfo);
			if(psSurface->u.window.ws.bFlipping)
			{
				if(ui32CurrentDisplaySurface != 0)
				{
					PVRSRVQueueFlip(psSurface->psQueueInfo,	psSurface->u.window.ws.apsSurfaces[0]->psSyncInfo,
						psSurface->u.window.ws.apsSurfaces[ui32CurrentDisplaySurface]->psSyncInfo,
						psSurface->u.window.ws.apsSurfaces[0], psSurface->u.window.ws.bLockToVsync,	1);

					psSurface->u.window.ws.ui32NextDisplaySurface=0;
					psSurface->u.window.ws.bFlipping=FALSE;
				}
			}
			SetWindowLong((HWND)psSurface->u.window.native,GWL_WNDPROC,(IMG_UINT32)psSurface->u.window.ws.WndProc);			
			if(psSurface->u.window.ws.hShadowWnd)
			{
				hMonitor= MonitorFromWindow(psSurface->u.window.ws.hShadowWnd,MONITOR_DEFAULTTOPRIMARY);

				sMInfo.cbSize=sizeof(sMInfo);
				GetMonitorInfo(hMonitor,  &sMInfo );
				SetWindowPos(psSurface->u.window.ws.hShadowWnd,HWND_TOP,sMInfo.rcMonitor.left,sMInfo.rcMonitor.top,sMInfo.rcMonitor.right-sMInfo.rcMonitor.left,sMInfo.rcMonitor.bottom-sMInfo.rcMonitor.top,SWP_NOACTIVATE);

				DestroyWindow(psSurface->u.window.ws.hShadowWnd);
				UnregisterClass(TEXT("ShadowWindow"),GetModuleHandle(NULL));
				psSurface->u.window.ws.hShadowWnd=NULL;
			}

		}
		psSurface=psSurface->pNextSurface;
	}

	PVRSRVReleasePrimary(&dpy->ws.psService_context->sDisplay, dpy->ws.psPrimary_surface);
}

/*
<function>
   FUNCTION:   WS_CfgVariants
   PURPOSE:

   Derive a specified configuration variant for a specified display
   based on a supplied generic EGL base configuration. The variant
   requested will be numbered 0..(N-1) where N is the number returned
   by the WS_CfgVariants function.

   The generic EGL component will provide a set of base configurations
   for the capabilities of OGL covering depth buffer and sample buffer
   variations. The window system interface is expected to augment
   these base configurations with specific values of ARGB and buffer
   size.

   PARAMETERS: In:  dpy - EGL display.
   RETURNS:    Number of configuration variants supported by the display.
</function>
 */
EGLint
WS_CfgVariants (KEGL_DISPLAY *dpy)
{
	return 1;
}

/*
<function>
   FUNCTION:   WS_CfgVariants
   PURPOSE:

   Derive a specified configuration variant for a specified display
   based on a supplied generic EGL base configuration. The variant
   requested will be numbered 0..(N-1) where N is the number returned
   by the WS_CfgVariants function.

   The generic EGL component will provide a set of base configurations
   for the capabilities of OGL covering depth buffer and sample buffer
   variations. The window system interface is expected to augment
   these base configurations with specific values of ARGB and buffer
   size.

   PARAMETERS: In:  dpy - EGL display.
   RETURNS:    Number of configuration variants supported by the display.
</function>
 */
KEGL_CONFIG *
	WS_DeriveCfg (KEGL_DISPLAY *dpy,
		KEGL_CONFIG *cfg,
		EGLint variant)
{
	//assert (dpy!=NULL);
	switch (variant)
	{
	case 0:
		{
			EGLint pf = dpy->ws.psPrimary_surface->ePixelFormat;
			cfg = CFGC_CopyNl (cfg);
			CFGC_SetAttrib (cfg, EGL_BUFFER_SIZE, SRV_pixel_format_width [pf]);
			CFGC_SetAttrib (cfg, EGL_ALPHA_SIZE, SRV_pixel_format_alpha [pf]);
			CFGC_SetAttrib (cfg, EGL_RED_SIZE, SRV_pixel_format_red [pf]);
			CFGC_SetAttrib (cfg, EGL_GREEN_SIZE, SRV_pixel_format_green [pf]);
			CFGC_SetAttrib (cfg, EGL_BLUE_SIZE, SRV_pixel_format_blue [pf]);
			return cfg;
		}
	default:
		return cfg;
		//assert (0);
	}
}


/*
<function>
   FUNCTION:   WS_WindowValid ()
   PURPOSE:    Query if a native window handle still represents a valid
               window.
   PARAMETERS: In:  window - Native window to test.
   RETURNS:    EGL_TRUE - Window is valid.
               EGL_FALSE - Window is not valid.
</function>
 */
EGLBoolean
WS_WindowValid (NativeWindowType window)
{
	return EGL_TRUE;
}
/*
<function>
   FUNCTION:   WS_ValidateDisplay ()
   PURPOSE:    Confirm that the native display type is valid and record native information
   PARAMETERS: In : hNativeDpy - Native display handle.
               In : pKEGLDisplay - The KEGL display structure corresponding to the native display
   RETURNS:    IMG_TRUE if the display is valid
</function>
 */

IMG_BOOL
WS_ValidateDisplay (NativeDisplayType hNativeDpy, KEGL_DISPLAY* pKEGLDisplay)
{
	return IMG_TRUE;
}

/*
<function>
   FUNCTION:   WS_MapEGLDisplay2WSDisplay
   PURPOSE:    Map the incoming NativeDpy to a value for use in the current windowing system
   PARAMETERS: In:  nativeDpy - Native display handle.
   RETURNS:    nativeDpy - remapped Native display handle.
</function>
 */
NativeDisplayType 
WS_MapEGLDisplay2WSDisplay (NativeDisplayType nativeDpy)
{
	return (NativeDisplayType)1;
}

/*
<function>
   FUNCTION:   WS_WaitNative
   PURPOSE:    Flush native rendering requests for window.
               Requests to wait on a native surface which has become invalid
               should return EGL_BAD_CURRENT_SURFACE.
   PARAMETERS: In:  window - window to flush
   RETURNS:    EGL_SUCCESS - Success.
               Other EGL error code.
</function>
 */
EGLint
WS_WaitNative (KEGL_SURFACE *surface, EGLint engine)
{
	//  trace ("ws  (egl->ws):  ws_wait_native (engine=0x%x)\n", engine);
	//assert (surface!=NULL);

	/* If the native surface has become invalid, report EGL_BAD_CURRENT_SURFACE,
	in the null driver this cannot happen. */
	if (0)
		return EGL_BAD_CURRENT_SURFACE;

	switch (engine)
	{
	case EGL_CORE_NATIVE_ENGINE:
		break;
	default:
		return EGL_BAD_PARAMETER;
	}

	return EGL_SUCCESS;
}

/*
<function>
   FUNCTION:   WS_CompareNativeVisualType ()

   PURPOSE:    

   The generic K-EGL component must be able to sort configs. The K-EGL
   specification permits the window system interface to define the
   sort order for native visual types if they are
   used. Implementations which do not support native visual types
   should return: 0 i.e. (a == b).

   PARAMETERS: 
   
   RETURNS:    
     0 :: a == b
    <0 :: a < b
    >0 :: a > b
</function>
 */
EGLint
WS_CompareNativeVisualType (EGLint a, EGLint b)
{
	/* The default implementation does not have native visual types, therefore
	comarison alway yields "==" */
	return 0;
}

/*
   <function>
   FUNCTION   : WS_CreateWindowDrawable

   PURPOSE    :

   Validate and create a drawable from native window. Must validate the
   native window against the surface configuration.

   PARAMETERS :
     In:  servicesContext - Services context.
     In:  dpy - Display.
     In:  surface - Surface.
     In:  window - Native window.
     
   RETURNS    :
     EGL_SUCCESS: pixmap conforms to config.
     EGL_BAD_NATIVE_PIXMAP: invalid pixmap handle.
     EGL_BAD_MATCH: pixmap does not conform to specified config.
   </function>
 */
EGLint
WS_CreateWindowDrawable (KEGL_DISPLAY *dpy,
	KEGL_SURFACE *surface,
	NativeWindowType nativeWindow)
{
	POINT pt;
	RECT rc;
	HWND hWnd;
	GLESAppHints sAppHints;
 	PVRSRV_SURF *psCurrentRenderSurface = &surface->sCurrentRenderSurface;

	hWnd=(HWND)nativeWindow;

	surface->u.window.ws.psPrimary_surface	 = 		dpy->ws.psPrimary_surface;
	psCurrentRenderSurface->ui32PixelWidth 	 =		dpy->ws.psPrimary_surface->ui32PixelWidth;
	psCurrentRenderSurface->ui32PixelHeight  =		dpy->ws.psPrimary_surface->ui32PixelHeight;
	psCurrentRenderSurface->ePixelFormat 	 =		dpy->ws.psPrimary_surface->ePixelFormat;
	psCurrentRenderSurface->ui32ByteStride 	 =		dpy->ws.psPrimary_surface->ui32ByteStride;
	surface->u.window.ws.WndProc=GetWindowLong(nativeWindow,  GWL_WNDPROC);
	surface->u.window.ws.psClippedBlits  = 		NULL;
	surface->u.window.ws.psOverlappingRects = 		NULL;
	surface->u.window.ws.bPosChanged=FALSE;
	surface->u.window.ws.psOverlappedWindowList=NULL;
	surface->u.window.ws.hShadowWnd=NULL;
	surface->u.window.ws.bSecondaryExternalFullScreen=IsSecondaryExternalFullScreen();

	surface->u.window.ws.ui8BackBuffers=2;

	if(surface->u.window.ws.bSecondaryExternalFullScreen)
	{
		surface->u.window.ws.ui32RotationAngle=GetExternalRotationAngle();
	}
	else
	{
		surface->u.window.ws.ui32RotationAngle=GetRotationAngle();
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -