SDL  2.0
SDL_offscreenwindow.c
Go to the documentation of this file.
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 
22 #include "../../SDL_internal.h"
23 
24 #if SDL_VIDEO_DRIVER_OFFSCREEN
25 
26 #include "../SDL_egl_c.h"
27 #include "../SDL_sysvideo.h"
28 
29 #include "SDL_offscreenwindow.h"
30 
31 int
33 {
34  OFFSCREEN_Window* offscreen_window = SDL_calloc(1, sizeof(OFFSCREEN_Window));
35 
36  if (!offscreen_window) {
37  return SDL_OutOfMemory();
38  }
39 
40  window->driverdata = offscreen_window;
41 
42  if (window->x == SDL_WINDOWPOS_UNDEFINED) {
43  window->x = 0;
44  }
45 
46  if (window->y == SDL_WINDOWPOS_UNDEFINED) {
47  window->y = 0;
48  }
49 
50  offscreen_window->sdl_window = window;
51 
52  if (window->flags & SDL_WINDOW_OPENGL) {
53 
54  if (!_this->egl_data) {
55  return SDL_SetError("Cannot create an OPENGL window invalid egl_data");
56  }
57 
58  offscreen_window->egl_surface = SDL_EGL_CreateOffscreenSurface(_this, window->w, window->h);
59 
60  if (offscreen_window->egl_surface == EGL_NO_SURFACE) {
61  return SDL_SetError("Failed to created an offscreen surface (EGL display: %p)",
62  _this->egl_data->egl_display);
63  }
64  }
65  else {
66  offscreen_window->egl_surface = EGL_NO_SURFACE;
67  }
68 
69  return 0;
70 }
71 
72 void
74 {
75  OFFSCREEN_Window* offscreen_window = window->driverdata;
76 
77  if (offscreen_window) {
78  SDL_EGL_DestroySurface(_this, offscreen_window->egl_surface);
79  SDL_free(offscreen_window);
80  }
81 
82  window->driverdata = NULL;
83 }
84 
85 #endif /* SDL_VIDEO_DRIVER_OFFSCREEN */
86 
87 /* vi: set ts=4 sw=4 expandtab: */
#define _THIS
#define SDL_SetError
#define SDL_free
#define SDL_calloc
#define SDL_OutOfMemory()
Definition: SDL_error.h:88
void OFFSCREEN_DestroyWindow(_THIS, SDL_Window *window)
int OFFSCREEN_CreateWindow(_THIS, SDL_Window *window)
static SDL_VideoDevice * _this
Definition: SDL_video.c:126
#define SDL_WINDOWPOS_UNDEFINED
Definition: SDL_video.h:130
@ SDL_WINDOW_OPENGL
Definition: SDL_video.h:100
#define NULL
Definition: begin_code.h:163
#define EGL_NO_SURFACE
Definition: egl.h:100
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
SDL_Window * sdl_window
The type used to identify a window.
Definition: SDL_sysvideo.h:75