Merge commit 'dec0d4ec4153bf9fc2b78ae6c2df45b6ea8dde7a' as 'external/sdl/SDL'

This commit is contained in:
2023-07-25 22:27:55 +02:00
1663 changed files with 627495 additions and 0 deletions

View File

@@ -0,0 +1,194 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.h"
#ifdef SDL_VIDEO_DRIVER_NGAGE
/* Being a ngage driver, there's no event stream. We just define stubs for
most of the API. */
#ifdef __cplusplus
extern "C" {
#endif
#include "../../events/SDL_events_c.h"
#include "../../events/SDL_keyboard_c.h"
#ifdef __cplusplus
}
#endif
#include "SDL_ngagevideo.h"
#include "SDL_ngageevents_c.h"
int HandleWsEvent(SDL_VideoDevice *_this, const TWsEvent &aWsEvent);
void NGAGE_PumpEvents(SDL_VideoDevice *_this)
{
SDL_VideoData *phdata = _this->driverdata;
while (phdata->NGAGE_WsEventStatus != KRequestPending) {
phdata->NGAGE_WsSession.GetEvent(phdata->NGAGE_WsEvent);
HandleWsEvent(_this, phdata->NGAGE_WsEvent);
phdata->NGAGE_WsEventStatus = KRequestPending;
phdata->NGAGE_WsSession.EventReady(&phdata->NGAGE_WsEventStatus);
}
}
/*****************************************************************************/
/* Internal */
/*****************************************************************************/
#include <bautils.h>
#include <hal.h>
extern void DisableKeyBlocking(SDL_VideoDevice *_this);
extern void RedrawWindowL(SDL_VideoDevice *_this);
TBool isCursorVisible = EFalse;
static SDL_Scancode ConvertScancode(SDL_VideoDevice *_this, int key)
{
SDL_Keycode keycode;
switch (key) {
case EStdKeyBackspace: // Clear key
keycode = SDLK_BACKSPACE;
break;
case 0x31: // 1
keycode = SDLK_1;
break;
case 0x32: // 2
keycode = SDLK_2;
break;
case 0x33: // 3
keycode = SDLK_3;
break;
case 0x34: // 4
keycode = SDLK_4;
break;
case 0x35: // 5
keycode = SDLK_5;
break;
case 0x36: // 6
keycode = SDLK_6;
break;
case 0x37: // 7
keycode = SDLK_7;
break;
case 0x38: // 8
keycode = SDLK_8;
break;
case 0x39: // 9
keycode = SDLK_9;
break;
case 0x30: // 0
keycode = SDLK_0;
break;
case 0x2a: // Asterisk
keycode = SDLK_ASTERISK;
break;
case EStdKeyHash: // Hash
keycode = SDLK_HASH;
break;
case EStdKeyDevice0: // Left softkey
keycode = SDLK_SOFTLEFT;
break;
case EStdKeyDevice1: // Right softkey
keycode = SDLK_SOFTRIGHT;
break;
case EStdKeyApplication0: // Call softkey
keycode = SDLK_CALL;
break;
case EStdKeyApplication1: // End call softkey
keycode = SDLK_ENDCALL;
break;
case EStdKeyDevice3: // Middle softkey
keycode = SDLK_SELECT;
break;
case EStdKeyUpArrow: // Up arrow
keycode = SDLK_UP;
break;
case EStdKeyDownArrow: // Down arrow
keycode = SDLK_DOWN;
break;
case EStdKeyLeftArrow: // Left arrow
keycode = SDLK_LEFT;
break;
case EStdKeyRightArrow: // Right arrow
keycode = SDLK_RIGHT;
break;
default:
keycode = SDLK_UNKNOWN;
break;
}
return SDL_GetScancodeFromKey(keycode);
}
int HandleWsEvent(SDL_VideoDevice *_this, const TWsEvent &aWsEvent)
{
SDL_VideoData *phdata = _this->driverdata;
int posted = 0;
switch (aWsEvent.Type()) {
case EEventKeyDown: /* Key events */
SDL_SendKeyboardKey(0, SDL_PRESSED, ConvertScancode(_this, aWsEvent.Key()->iScanCode));
break;
case EEventKeyUp: /* Key events */
SDL_SendKeyboardKey(0, SDL_RELEASED, ConvertScancode(_this, aWsEvent.Key()->iScanCode));
break;
case EEventFocusGained: /* SDL window got focus */
phdata->NGAGE_IsWindowFocused = ETrue;
/* Draw window background and screen buffer */
DisableKeyBlocking(_this);
RedrawWindowL(_this);
break;
case EEventFocusLost: /* SDL window lost focus */
{
phdata->NGAGE_IsWindowFocused = EFalse;
RWsSession s;
s.Connect();
RWindowGroup g(s);
g.Construct(TUint32(&g), EFalse);
g.EnableReceiptOfFocus(EFalse);
RWindow w(s);
w.Construct(g, TUint32(&w));
w.SetExtent(TPoint(0, 0), phdata->NGAGE_WsWindow.Size());
w.SetOrdinalPosition(0);
w.Activate();
w.Close();
g.Close();
s.Close();
break;
}
case EEventModifiersChanged:
break;
default:
break;
}
return posted;
}
#endif /* SDL_VIDEO_DRIVER_NGAGE */

