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
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld [DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp local skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
GLuint start
Definition: SDL_opengl.h:1571
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
uint32_t Uint32
Definition: SDL_stdinc.h:203
#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