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 #ifdef AOS_COMP_UDISPLAY
26 #include "udisplay.h"
27 #endif
28 
29 #include "../SDL_sysvideo.h"
30 #include "SDL_AliOS_framebuffer_c.h"
31 
32 
33 #define ALIOS_SURFACE   "_SDL_AliOSSurface"
34 
SDL_AliOS_CreateWindowFramebuffer(_THIS,SDL_Window * window,Uint32 * format,void ** pixels,int * pitch)35 int SDL_AliOS_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
36 {
37     SDL_Surface *surface;
38     const Uint32 surface_format = SDL_PIXELFORMAT_RGB565;
39     int w, h;
40     int bpp;
41     Uint32 Rmask, Gmask, Bmask, Amask;
42 
43     /* Free the old framebuffer surface */
44     surface = (SDL_Surface *) SDL_GetWindowData(window, ALIOS_SURFACE);
45     SDL_FreeSurface(surface);
46 
47     /* Create a new one */
48     SDL_PixelFormatEnumToMasks(surface_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
49     SDL_GetWindowSize(window, &w, &h);
50     surface = SDL_CreateRGBSurface(0, w, h, bpp, Rmask, Gmask, Bmask, Amask);
51     if (!surface) {
52         return -1;
53     }
54 
55     /* Save the info and return! */
56     SDL_SetWindowData(window, ALIOS_SURFACE, surface);
57     *format = surface_format;
58     *pixels = surface->pixels;
59     *pitch = surface->pitch;
60     return 0;
61 }
62 
SDL_AliOS_UpdateWindowFramebuffer(_THIS,SDL_Window * window,const SDL_Rect * rects,int numrects)63 int SDL_AliOS_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects)
64 {
65     static int frame_number;
66     SDL_Surface *surface;
67 
68     surface = (SDL_Surface *) SDL_GetWindowData(window, ALIOS_SURFACE);
69     if (!surface) {
70         return SDL_SetError("Couldn't find alios surface for window");
71     }
72 #ifdef AOS_COMP_LCD
73     hal_lcd_t *hal_lcd = get_hal_lcd();
74     hal_lcd->lcd_frame_draw(surface->pixels);
75 #endif
76 #ifdef AOS_COMP_UDISPLAY
77     udisplay_show_rect(surface->pixels, 0, 0, surface->w, surface->h, false);
78 #endif
79     return 0;
80 }
81 
SDL_AliOS_DestroyWindowFramebuffer(_THIS,SDL_Window * window)82 void SDL_AliOS_DestroyWindowFramebuffer(_THIS, SDL_Window * window)
83 {
84     SDL_Surface *surface;
85 
86     surface = (SDL_Surface *) SDL_SetWindowData(window, ALIOS_SURFACE, NULL);
87     SDL_FreeSurface(surface);
88 }
89 
90 #endif /* SDL_VIDEO_DRIVER_ALIOS */
91 
92 /* vi: set ts=4 sw=4 expandtab: */
93