View File

@@ -0,0 +1,26 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.h"
#include "SDL_ngagevideo.h"
extern void NGAGE_PumpEvents(SDL_VideoDevice *_this);

View File

@@ -0,0 +1,397 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.h"
#ifdef SDL_VIDEO_DRIVER_NGAGE
#include <SDL.h>
#include "../SDL_sysvideo.h"
#include "SDL_ngagevideo.h"
#include "SDL_ngageframebuffer_c.h"
#define NGAGE_SURFACE "NGAGE_FrameBuffer"
/* For 12 bit screen HW. Table for fast conversion from 8 bit to 12 bit
*
* TUint16 is enough, but using TUint32 so we can use better instruction
* selection on ARMI.
*/
static TUint32 NGAGE_HWPalette_256_to_Screen[256];
int GetBpp(TDisplayMode displaymode);
void DirectUpdate(SDL_VideoDevice *_this, int numrects, SDL_Rect *rects);
void DrawBackground(SDL_VideoDevice *_this);
void DirectDraw(SDL_VideoDevice *_this, int numrects, SDL_Rect *rects, TUint16 *screenBuffer);
void RedrawWindowL(SDL_VideoDevice *_this);
int SDL_NGAGE_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, Uint32 *format, void **pixels, int *pitch)
{
SDL_VideoData *phdata = _this->driverdata;
SDL_Surface *surface;
const Uint32 surface_format = SDL_PIXELFORMAT_RGB444;
int w, h;
/* Free the old framebuffer surface */
SDL_NGAGE_DestroyWindowFramebuffer(_this, window);
/* Create a new one */
SDL_GetWindowSizeInPixels(window, &w, &h);
surface = SDL_CreateSurface(w, h, surface_format);
if (surface == NULL) {
return -1;
}
/* Save the info and return! */
SDL_SetWindowData(window, NGAGE_SURFACE, surface);
*format = surface_format;
*pixels = surface->pixels;
*pitch = surface->pitch;
/* Initialise Epoc frame buffer */
TDisplayMode displayMode = phdata->NGAGE_WsScreen->DisplayMode();
TScreenInfoV01 screenInfo;
TPckg<TScreenInfoV01> sInfo(screenInfo);
UserSvr::ScreenInfo(sInfo);
phdata->NGAGE_ScreenSize = screenInfo.iScreenSize;
phdata->NGAGE_DisplayMode = displayMode;
phdata->NGAGE_HasFrameBuffer = screenInfo.iScreenAddressValid;
phdata->NGAGE_FrameBuffer = phdata->NGAGE_HasFrameBuffer ? (TUint8 *)screenInfo.iScreenAddress : NULL;
phdata->NGAGE_BytesPerPixel = ((GetBpp(displayMode) - 1) / 8) + 1;
phdata->NGAGE_BytesPerScanLine = screenInfo.iScreenSize.iWidth * phdata->NGAGE_BytesPerPixel;
phdata->NGAGE_BytesPerScreen = phdata->NGAGE_BytesPerScanLine * phdata->NGAGE_ScreenSize.iHeight;
SDL_Log("Screen width %d", screenInfo.iScreenSize.iWidth);
SDL_Log("Screen height %d", screenInfo.iScreenSize.iHeight);
SDL_Log("Screen dmode %d", displayMode);
SDL_Log("Screen valid %d", screenInfo.iScreenAddressValid);
SDL_Log("Bytes per pixel %d", phdata->NGAGE_BytesPerPixel);
SDL_Log("Bytes per scan line %d", phdata->NGAGE_BytesPerScanLine);
SDL_Log("Bytes per screen %d", phdata->NGAGE_BytesPerScreen);
/* It seems that in SA1100 machines for 8bpp displays there is a 512
* palette table at the beginning of the frame buffer.
*
* In 12 bpp machines the table has 16 entries.
*/
if (phdata->NGAGE_HasFrameBuffer && GetBpp(displayMode) == 8) {
phdata->NGAGE_FrameBuffer += 512;
} else {
phdata->NGAGE_FrameBuffer += 32;
}
#if 0
if (phdata->NGAGE_HasFrameBuffer && GetBpp(displayMode) == 12) {
phdata->NGAGE_FrameBuffer += 16 * 2;
}
if (phdata->NGAGE_HasFrameBuffer && GetBpp(displayMode) == 16) {
phdata->NGAGE_FrameBuffer += 16 * 2;
}
#endif
// Get draw device for updating the screen
TScreenInfoV01 screenInfo2;
NGAGE_Runtime::GetScreenInfo(screenInfo2);
TRAPD(status, phdata->NGAGE_DrawDevice = CFbsDrawDevice::NewScreenDeviceL(screenInfo2, displayMode));
User::LeaveIfError(status);
/* Activate events for me */
phdata->NGAGE_WsEventStatus = KRequestPending;
phdata->NGAGE_WsSession.EventReady(&phdata->NGAGE_WsEventStatus);
SDL_Log("SDL:WsEventStatus");
User::WaitForRequest(phdata->NGAGE_WsEventStatus);
phdata->NGAGE_RedrawEventStatus = KRequestPending;
phdata->NGAGE_WsSession.RedrawReady(&phdata->NGAGE_RedrawEventStatus);
SDL_Log("SDL:RedrawEventStatus");
User::WaitForRequest(phdata->NGAGE_RedrawEventStatus);
phdata->NGAGE_WsWindow.PointerFilter(EPointerFilterDrag, 0);
phdata->NGAGE_ScreenOffset = TPoint(0, 0);
SDL_Log("SDL:DrawBackground");
DrawBackground(_this); // Clear screen
return 0;
}
int SDL_NGAGE_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects)
{
static int frame_number;
SDL_Surface *surface;
surface = (SDL_Surface *)SDL_GetWindowData(window, NGAGE_SURFACE);
if (surface == NULL) {
return SDL_SetError("Couldn't find ngage surface for window");
}
/* Send the data to the display */
if (SDL_getenv("SDL_VIDEO_NGAGE_SAVE_FRAMES")) {
char file[128];
SDL_snprintf(file, sizeof(file), "SDL_window%d-%8.8d.bmp",
(int)SDL_GetWindowID(window), ++frame_number);
SDL_SaveBMP(surface, file);
}
DirectUpdate(_this, numrects, (SDL_Rect *)rects);
return 0;
}
void SDL_NGAGE_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window)
{
SDL_Surface *surface;
surface = (SDL_Surface *)SDL_SetWindowData(window, NGAGE_SURFACE, NULL);
SDL_DestroySurface(surface);
}
/*****************************************************************************/
/* Runtime */
/*****************************************************************************/
#include <e32svr.h>
#include <hal_data.h>
#include <hal.h>
EXPORT_C void NGAGE_Runtime::GetScreenInfo(TScreenInfoV01 &screenInfo2)
{
TPckg<TScreenInfoV01> sInfo2(screenInfo2);
UserSvr::ScreenInfo(sInfo2);
}
/*****************************************************************************/
/* Internal */
/*****************************************************************************/
int GetBpp(TDisplayMode displaymode)
{
return TDisplayModeUtils::NumDisplayModeBitsPerPixel(displaymode);
}
void DrawBackground(SDL_VideoDevice *_this)
{
SDL_VideoData *phdata = _this->driverdata;
/* Draw background */
TUint16 *screenBuffer = (TUint16 *)phdata->NGAGE_FrameBuffer;
/* Draw black background */
Mem::FillZ(screenBuffer, phdata->NGAGE_BytesPerScreen);
}
void DirectDraw(SDL_VideoDevice *_this, int numrects, SDL_Rect *rects, TUint16 *screenBuffer)
{
SDL_VideoData *phdata = _this->driverdata;
SDL_Surface *screen = (SDL_Surface *)SDL_GetWindowData(_this->windows, NGAGE_SURFACE);
TInt i;
TDisplayMode displayMode = phdata->NGAGE_DisplayMode;
const TInt sourceNumBytesPerPixel = ((GetBpp(displayMode) - 1) / 8) + 1;
const TPoint fixedOffset = phdata->NGAGE_ScreenOffset;
const TInt screenW = screen->w;
const TInt screenH = screen->h;
const TInt sourceScanlineLength = screenW;
const TInt targetScanlineLength = phdata->NGAGE_ScreenSize.iWidth;
/* Render the rectangles in the list */
for (i = 0; i < numrects; ++i) {
const SDL_Rect &currentRect = rects[i];
SDL_Rect rect2;
rect2.x = currentRect.x;
rect2.y = currentRect.y;
rect2.w = currentRect.w;
rect2.h = currentRect.h;
if (rect2.w <= 0 || rect2.h <= 0) /* Sanity check */ {
continue;
}
/* All variables are measured in pixels */
/* Check rects validity, i.e. upper and lower bounds */
TInt maxX = Min(screenW - 1, rect2.x + rect2.w - 1);
TInt maxY = Min(screenH - 1, rect2.y + rect2.h - 1);
if (maxX < 0 || maxY < 0) /* sanity check */ {
continue;
}
/* Clip from bottom */
maxY = Min(maxY, phdata->NGAGE_ScreenSize.iHeight - 1);
/* TODO: Clip from the right side */
const TInt sourceRectWidth = maxX - rect2.x + 1;
const TInt sourceRectWidthInBytes = sourceRectWidth * sourceNumBytesPerPixel;
const TInt sourceRectHeight = maxY - rect2.y + 1;
const TInt sourceStartOffset = rect2.x + rect2.y * sourceScanlineLength;
const TUint skipValue = 1; /* 1 = No skip */
TInt targetStartOffset = fixedOffset.iX + rect2.x + (fixedOffset.iY + rect2.y) * targetScanlineLength;
switch (screen->format->BitsPerPixel) {
case 12:
{
TUint16 *bitmapLine = (TUint16 *)screen->pixels + sourceStartOffset;
TUint16 *screenMemory = screenBuffer + targetStartOffset;
if (skipValue == 1) {
for (TInt y = 0; y < sourceRectHeight; y++) {
Mem::Copy(screenMemory, bitmapLine, sourceRectWidthInBytes);
bitmapLine += sourceScanlineLength;
screenMemory += targetScanlineLength;
}
} else {
for (TInt y = 0; y < sourceRectHeight; y++) {
TUint16 *bitmapPos = bitmapLine; /* 2 bytes per pixel */
TUint16 *screenMemoryLinePos = screenMemory; /* 2 bytes per pixel */
for (TInt x = 0; x < sourceRectWidth; x++) {
__ASSERT_DEBUG(screenMemory < (screenBuffer + phdata->NGAGE_ScreenSize.iWidth * phdata->NGAGE_ScreenSize.iHeight), User::Panic(_L("SDL"), KErrCorrupt));
__ASSERT_DEBUG(screenMemory >= screenBuffer, User::Panic(_L("SDL"), KErrCorrupt));
__ASSERT_DEBUG(bitmapLine < ((TUint16 *)screen->pixels + (screen->w * screen->h)), User::Panic(_L("SDL"), KErrCorrupt));
__ASSERT_DEBUG(bitmapLine >= (TUint16 *)screen->pixels, User::Panic(_L("SDL"), KErrCorrupt));
*screenMemoryLinePos++ = *bitmapPos;
bitmapPos += skipValue;
}
bitmapLine += sourceScanlineLength;
screenMemory += targetScanlineLength;
}
}
} break;
// 256 color paletted mode: 8 bpp --> 12 bpp
default:
{
if (phdata->NGAGE_BytesPerPixel <= 2) {
TUint8 *bitmapLine = (TUint8 *)screen->pixels + sourceStartOffset;
TUint16 *screenMemory = screenBuffer + targetStartOffset;
for (TInt y = 0; y < sourceRectHeight; y++) {
TUint8 *bitmapPos = bitmapLine; /* 1 byte per pixel */
TUint16 *screenMemoryLinePos = screenMemory; /* 2 bytes per pixel */
/* Convert each pixel from 256 palette to 4k color values */
for (TInt x = 0; x < sourceRectWidth; x++) {
__ASSERT_DEBUG(screenMemoryLinePos < (screenBuffer + (phdata->NGAGE_ScreenSize.iWidth * phdata->NGAGE_ScreenSize.iHeight)), User::Panic(_L("SDL"), KErrCorrupt));
__ASSERT_DEBUG(screenMemoryLinePos >= screenBuffer, User::Panic(_L("SDL"), KErrCorrupt));
__ASSERT_DEBUG(bitmapPos < ((TUint8 *)screen->pixels + (screen->w * screen->h)), User::Panic(_L("SDL"), KErrCorrupt));
__ASSERT_DEBUG(bitmapPos >= (TUint8 *)screen->pixels, User::Panic(_L("SDL"), KErrCorrupt));
*screenMemoryLinePos++ = NGAGE_HWPalette_256_to_Screen[*bitmapPos++];
}
bitmapLine += sourceScanlineLength;
screenMemory += targetScanlineLength;
}
} else {
TUint8 *bitmapLine = (TUint8 *)screen->pixels + sourceStartOffset;
TUint32 *screenMemory = reinterpret_cast<TUint32 *>(screenBuffer + targetStartOffset);
for (TInt y = 0; y < sourceRectHeight; y++) {
TUint8 *bitmapPos = bitmapLine; /* 1 byte per pixel */
TUint32 *screenMemoryLinePos = screenMemory; /* 2 bytes per pixel */
/* Convert each pixel from 256 palette to 4k color values */
for (TInt x = 0; x < sourceRectWidth; x++) {
__ASSERT_DEBUG(screenMemoryLinePos < (reinterpret_cast<TUint32 *>(screenBuffer) + (phdata->NGAGE_ScreenSize.iWidth * phdata->NGAGE_ScreenSize.iHeight)), User::Panic(_L("SDL"), KErrCorrupt));
__ASSERT_DEBUG(screenMemoryLinePos >= reinterpret_cast<TUint32 *>(screenBuffer), User::Panic(_L("SDL"), KErrCorrupt));
__ASSERT_DEBUG(bitmapPos < ((TUint8 *)screen->pixels + (screen->w * screen->h)), User::Panic(_L("SDL"), KErrCorrupt));
__ASSERT_DEBUG(bitmapPos >= (TUint8 *)screen->pixels, User::Panic(_L("SDL"), KErrCorrupt));
*screenMemoryLinePos++ = NGAGE_HWPalette_256_to_Screen[*bitmapPos++];
}
bitmapLine += sourceScanlineLength;
screenMemory += targetScanlineLength;
}
}
}
}
}
}
void DirectUpdate(SDL_VideoDevice *_this, int numrects, SDL_Rect *rects)
{
SDL_VideoData *phdata = _this->driverdata;
if (!phdata->NGAGE_IsWindowFocused) {
SDL_PauseAudio(1);
SDL_Delay(1000);
return;
}
SDL_PauseAudio(0);
TUint16 *screenBuffer = (TUint16 *)phdata->NGAGE_FrameBuffer;
#if 0
if (phdata->NGAGE_ScreenOrientation == CFbsBitGc::EGraphicsOrientationRotated270) {
// ...
} else
#endif
{
DirectDraw(_this, numrects, rects, screenBuffer);
}
for (int i = 0; i < numrects; ++i) {
TInt aAx = rects[i].x;
TInt aAy = rects[i].y;
TInt aBx = rects[i].w;
TInt aBy = rects[i].h;
TRect rect2 = TRect(aAx, aAy, aBx, aBy);
phdata->NGAGE_DrawDevice->UpdateRegion(rect2); /* Should we update rects parameter area only? */
phdata->NGAGE_DrawDevice->Update();
}
}
void RedrawWindowL(SDL_VideoDevice *_this)
{
SDL_VideoData *phdata = _this->driverdata;
SDL_Surface *screen = (SDL_Surface *)SDL_GetWindowData(_this->windows, NGAGE_SURFACE);
int w = screen->w;
int h = screen->h;
if (phdata->NGAGE_ScreenOrientation == CFbsBitGc::EGraphicsOrientationRotated270) {
w = screen->h;
h = screen->w;
}
if ((w < phdata->NGAGE_ScreenSize.iWidth) || (h < phdata->NGAGE_ScreenSize.iHeight)) {
DrawBackground(_this);
}
/* Tell the system that something has been drawn */
TRect rect = TRect(phdata->NGAGE_WsWindow.Size());
phdata->NGAGE_WsWindow.Invalidate(rect);
/* Draw current buffer */
SDL_Rect fullScreen;
fullScreen.x = 0;
fullScreen.y = 0;
fullScreen.w = screen->w;
fullScreen.h = screen->h;
DirectUpdate(_this, 1, &fullScreen);
}
#endif /* SDL_VIDEO_DRIVER_NGAGE */

