SDL_mirframebuffer.c
Go to the documentation of this file.
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/*
Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_MIR
#include "SDL_mirevents.h"
#include "SDL_mirframebuffer.h"
#include "SDL_mirwindow.h"
#include "SDL_mirdyn.h"
int
MIR_CreateWindowFramebuffer(_THIS, SDL_Window* window, Uint32* format,
void** pixels, int* pitch)
{
MIR_Data* mir_data = _this->driverdata;
mir_data->software = SDL_TRUE;
if (MIR_CreateWindow(_this, window) < 0)
return SDL_SetError("Failed to create a mir window.");
*format = MIR_GetSDLPixelFormat(mir_data->pixel_format);
if (*format == SDL_PIXELFORMAT_UNKNOWN)
return SDL_SetError("Unknown pixel format");
*pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
*pixels = SDL_malloc(window->h*(*pitch));
if (*pixels == NULL)
return SDL_OutOfMemory();
return 0;
}
int
MIR_UpdateWindowFramebuffer(_THIS, SDL_Window* window,
const SDL_Rect* rects, int numrects)
{
MIR_Window* mir_window = window->driverdata;
MirGraphicsRegion region;
MirBufferStream* bs;
int i, j, x, y, w, h, start;
int bytes_per_pixel, bytes_per_row, s_stride, d_stride;
char* s_dest;
char* pixels;
bs = MIR_mir_window_get_buffer_stream(mir_window->window);
MIR_mir_buffer_stream_get_graphics_region(bs, &region);
s_dest = region.vaddr;
pixels = (char*)window->surface->pixels;
s_stride = window->surface->pitch;
d_stride = region.stride;
bytes_per_pixel = window->surface->format->BytesPerPixel;
for (i = 0; i < numrects; i++) {
s_dest = region.vaddr;
pixels = (char*)window->surface->pixels;
x = rects[i].x;
y = rects[i].y;
w = rects[i].w;
h = rects[i].h;
if (w <= 0 || h <= 0 || (x + w) <= 0 || (y + h) <= 0)
continue;
if (x < 0) {
x += w;
w += rects[i].x;
}
if (y < 0) {
y += h;
h += rects[i].y;
}
if (x + w > window->w)
w = window->w - x;
if (y + h > window->h)
h = window->h - y;
start = y * s_stride + x;
pixels += start;
s_dest += start;
bytes_per_row = bytes_per_pixel * w;
for (j = 0; j < h; j++) {
SDL_memcpy(s_dest, pixels, bytes_per_row);
pixels += s_stride;
s_dest += d_stride;
}
}
MIR_mir_buffer_stream_swap_buffers_sync(bs);
return 0;
}
void
MIR_DestroyWindowFramebuffer(_THIS, SDL_Window* window)
{
}
#endif /* SDL_VIDEO_DRIVER_MIR */
/* vi: set ts=4 sw=4 expandtab: */
SDL_TRUE
Definition: SDL_stdinc.h:142
SDL_mirevents.h
SDL_Window::w
int w
Definition: SDL_sysvideo.h:80
x
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
MIR_CreateWindowFramebuffer
int MIR_CreateWindowFramebuffer(_THIS, SDL_Window *sdl_window, Uint32 *format, void **pixels, int *pitch)
SDL_PixelFormat::BytesPerPixel
Uint8 BytesPerPixel
Definition: SDL_pixels.h:320
MIR_CreateWindow
int MIR_CreateWindow(_THIS, SDL_Window *window)
MIR_Data::pixel_format
MirPixelFormat pixel_format
Definition: SDL_mirvideo.h:41
h
GLfloat GLfloat GLfloat GLfloat h
Definition: SDL_opengl_glext.h:1946
SDL_VideoDevice::driverdata
void * driverdata
Definition: SDL_sysvideo.h:377
SDL_mirwindow.h
MIR_Window
Definition: SDL_mirwindow.h:34
SDL_BYTESPERPIXEL
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
start
GLuint start
Definition: SDL_opengl.h:1571
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:181
MIR_Data
Definition: SDL_mirvideo.h:35
_this
static SDL_VideoDevice * _this
Definition: SDL_video.c:121
format
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
SDL_memcpy
#define SDL_memcpy
Definition: SDL_dynapi_overrides.h:387
MIR_Data::software
SDL_bool software
Definition: SDL_mirvideo.h:40
SDL_Surface::pixels
void * pixels
Definition: SDL_surface.h:75
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
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_PIXELFORMAT_UNKNOWN
Definition: SDL_pixels.h:173
w
GLubyte GLubyte GLubyte GLubyte w
Definition: SDL_opengl_glext.h:731
MIR_UpdateWindowFramebuffer
int MIR_UpdateWindowFramebuffer(_THIS, SDL_Window *sdl_window, const SDL_Rect *rects, int numrects)
MIR_Window::window
MirWindow * window
Definition: SDL_mirwindow.h:38
y
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
SDL_Rect::x
int x
Definition: SDL_rect.h:66
pixels
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
SDL_mirdyn.h
SDL_Rect::w
int w
Definition: SDL_rect.h:67
SDL_Window::h
int h
Definition: SDL_sysvideo.h:80
MIR_DestroyWindowFramebuffer
void MIR_DestroyWindowFramebuffer(_THIS, SDL_Window *sdl_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
NULL
#define NULL
Definition: begin_code.h:164
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_Surface::format
SDL_PixelFormat * format
Definition: SDL_surface.h:72
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
window
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
SDL_Rect::h
int h
Definition: SDL_rect.h:67
SDL_Window
The type used to identify a window.
Definition: SDL_sysvideo.h:73
SDL_Surface::pitch
int pitch
Definition: SDL_surface.h:74
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:374
SDL_Window::driverdata
void * driverdata
Definition: SDL_sysvideo.h:111
rects
EGLSurface EGLint * rects
Definition: eglext.h:282
MIR_GetSDLPixelFormat
Uint32 MIR_GetSDLPixelFormat(MirPixelFormat format)
SDL_Window::surface
SDL_Surface * surface
Definition: SDL_sysvideo.h:97
SDL_Rect::y
int y
Definition: SDL_rect.h:66
SDL_mirframebuffer.h
SDL_Rect
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64