Skip to content

Latest commit

 

History

History
153 lines (118 loc) · 4.33 KB

SDL_mirframebuffer.c

File metadata and controls

153 lines (118 loc) · 4.33 KB
 
1
2
/*
Simple DirectMedia Layer
Jan 2, 2016
Jan 2, 2016
3
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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"
static const Uint32 mir_pixel_format_to_sdl_format[] = {
SDL_PIXELFORMAT_UNKNOWN, /* mir_pixel_format_invalid */
SDL_PIXELFORMAT_ABGR8888, /* mir_pixel_format_abgr_8888 */
SDL_PIXELFORMAT_BGR888, /* mir_pixel_format_xbgr_8888 */
SDL_PIXELFORMAT_ARGB8888, /* mir_pixel_format_argb_8888 */
SDL_PIXELFORMAT_RGB888, /* mir_pixel_format_xrgb_8888 */
Feb 21, 2016
Feb 21, 2016
42
43
44
45
46
SDL_PIXELFORMAT_BGR24, /* mir_pixel_format_bgr_888 */
SDL_PIXELFORMAT_RGB24, /* mir_pixel_format_rgb_888 */
SDL_PIXELFORMAT_RGB565, /* mir_pixel_format_rgb_565 */
SDL_PIXELFORMAT_RGBA5551, /* mir_pixel_format_rgba_5551 */
SDL_PIXELFORMAT_RGBA4444 /* mir_pixel_format_rgba_4444 */
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
};
Uint32
MIR_GetSDLPixelFormat(MirPixelFormat format)
{
return mir_pixel_format_to_sdl_format[format];
}
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 created a mir window.");
Feb 21, 2016
Feb 21, 2016
66
*format = MIR_GetSDLPixelFormat(mir_data->pixel_format);
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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;
Feb 21, 2016
Feb 21, 2016
86
MirBufferStream* bs;
87
88
89
90
91
int i, j, x, y, w, h, start;
int bytes_per_pixel, bytes_per_row, s_stride, d_stride;
char* s_dest;
char* pixels;
Feb 21, 2016
Feb 21, 2016
92
93
bs = MIR_mir_surface_get_buffer_stream(mir_window->surface);
MIR_mir_buffer_stream_get_graphics_region(bs, &region);
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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++) {
memcpy(s_dest, pixels, bytes_per_row);
pixels += s_stride;
s_dest += d_stride;
}
}
Feb 21, 2016
Feb 21, 2016
141
MIR_mir_buffer_stream_swap_buffers_sync(bs);
142
143
144
145
146
147
148
149
150
151
152
153
return 0;
}
void
MIR_DestroyWindowFramebuffer(_THIS, SDL_Window* window)
{
}
#endif /* SDL_VIDEO_DRIVER_MIR */
/* vi: set ts=4 sw=4 expandtab: */