View File

@@ -0,0 +1,36 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.h"
extern int SDL_NGAGE_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, Uint32 *format, void **pixels, int *pitch);
extern int SDL_NGAGE_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects);
extern void SDL_NGAGE_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window);
/****************************************************************************/
/* Runtime */
/****************************************************************************/
class NGAGE_Runtime
{
public:
IMPORT_C static void GetScreenInfo(TScreenInfoV01 &screenInfo2);
};

View File

@@ -0,0 +1,165 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include <stdlib.h>
#ifdef NULL
#undef NULL
#endif
#include "SDL_internal.h"
#ifdef SDL_VIDEO_DRIVER_NGAGE
#ifdef __cplusplus
extern "C" {
#endif
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
#ifdef __cplusplus
}
#endif
#include "SDL_ngagevideo.h"
#include "SDL_ngagewindow.h"
#include "SDL_ngageevents_c.h"
#include "SDL_ngageframebuffer_c.h"
#define NGAGEVID_DRIVER_NAME "ngage"
/* Initialization/Query functions */
static int NGAGE_VideoInit(SDL_VideoDevice *_this);
static void NGAGE_VideoQuit(SDL_VideoDevice *_this);
/* NGAGE driver bootstrap functions */
static void NGAGE_DeleteDevice(SDL_VideoDevice *device)
{
SDL_VideoData *phdata = device->driverdata;
if (phdata) {
/* Free Epoc resources */
/* Disable events for me */
if (phdata->NGAGE_WsEventStatus != KRequestPending) {
phdata->NGAGE_WsSession.EventReadyCancel();
}
if (phdata->NGAGE_RedrawEventStatus != KRequestPending) {
phdata->NGAGE_WsSession.RedrawReadyCancel();
}
free(phdata->NGAGE_DrawDevice); /* This should NOT be SDL_free() */
if (phdata->NGAGE_WsWindow.WsHandle()) {
phdata->NGAGE_WsWindow.Close();
}
if (phdata->NGAGE_WsWindowGroup.WsHandle()) {
phdata->NGAGE_WsWindowGroup.Close();
}
delete phdata->NGAGE_WindowGc;
phdata->NGAGE_WindowGc = NULL;
delete phdata->NGAGE_WsScreen;
phdata->NGAGE_WsScreen = NULL;
if (phdata->NGAGE_WsSession.WsHandle()) {
phdata->NGAGE_WsSession.Close();
}
SDL_free(phdata);
phdata = NULL;
}
if (device) {
SDL_free(device);
device = NULL;
}
}
static SDL_VideoDevice *NGAGE_CreateDevice(void)
{
SDL_VideoDevice *device;
SDL_VideoData *phdata;
/* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice));
if (device == NULL) {
SDL_OutOfMemory();
return 0;
}
/* Initialize internal N-Gage specific data */
phdata = (SDL_VideoData *)SDL_calloc(1, sizeof(SDL_VideoData));
if (phdata == NULL) {
SDL_OutOfMemory();
SDL_free(device);
return 0;
}
/* General video */
device->VideoInit = NGAGE_VideoInit;
device->VideoQuit = NGAGE_VideoQuit;
device->PumpEvents = NGAGE_PumpEvents;
device->CreateWindowFramebuffer = SDL_NGAGE_CreateWindowFramebuffer;
device->UpdateWindowFramebuffer = SDL_NGAGE_UpdateWindowFramebuffer;
device->DestroyWindowFramebuffer = SDL_NGAGE_DestroyWindowFramebuffer;
device->free = NGAGE_DeleteDevice;
/* "Window" */
device->CreateSDLWindow = NGAGE_CreateWindow;
device->DestroyWindow = NGAGE_DestroyWindow;
/* N-Gage specific data */
device->driverdata = phdata;
return device;
}
VideoBootStrap NGAGE_bootstrap = {
NGAGEVID_DRIVER_NAME, "SDL ngage video driver",
NGAGE_CreateDevice
};
int NGAGE_VideoInit(SDL_VideoDevice *_this)
{
SDL_DisplayMode mode;
/* Use 12-bpp desktop mode */
SDL_zero(mode);
mode.format = SDL_PIXELFORMAT_RGB444;
mode.w = 176;
mode.h = 208;
if (SDL_AddBasicVideoDisplay(&mode) == 0) {
return -1;
}
/* We're done! */
return 0;
}
void NGAGE_VideoQuit(SDL_VideoDevice *_this)
{
}
#endif /* SDL_VIDEO_DRIVER_NGAGE */

