SDL  2.0
SDL_mirframebuffer.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2018 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 /*
23  Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
24 */
25 
26 #include "../../SDL_internal.h"
27 
28 #if SDL_VIDEO_DRIVER_MIR
29 
30 #include "SDL_mirevents.h"
31 #include "SDL_mirframebuffer.h"
32 #include "SDL_mirwindow.h"
33 
34 #include "SDL_mirdyn.h"
35 
36 int
38  void** pixels, int* pitch)
39 {
40  MIR_Data* mir_data = _this->driverdata;
41 
42  mir_data->software = SDL_TRUE;
43 
44  if (MIR_CreateWindow(_this, window) < 0)
45  return SDL_SetError("Failed to create a mir window.");
46 
49  return SDL_SetError("Unknown pixel format");
50 
51  *pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
52 
53  *pixels = SDL_malloc(window->h*(*pitch));
54  if (*pixels == NULL)
55  return SDL_OutOfMemory();
56 
57  return 0;
58 }
59 
60 int
62  const SDL_Rect* rects, int numrects)
63 {
64  MIR_Window* mir_window = window->driverdata;
65 
66  MirGraphicsRegion region;
67  MirBufferStream* bs;
68  int i, j, x, y, w, h, start;
69  int bytes_per_pixel, bytes_per_row, s_stride, d_stride;
70  char* s_dest;
71  char* pixels;
72 
73  bs = MIR_mir_window_get_buffer_stream(mir_window->window);
74  MIR_mir_buffer_stream_get_graphics_region(bs, &region);
75 
76  s_dest = region.vaddr;
77  pixels = (char*)window->surface->pixels;
78 
79  s_stride = window->surface->pitch;
80  d_stride = region.stride;
81  bytes_per_pixel = window->surface->format->BytesPerPixel;
82 
83  for (i = 0; i < numrects; i++) {
84  s_dest = region.vaddr;
85  pixels = (char*)window->surface->pixels;
86 
87  x = rects[i].x;
88  y = rects[i].y;
89  w = rects[i].w;
90  h = rects[i].h;
91 
92  if (w <= 0 || h <= 0 || (x + w) <= 0 || (y + h) <= 0)
93  continue;
94 
95  if (x < 0) {
96  x += w;
97  w += rects[i].x;
98  }
99 
100  if (y < 0) {
101  y += h;
102  h += rects[i].y;
103  }
104 
105  if (x + w > window->w)
106  w = window->w - x;
107  if (y + h > window->h)
108  h = window->h - y;
109 
110  start = y * s_stride + x;
111  pixels += start;
112  s_dest += start;
113 
114  bytes_per_row = bytes_per_pixel * w;
115  for (j = 0; j < h; j++) {
116  SDL_memcpy(s_dest, pixels, bytes_per_row);
117  pixels += s_stride;
118  s_dest += d_stride;
119  }
120  }
121 
122  MIR_mir_buffer_stream_swap_buffers_sync(bs);
123 
124  return 0;
125 }
126 
127 void
129 {
130 }
131 
132 #endif /* SDL_VIDEO_DRIVER_MIR */
133 
134 /* vi: set ts=4 sw=4 expandtab: */
format
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
MIR_Window::window
MirWindow * window
Definition: SDL_mirwindow.h:38
MIR_Window
Definition: SDL_mirwindow.h:34
SDL_VideoDevice::driverdata
void * driverdata
Definition: SDL_sysvideo.h:381
MIR_Data::pixel_format
MirPixelFormat pixel_format
Definition: SDL_mirvideo.h:41
SDL_mirwindow.h
NULL
#define NULL
Definition: begin_code.h:164
MIR_GetSDLPixelFormat
Uint32 MIR_GetSDLPixelFormat(MirPixelFormat format)
SDL_mirevents.h
SDL_mirframebuffer.h
MIR_DestroyWindowFramebuffer
void MIR_DestroyWindowFramebuffer(_THIS, SDL_Window *sdl_window)
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:203
MIR_UpdateWindowFramebuffer
int MIR_UpdateWindowFramebuffer(_THIS, SDL_Window *sdl_window, const SDL_Rect *rects, int numrects)
h
GLfloat GLfloat GLfloat GLfloat h
Definition: SDL_opengl_glext.h:1946
MIR_CreateWindowFramebuffer
int MIR_CreateWindowFramebuffer(_THIS, SDL_Window *sdl_window, Uint32 *format, void **pixels, int *pitch)
SDL_Window
The type used to identify a window.
Definition: SDL_sysvideo.h:74
SDL_memcpy
#define SDL_memcpy
Definition: SDL_dynapi_overrides.h:387
_this
static SDL_VideoDevice * _this
Definition: SDL_video.c:121
x
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
window
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
MIR_Data
Definition: SDL_mirvideo.h:36
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
MIR_Data::software
SDL_bool software
Definition: SDL_mirvideo.h:40
SDL_PIXELFORMAT_UNKNOWN
@ SDL_PIXELFORMAT_UNKNOWN
Definition: SDL_pixels.h:173
SDL_TRUE
@ SDL_TRUE
Definition: SDL_stdinc.h:164
start
GLuint start
Definition: SDL_opengl.h:1571
pixels
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
y
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
SDL_mirdyn.h
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
SDL_BYTESPERPIXEL
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
SDL_Rect
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:65
j
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int in j)
Definition: SDL_x11sym.h:50
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:374
rects
EGLSurface EGLint * rects
Definition: eglext.h:282
MIR_CreateWindow
int MIR_CreateWindow(_THIS, SDL_Window *window)
i
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
w
GLubyte GLubyte GLubyte GLubyte w
Definition: SDL_opengl_glext.h:731