1 /*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "../../SDL_internal.h"
22
23 #if SDL_VIDEO_DRIVER_ALIOS
24
25 /* Dummy SDL video driver implementation; this is just enough to make an
26 * SDL-based application THINK it's got a working video driver, for
27 * applications that call SDL_Init(SDL_INIT_VIDEO) when they don't need it,
28 * and also for use as a collection of stubs when porting SDL to a new
29 * platform for which you haven't yet written a valid video driver.
30 *
31 * This is also a great way to determine bottlenecks: if you think that SDL
32 * is a performance problem for a given platform, enable this driver, and
33 * then see if your application runs faster without video overhead.
34 *
35 * Initial work by Ryan C. Gordon (icculus@icculus.org). A good portion
36 * of this was cut-and-pasted from Stephane Peter's work in the AAlib
37 * SDL video driver. Renamed to "AliOS" by Sam Lantinga.
38 */
39
40 #include "SDL_video.h"
41 #include "SDL_mouse.h"
42 #include "../SDL_sysvideo.h"
43 #include "../SDL_pixels_c.h"
44 #include "../../events/SDL_events_c.h"
45
46 #include "SDL_AliOS_video.h"
47 #include "SDL_AliOS_events_c.h"
48 #include "SDL_AliOS_framebuffer_c.h"
49
50 #define ALIOSVID_DRIVER_NAME "alios"
51
52 /* Initialization/Query functions */
53 static int AliOS_VideoInit(_THIS);
54 static int AliOS_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
55 static void AliOS_VideoQuit(_THIS);
56
57 /* AliOS driver bootstrap functions */
58
59 static int
AliOS_Available(void)60 AliOS_Available(void)
61 {
62 #ifdef __ALIOS__
63 return (1);
64 #else
65 const char *envr = SDL_getenv("SDL_VIDEODRIVER");
66 if ((envr) && (SDL_strcmp(envr, ALIOSVID_DRIVER_NAME) == 0)) {
67 return (1);
68 }
69
70 return (0);
71 #endif
72 }
73
74 static void
AliOS_DeleteDevice(SDL_VideoDevice * device)75 AliOS_DeleteDevice(SDL_VideoDevice * device)
76 {
77 SDL_free(device);
78 }
79
80 static SDL_VideoDevice *
AliOS_CreateDevice(int devindex)81 AliOS_CreateDevice(int devindex)
82 {
83 SDL_VideoDevice *device;
84
85 /* Initialize all variables that we clean on shutdown */
86 device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
87 if (!device) {
88 SDL_OutOfMemory();
89 return (0);
90 }
91 device->is_dummy = SDL_TRUE;
92
93 /* Set the function pointers */
94 device->VideoInit = AliOS_VideoInit;
95 device->VideoQuit = AliOS_VideoQuit;
96 device->SetDisplayMode = AliOS_SetDisplayMode;
97 device->PumpEvents = AliOS_PumpEvents;
98 device->CreateWindowFramebuffer = SDL_AliOS_CreateWindowFramebuffer;
99 device->UpdateWindowFramebuffer = SDL_AliOS_UpdateWindowFramebuffer;
100 device->DestroyWindowFramebuffer = SDL_AliOS_DestroyWindowFramebuffer;
101
102 device->free = AliOS_DeleteDevice;
103
104 return device;
105 }
106
107 VideoBootStrap AliOS_bootstrap = {
108 ALIOSVID_DRIVER_NAME, "SDL alios video driver",
109 AliOS_Available, AliOS_CreateDevice
110 };
111
112
113 int
AliOS_VideoInit(_THIS)114 AliOS_VideoInit(_THIS)
115 {
116 SDL_DisplayMode mode;
117
118 /* Use a fake 32-bpp desktop mode */
119 #ifdef AOS_COMP_LCD
120 #ifdef AOS_APP_GAME_DEMO
121 hal_lcd_t *hal_lcd = get_hal_lcd();
122 uint8_t *frame;
123 mode.format = SDL_PIXELFORMAT_RGB565;
124 mode.w = 240;
125 mode.h = 320;
126 frame = malloc(mode.w*mode.h*2);
127 #else
128 hal_lcd_t *hal_lcd = get_hal_lcd();
129 uint8_t *frame;
130 mode.format = SDL_PIXELFORMAT_BGR565;
131 mode.w = 320;
132 mode.h = 240;
133 frame = malloc(mode.w*mode.h*2);
134 #endif
135 #endif
136 #ifdef AOS_COMP_UDISPLAY
137 mode.format = SDL_PIXELFORMAT_BGR565;
138 mode.w = 320;
139 mode.h = 240;
140 #endif
141 mode.refresh_rate = 0;
142 mode.driverdata = NULL;
143 if (SDL_AddBasicVideoDisplay(&mode) < 0) {
144 return -1;
145 }
146
147 SDL_zero(mode);
148 SDL_AddDisplayMode(&_this->displays[0], &mode);
149
150 #ifdef SDL_INPUT_LINUXEV
151 SDL_EVDEV_Init();
152 #endif
153
154 #ifdef AOS_COMP_LCD
155 #ifdef AOS_APP_GAME_DEMO
156 hal_lcd->lcd_init();
157 hal_lcd->lcd_rotation_set(HAL_LCD_ROTATE_0);
158 memset(frame, 0xffff, mode.w*mode.h*2);
159 hal_lcd->lcd_frame_draw(frame);
160 free(frame);
161 #else
162 hal_lcd->lcd_init();
163 hal_lcd->lcd_rotation_set(HAL_LCD_ROTATE_90);
164 memset(frame, 0xffff, mode.w*mode.h*2);
165 hal_lcd->lcd_frame_draw(frame);
166 free(frame);
167 #endif
168 #endif
169 //AliOS_InitMouse(_this);
170
171 #ifdef AOS_COMP_UDISPLAY
172 udisplay_init();
173 #endif
174 /* We're done! */
175 return 0;
176 }
177
178 static int
AliOS_SetDisplayMode(_THIS,SDL_VideoDisplay * display,SDL_DisplayMode * mode)179 AliOS_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
180 {
181 return 0;
182 }
183
184 void
AliOS_VideoQuit(_THIS)185 AliOS_VideoQuit(_THIS)
186 {
187 }
188
189 #endif /* SDL_VIDEO_DRIVER_ALIOS */
190
191 /* vi: set ts=4 sw=4 expandtab: */
192