View File

@@ -0,0 +1,66 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.h"
#ifndef SDL_ngagevideo_h
#define SDL_ngagevideo_h
#include "../SDL_sysvideo.h"
#include <e32std.h>
#include <e32svr.h>
#include <bitdev.h>
#include <w32std.h>
#include "bitdraw.h" // CFbsDrawDevice
#define SDL_VideoDevice *_this SDL_VideoDevice *_this
struct SDL_VideoData
{
/* Epoc window server info */
RWsSession NGAGE_WsSession;
RWindowGroup NGAGE_WsWindowGroup;
TInt NGAGE_WsWindowGroupID;
RWindow NGAGE_WsWindow;
CWsScreenDevice *NGAGE_WsScreen;
CWindowGc *NGAGE_WindowGc;
TRequestStatus NGAGE_WsEventStatus;
TRequestStatus NGAGE_RedrawEventStatus;
TWsEvent NGAGE_WsEvent;
CFbsDrawDevice *NGAGE_DrawDevice;
TBool NGAGE_IsWindowFocused; /* Not used yet */
/* Screen hardware frame buffer info */
TBool NGAGE_HasFrameBuffer;
TInt NGAGE_BytesPerPixel;
TInt NGAGE_BytesPerScanLine;
TInt NGAGE_BytesPerScreen;
TDisplayMode NGAGE_DisplayMode;
TSize NGAGE_ScreenSize;
TUint8 *NGAGE_FrameBuffer;
TPoint NGAGE_ScreenOffset;
CFbsBitGc::TGraphicsOrientation NGAGE_ScreenOrientation;
};
#endif /* SDL_ngagevideo_h */

