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 
47  *format = MIR_GetSDLPixelFormat(mir_data->pixel_format);
48  if (*format == SDL_PIXELFORMAT_UNKNOWN)
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: */
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
int MIR_CreateWindowFramebuffer(_THIS, SDL_Window *sdl_window, Uint32 *format, void **pixels, int *pitch)
Uint8 BytesPerPixel
Definition: SDL_pixels.h:320
int MIR_CreateWindow(_THIS, SDL_Window *window)
MirPixelFormat pixel_format
Definition: SDL_mirvideo.h:41
GLfloat GLfloat GLfloat GLfloat h
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
GLuint start
Definition: SDL_opengl.h:1571
uint32_t Uint32
Definition: SDL_stdinc.h:181
static SDL_VideoDevice * _this
Definition: SDL_video.c:121
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
#define SDL_memcpy
SDL_bool software
Definition: SDL_mirvideo.h:40
void * pixels
Definition: SDL_surface.h:75
#define _THIS
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
GLubyte GLubyte GLubyte GLubyte w
int MIR_UpdateWindowFramebuffer(_THIS, SDL_Window *sdl_window, const SDL_Rect *rects, int numrects)
MirWindow * window
Definition: SDL_mirwindow.h:38
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
int x
Definition: SDL_rect.h:66
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
int w
Definition: SDL_rect.h:67
void MIR_DestroyWindowFramebuffer(_THIS, SDL_Window *sdl_window)
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
#define NULL
Definition: begin_code.h:164
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_PixelFormat * format
Definition: SDL_surface.h:72
#define SDL_SetError
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
int h
Definition: SDL_rect.h:67
The type used to identify a window.
Definition: SDL_sysvideo.h:73
#define SDL_malloc
void * driverdata
Definition: SDL_sysvideo.h:111
EGLSurface EGLint * rects
Definition: eglext.h:282
Uint32 MIR_GetSDLPixelFormat(MirPixelFormat format)
SDL_Surface * surface
Definition: SDL_sysvideo.h:97
int y
Definition: SDL_rect.h:66
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64