View File

@@ -0,0 +1,125 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.h"
#ifdef SDL_VIDEO_DRIVER_NGAGE
#include "../SDL_sysvideo.h"
#include "SDL_ngagewindow.h"
const TUint32 WindowClientHandle = 9210;
void DisableKeyBlocking(SDL_VideoDevice *_this);
void ConstructWindowL(SDL_VideoDevice *_this);
int NGAGE_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
{
NGAGE_Window *ngage_window = (NGAGE_Window *)SDL_calloc(1, sizeof(NGAGE_Window));
if (ngage_window == NULL) {
return SDL_OutOfMemory();
}
window->driverdata = ngage_window;
if (window->x == SDL_WINDOWPOS_UNDEFINED) {
window->x = 0;
}
if (window->y == SDL_WINDOWPOS_UNDEFINED) {
window->y = 0;
}
ngage_window->sdl_window = window;
ConstructWindowL(_this);
return 0;
}
void NGAGE_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
{
NGAGE_Window *ngage_window = (NGAGE_Window *)window->driverdata;
if (ngage_window) {
SDL_free(ngage_window);
}
window->driverdata = NULL;
}
/*****************************************************************************/
/* Internal */
/*****************************************************************************/
void DisableKeyBlocking(SDL_VideoDevice *_this)
{
SDL_VideoData *phdata = _this->driverdata;
TRawEvent event;
event.Set((TRawEvent::TType) /*EDisableKeyBlock*/ 51);
phdata->NGAGE_WsSession.SimulateRawEvent(event);
}
void ConstructWindowL(SDL_VideoDevice *_this)
{
SDL_VideoData *phdata = _this->driverdata;
TInt error;
error = phdata->NGAGE_WsSession.Connect();
User::LeaveIfError(error);
phdata->NGAGE_WsScreen = new (ELeave) CWsScreenDevice(phdata->NGAGE_WsSession);
User::LeaveIfError(phdata->NGAGE_WsScreen->Construct());
User::LeaveIfError(phdata->NGAGE_WsScreen->CreateContext(phdata->NGAGE_WindowGc));
phdata->NGAGE_WsWindowGroup = RWindowGroup(phdata->NGAGE_WsSession);
User::LeaveIfError(phdata->NGAGE_WsWindowGroup.Construct(WindowClientHandle));
phdata->NGAGE_WsWindowGroup.SetOrdinalPosition(0);
RProcess thisProcess;
TParse exeName;
exeName.Set(thisProcess.FileName(), NULL, NULL);
TBuf<32> winGroupName;
winGroupName.Append(0);
winGroupName.Append(0);
winGroupName.Append(0); // UID
winGroupName.Append(0);
winGroupName.Append(exeName.Name()); // Caption
winGroupName.Append(0);
winGroupName.Append(0); // DOC name
phdata->NGAGE_WsWindowGroup.SetName(winGroupName);
phdata->NGAGE_WsWindow = RWindow(phdata->NGAGE_WsSession);
User::LeaveIfError(phdata->NGAGE_WsWindow.Construct(phdata->NGAGE_WsWindowGroup, WindowClientHandle - 1));
phdata->NGAGE_WsWindow.SetBackgroundColor(KRgbWhite);
phdata->NGAGE_WsWindow.Activate();
phdata->NGAGE_WsWindow.SetSize(phdata->NGAGE_WsScreen->SizeInPixels());
phdata->NGAGE_WsWindow.SetVisible(ETrue);
phdata->NGAGE_WsWindowGroupID = phdata->NGAGE_WsWindowGroup.Identifier();
phdata->NGAGE_IsWindowFocused = EFalse;
DisableKeyBlocking(_this);
}
#endif /* SDL_VIDEO_DRIVER_NGAGE */

View File

@@ -0,0 +1,43 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef SDL_ngagewindow_h
#define SDL_ngagewindow_h
#include "../SDL_sysvideo.h"
#include <SDL3/SDL_syswm.h>
#include "SDL_ngagevideo.h"
typedef struct
{
SDL_Window *sdl_window;
} NGAGE_Window;
extern int
NGAGE_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern void
NGAGE_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window);
#endif /* SDL_ngagewindow */