parent
1903483c0c
commit
485e932deb
1
Makefile
1
Makefile
|
@ -6,7 +6,6 @@ include build-aux/version.mak
|
|||
MODULES=\
|
||||
libc \
|
||||
libm \
|
||||
dispd \
|
||||
libdisplay \
|
||||
libmount \
|
||||
libui \
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
*.a
|
||||
*.o
|
||||
server/dispd
|
|
@ -1,53 +0,0 @@
|
|||
SOFTWARE_MEANT_FOR_SORTIX=1
|
||||
include ../build-aux/platform.mak
|
||||
include ../build-aux/compiler.mak
|
||||
include ../build-aux/version.mak
|
||||
include ../build-aux/dirs.mak
|
||||
|
||||
OPTLEVEL?=$(DEFAULT_OPTLEVEL)
|
||||
CFLAGS?=$(OPTLEVEL)
|
||||
|
||||
CFLAGS:=$(CFLAGS) -Wall -Wextra
|
||||
CPPFLAGS:=$(CPPFLAGS) -I include
|
||||
|
||||
CLIENT_OBJS:=\
|
||||
client/library.o \
|
||||
client/session.o \
|
||||
client/window.o \
|
||||
|
||||
BINS:=client/libdispd.a
|
||||
|
||||
all: $(BINS)
|
||||
|
||||
.PHONY: all headers client clean install install-include-dirs \
|
||||
install-headers install-client-dirs install-client
|
||||
|
||||
headers:
|
||||
|
||||
client: client/libdispd.a
|
||||
|
||||
client/libdispd.a: $(CLIENT_OBJS)
|
||||
$(AR) rcs $@ $(CLIENT_OBJS)
|
||||
|
||||
clean:
|
||||
rm -f $(CLIENT_OBJS)
|
||||
rm -f $(BINS)
|
||||
rm -f *.o client/*.o
|
||||
|
||||
%.o: %.c
|
||||
$(CC) -std=gnu11 $(CFLAGS) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
# Installation into sysroot
|
||||
install: install-headers install-client
|
||||
|
||||
install-include-dirs: headers
|
||||
mkdir -p $(DESTDIR)$(INCLUDEDIR)
|
||||
|
||||
install-headers: install-include-dirs headers
|
||||
cp -RTv include $(DESTDIR)$(INCLUDEDIR)
|
||||
|
||||
install-client-dirs:
|
||||
mkdir -p $(DESTDIR)$(LIBDIR)
|
||||
|
||||
install-client: install-client-dirs client
|
||||
cp -P client/libdispd.a $(DESTDIR)$(LIBDIR)
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2016 Jonas 'Sortie' Termansen.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* framebuffer.h
|
||||
* Keeps track of framebuffers.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_DISPD_FRAMEBUFFER_H
|
||||
#define INCLUDE_DISPD_FRAMEBUFFER_H
|
||||
|
||||
struct dispd_framebuffer
|
||||
{
|
||||
struct dispd_window* window;
|
||||
uint8_t* data;
|
||||
size_t datasize;
|
||||
size_t pitch;
|
||||
int bpp;
|
||||
int width;
|
||||
int height;
|
||||
uint64_t fb_location;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2012 Jonas 'Sortie' Termansen.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* library.c
|
||||
* Main entry point of the Sortix Display Daemon.
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <dispd.h>
|
||||
|
||||
#include "session.h"
|
||||
|
||||
bool dispd_initialize(int* argc, char*** argv)
|
||||
{
|
||||
if ( !dispd__session_initialize(argc, argv) )
|
||||
return false;
|
||||
return true;
|
||||
}
|
|
@ -1,130 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2013, 2014, 2016 Jonas 'Sortie' Termansen.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* session.c
|
||||
* Handles session management.
|
||||
*/
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/display.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <dispd.h>
|
||||
|
||||
#include "session.h"
|
||||
|
||||
struct dispd_session* global_session = NULL;
|
||||
|
||||
bool dispd__session_initialize(int* argc, char*** argv)
|
||||
{
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
size_t size = sizeof(struct dispd_session);
|
||||
global_session = (struct dispd_session*) malloc(size);
|
||||
if ( !global_session )
|
||||
return false;
|
||||
memset(global_session, 0, sizeof(*global_session));
|
||||
int tty_fd = open("/dev/tty", O_RDWR);
|
||||
if ( tty_fd < 0 )
|
||||
return free(global_session), false;
|
||||
struct tiocgdisplay display;
|
||||
struct tiocgdisplays gdisplays;
|
||||
memset(&gdisplays, 0, sizeof(gdisplays));
|
||||
gdisplays.count = 1;
|
||||
gdisplays.displays = &display;
|
||||
bool fail = ioctl(tty_fd, TIOCGDISPLAYS, &gdisplays) < 0 ||
|
||||
gdisplays.count == 0;
|
||||
close(tty_fd);
|
||||
if ( fail )
|
||||
return free(global_session), false;
|
||||
global_session->device = display.device;
|
||||
global_session->connector = display.connector;
|
||||
return true;
|
||||
}
|
||||
|
||||
struct dispd_session* dispd_attach_default_session()
|
||||
{
|
||||
global_session->refcount++;
|
||||
return global_session;
|
||||
}
|
||||
|
||||
bool dispd_detach_session(struct dispd_session* session)
|
||||
{
|
||||
session->refcount--;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dispd_session_setup_game_rgba(struct dispd_session* session)
|
||||
{
|
||||
if ( session->is_rgba )
|
||||
return true;
|
||||
if ( session->current_window )
|
||||
return false;
|
||||
struct dispmsg_get_crtc_mode msg;
|
||||
msg.msgid = DISPMSG_GET_CRTC_MODE;
|
||||
msg.device = session->device;
|
||||
msg.connector = session->connector;
|
||||
if ( dispmsg_issue(&msg, sizeof(msg)) != 0 )
|
||||
return false;
|
||||
if ( !(msg.mode.control & 1) || msg.mode.fb_format != 32 )
|
||||
{
|
||||
pid_t childpid = fork();
|
||||
if ( childpid < 0 )
|
||||
return false;
|
||||
if ( childpid )
|
||||
{
|
||||
int status;
|
||||
waitpid(childpid, &status, 0);
|
||||
return session->is_rgba = (WIFEXITED(status) && !WEXITSTATUS(status));
|
||||
}
|
||||
const char* chvideomode = "chvideomode";
|
||||
#if 1
|
||||
// TODO chvideomode currently launches --bpp 32 as a program...
|
||||
execlp(chvideomode, chvideomode, (const char*) NULL);
|
||||
#else
|
||||
execlp(chvideomode, chvideomode,
|
||||
"--bpp", "32",
|
||||
"--show-graphics", "true",
|
||||
"--show-text", "false",
|
||||
(const char*) NULL);
|
||||
#endif
|
||||
err(127, "%s", chvideomode);
|
||||
}
|
||||
|
||||
// HACK: The console may be rendered asynchronously and it might still be
|
||||
// rendering to the framebuffer, however this process is about to do
|
||||
// bitmapped graphics to the framebuffer as well. Since there is no
|
||||
// synchronization with the terminal except not writing to it, there
|
||||
// is a small window where both are fighting for the framebuffer.
|
||||
// We can resolve this issue by simply fsync()ing the terminal, which
|
||||
// causes the scheduled console rendering to finish before returning.
|
||||
int tty_fd = open("/dev/tty", O_WRONLY);
|
||||
if ( 0 <= tty_fd )
|
||||
{
|
||||
fsync(tty_fd);
|
||||
close(tty_fd);
|
||||
}
|
||||
|
||||
return session->is_rgba = true;
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2012 Jonas 'Sortie' Termansen.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* session.h
|
||||
* Handles session management.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_DISPD_SESSION_H
|
||||
#define INCLUDE_DISPD_SESSION_H
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct dispd_session
|
||||
{
|
||||
size_t refcount;
|
||||
uint64_t device;
|
||||
uint64_t connector;
|
||||
struct dispd_window* current_window;
|
||||
bool is_rgba;
|
||||
};
|
||||
|
||||
bool dispd__session_initialize(int* argc, char*** argv);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,150 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2013, 2014, 2016 Jonas 'Sortie' Termansen.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* window.c
|
||||
* Handles windows.
|
||||
*/
|
||||
|
||||
#include <sys/display.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <ioleast.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <dispd.h>
|
||||
|
||||
#include "framebuffer.h"
|
||||
#include "session.h"
|
||||
#include "window.h"
|
||||
|
||||
struct dispd_window* dispd_create_window_game_rgba(struct dispd_session* session)
|
||||
{
|
||||
if ( session->current_window )
|
||||
return NULL;
|
||||
if ( !session->is_rgba )
|
||||
return NULL;
|
||||
size_t size = sizeof(struct dispd_window);
|
||||
struct dispd_window* window = (struct dispd_window*) malloc(size);
|
||||
if ( !window )
|
||||
return NULL;
|
||||
memset(window, 0, sizeof(*window));
|
||||
window->session = session;
|
||||
return session->current_window = window;
|
||||
}
|
||||
|
||||
bool dispd_destroy_window(struct dispd_window* window)
|
||||
{
|
||||
free(window->cached_buffer);
|
||||
free(window);
|
||||
return true;
|
||||
}
|
||||
|
||||
static uint8_t* request_buffer(struct dispd_window* window, size_t size)
|
||||
{
|
||||
if ( window->cached_buffer )
|
||||
{
|
||||
if ( window->cached_buffer_size == size )
|
||||
{
|
||||
uint8_t* ret = window->cached_buffer;
|
||||
window->cached_buffer = NULL;
|
||||
window->cached_buffer_size = 0;
|
||||
return ret;
|
||||
}
|
||||
free(window->cached_buffer);
|
||||
window->cached_buffer = NULL;
|
||||
window->cached_buffer_size = 0;
|
||||
}
|
||||
return (uint8_t*) malloc(size);
|
||||
}
|
||||
|
||||
static void return_buffer(struct dispd_window* window, uint8_t* b, size_t size)
|
||||
{
|
||||
free(window->cached_buffer);
|
||||
window->cached_buffer = b;
|
||||
window->cached_buffer_size = size;
|
||||
}
|
||||
|
||||
struct dispd_framebuffer* dispd_begin_render(struct dispd_window* window)
|
||||
{
|
||||
struct dispmsg_get_crtc_mode msg;
|
||||
msg.msgid = DISPMSG_GET_CRTC_MODE;
|
||||
msg.device = window->session->device;
|
||||
msg.connector = window->session->connector;
|
||||
if ( dispmsg_issue(&msg, sizeof(msg)) != 0 )
|
||||
return NULL;
|
||||
size_t size = sizeof(struct dispd_framebuffer);
|
||||
struct dispd_framebuffer* fb = (struct dispd_framebuffer*) malloc(size);
|
||||
if ( !fb )
|
||||
return NULL;
|
||||
memset(fb, 0, sizeof(*fb));
|
||||
fb->window = window;
|
||||
fb->width = msg.mode.view_xres;
|
||||
fb->height = msg.mode.view_yres;
|
||||
fb->bpp = 32;
|
||||
fb->pitch = fb->width * fb->bpp / 8;
|
||||
fb->datasize = fb->pitch * fb->height;
|
||||
fb->data = (uint8_t*) request_buffer(window, fb->datasize);
|
||||
fb->fb_location = msg.mode.fb_location;
|
||||
if ( !fb->data ) { free(fb); return NULL; }
|
||||
return fb;
|
||||
}
|
||||
|
||||
bool dispd_finish_render(struct dispd_framebuffer* fb)
|
||||
{
|
||||
struct dispd_window* window = fb->window;
|
||||
bool ret = false;
|
||||
struct dispmsg_write_memory msg;
|
||||
msg.msgid = DISPMSG_WRITE_MEMORY;
|
||||
msg.device = window->session->device;
|
||||
msg.offset = fb->fb_location;
|
||||
msg.size = fb->datasize;
|
||||
msg.src = fb->data;
|
||||
if ( dispmsg_issue(&msg, sizeof(msg)) == 0 )
|
||||
ret = true;
|
||||
return_buffer(window, fb->data, fb->datasize);
|
||||
free(fb);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t* dispd_get_framebuffer_data(struct dispd_framebuffer* fb)
|
||||
{
|
||||
return fb->data;
|
||||
}
|
||||
|
||||
size_t dispd_get_framebuffer_pitch(struct dispd_framebuffer* fb)
|
||||
{
|
||||
return fb->pitch;
|
||||
}
|
||||
|
||||
int dispd_get_framebuffer_format(struct dispd_framebuffer* fb)
|
||||
{
|
||||
return fb->bpp;
|
||||
}
|
||||
|
||||
int dispd_get_framebuffer_height(struct dispd_framebuffer* fb)
|
||||
{
|
||||
return fb->height;
|
||||
}
|
||||
|
||||
int dispd_get_framebuffer_width(struct dispd_framebuffer* fb)
|
||||
{
|
||||
return fb->width;
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2012 Jonas 'Sortie' Termansen.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* window.h
|
||||
* Handles windows.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_DISPD_WINDOW_H
|
||||
#define INCLUDE_DISPD_WINDOW_H
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct dispd_window
|
||||
{
|
||||
struct dispd_session* session;
|
||||
uint8_t* cached_buffer;
|
||||
size_t cached_buffer_size;
|
||||
};
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2012 Jonas 'Sortie' Termansen.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* dispd.h
|
||||
* Interface to the Sortix Display Daemon.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_DISPD_H
|
||||
#define INCLUDE_DISPD_H
|
||||
|
||||
#if !defined(__cplusplus)
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct dispd_session;
|
||||
struct dispd_window;
|
||||
struct dispd_framebuffer;
|
||||
|
||||
bool dispd_initialize(int* argc, char*** argv);
|
||||
|
||||
struct dispd_session* dispd_attach_default_session(void);
|
||||
bool dispd_detach_session(struct dispd_session* session);
|
||||
|
||||
bool dispd_session_setup_game_rgba(struct dispd_session* session);
|
||||
|
||||
struct dispd_window* dispd_create_window_game_rgba(struct dispd_session* session);
|
||||
bool dispd_destroy_window(struct dispd_window* window);
|
||||
|
||||
struct dispd_framebuffer* dispd_begin_render(struct dispd_window* window);
|
||||
bool dispd_finish_render(struct dispd_framebuffer* framebuffer);
|
||||
|
||||
uint8_t* dispd_get_framebuffer_data(struct dispd_framebuffer* framebuffer);
|
||||
size_t dispd_get_framebuffer_pitch(struct dispd_framebuffer* framebuffer);
|
||||
int dispd_get_framebuffer_format(struct dispd_framebuffer* framebuffer);
|
||||
int dispd_get_framebuffer_height(struct dispd_framebuffer* framebuffer);
|
||||
int dispd_get_framebuffer_width(struct dispd_framebuffer* framebuffer);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,3 +1,26 @@
|
|||
diff -Paur --no-dereference -- libSDL.upstream/configure libSDL/configure
|
||||
--- libSDL.upstream/configure
|
||||
+++ libSDL/configure
|
||||
@@ -19338,7 +19338,7 @@
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
- #include <dispd.h>
|
||||
+ #include <display.h>
|
||||
|
||||
int
|
||||
main ()
|
||||
@@ -19362,8 +19362,8 @@
|
||||
|
||||
SOURCES="$SOURCES $srcdir/src/video/sortix/*.c"
|
||||
have_video=yes
|
||||
- EXTRA_LDFLAGS="$EXTRA_LDFLAGS -ldispd"
|
||||
- SDL_LIBS="$SDL_LIBS -ldispd"
|
||||
+ EXTRA_LDFLAGS="$EXTRA_LDFLAGS -ldisplay"
|
||||
+ SDL_LIBS="$SDL_LIBS -ldisplay"
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for display support" >&5
|
||||
$as_echo_n "checking for display support... " >&6; }
|
||||
diff -Paur --no-dereference -- libSDL.upstream/make.sortix libSDL/make.sortix
|
||||
--- libSDL.upstream/make.sortix
|
||||
+++ libSDL/make.sortix
|
||||
|
@ -10,3 +33,358 @@ diff -Paur --no-dereference -- libSDL.upstream/make.sortix libSDL/make.sortix
|
|||
+if [ "$1" = "install" ]; then
|
||||
+rm -fv "$DESTDIR/$EXEC_PREFIX/bin/sdl-config"
|
||||
+fi
|
||||
diff -Paur --no-dereference -- libSDL.upstream/sdl.pc libSDL/sdl.pc
|
||||
--- libSDL.upstream/sdl.pc
|
||||
+++ libSDL/sdl.pc
|
||||
@@ -10,6 +10,6 @@
|
||||
Version: 1.2.15
|
||||
Requires:
|
||||
Conflicts:
|
||||
-Libs: -L${libdir} -lSDL -ldispd -ldisplay
|
||||
-Libs.private: -lSDL -ldispd -ldisplay -liconv -lm -ldispd -ldisplay
|
||||
-Cflags: -I${includedir}/SDL
|
||||
+Libs: -L${libdir} -lSDL -ldisplay -ldisplay
|
||||
+Libs.private: -lSDL -ldisplay -ldisplay -liconv -lm -ldisplay -ldisplay
|
||||
+Cflags: -I${includedir}/SDL -D_GNU_SOURCE=1
|
||||
diff -Paur --no-dereference -- libSDL.upstream/src/video/sortix/SDL_dispd.c libSDL/src/video/sortix/SDL_dispd.c
|
||||
--- libSDL.upstream/src/video/sortix/SDL_dispd.c
|
||||
+++ libSDL/src/video/sortix/SDL_dispd.c
|
||||
@@ -28,14 +28,11 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
-#include <dispd.h>
|
||||
-#if __has_include(<display.h>)
|
||||
-#define DISPLAY
|
||||
-#include <display.h>
|
||||
-#endif
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
+#include <display.h>
|
||||
+
|
||||
#include "SDL_video.h"
|
||||
#include "../SDL_sysvideo.h"
|
||||
#include "../../events/SDL_sysevents.h"
|
||||
@@ -64,30 +61,12 @@
|
||||
|
||||
static void DispD_DeleteDevice(SDL_VideoDevice *device)
|
||||
{
|
||||
-#ifdef DISPLAY
|
||||
if ( device->hidden->connection ) {
|
||||
display_destroy_window(device->hidden->connection,
|
||||
device->hidden->window_id);
|
||||
display_disconnect(device->hidden->connection);
|
||||
device->hidden->connection = NULL;
|
||||
}
|
||||
-#endif
|
||||
- if ( device->hidden->fbinfo ) {
|
||||
- dispd_finish_render(device->hidden->fbinfo);
|
||||
- device->hidden->fbinfo = NULL;
|
||||
- }
|
||||
- if ( device->hidden->window ) {
|
||||
- dispd_destroy_window(device->hidden->window);
|
||||
- device->hidden->window = NULL;
|
||||
- }
|
||||
- if ( device->hidden->session ) {
|
||||
- dispd_detach_session(device->hidden->session);
|
||||
- device->hidden->session = NULL;
|
||||
- }
|
||||
- if ( 0 < device->hidden->tty_fd ) {
|
||||
- close(device->hidden->tty_fd);
|
||||
- device->hidden->tty_fd = -1;
|
||||
- }
|
||||
SDL_free(device->hidden);
|
||||
SDL_free(device);
|
||||
}
|
||||
@@ -112,68 +91,20 @@
|
||||
}
|
||||
SDL_memset(device->hidden, 0, (sizeof *device->hidden));
|
||||
|
||||
-#ifdef DISPLAY
|
||||
- if ( (device->hidden->connection = display_connect_default()) ) {
|
||||
- device->hidden->disconnected = 0;
|
||||
- device->hidden->window_id = 0;
|
||||
- device->hidden->window_width = 0;
|
||||
- device->hidden->window_height = 0;
|
||||
- display_create_window(device->hidden->connection,
|
||||
- device->hidden->window_id);
|
||||
- } else {
|
||||
-#endif
|
||||
- static int has_initialized_dispd = 0;
|
||||
- if ( !has_initialized_dispd ) {
|
||||
- if ( !dispd_initialize(NULL, NULL) ) {
|
||||
- return(0);
|
||||
- }
|
||||
- has_initialized_dispd = 1;
|
||||
- }
|
||||
- if ( (device->hidden->tty_fd = open("/dev/tty", O_RDONLY)) < 0 ) {
|
||||
- DispD_DeleteDevice(device);
|
||||
- return(0);
|
||||
- }
|
||||
-
|
||||
- if ( (device->hidden->session = dispd_attach_default_session()) == NULL ) {
|
||||
- DispD_DeleteDevice(device);
|
||||
- return(0);
|
||||
- }
|
||||
-
|
||||
- if ( !(dispd_session_setup_game_rgba(device->hidden->session)) ) {
|
||||
- DispD_DeleteDevice(device);
|
||||
- return(0);
|
||||
- }
|
||||
+ if ( !(device->hidden->connection = display_connect_default()) ) {
|
||||
+ return(0);
|
||||
+ }
|
||||
|
||||
- if ( (device->hidden->window =
|
||||
- dispd_create_window_game_rgba(device->hidden->session)) == NULL ) {
|
||||
- DispD_DeleteDevice(device);
|
||||
- return(0);
|
||||
- }
|
||||
+ device->hidden->disconnected = 0;
|
||||
+ device->hidden->window_id = 0;
|
||||
+ device->hidden->window_width = 0;
|
||||
+ device->hidden->window_height = 0;
|
||||
+ display_create_window(device->hidden->connection,
|
||||
+ device->hidden->window_id);
|
||||
|
||||
- if ( (device->hidden->fbinfo =
|
||||
- dispd_begin_render(device->hidden->window)) == NULL ) {
|
||||
- DispD_DeleteDevice(device);
|
||||
- return(0);
|
||||
- }
|
||||
-#ifdef DISPLAY
|
||||
- }
|
||||
-#endif
|
||||
+ device->hidden->current_mode.w = 800;
|
||||
+ device->hidden->current_mode.h = 600;
|
||||
|
||||
- device->hidden->current_mode.x = 0;
|
||||
- device->hidden->current_mode.y = 0;
|
||||
-#ifdef DISPLAY
|
||||
- if ( device->hidden->connection ) {
|
||||
- device->hidden->current_mode.w = 800;
|
||||
- device->hidden->current_mode.h = 600;
|
||||
- } else {
|
||||
-#endif
|
||||
- device->hidden->current_mode.w =
|
||||
- dispd_get_framebuffer_width(device->hidden->fbinfo);
|
||||
- device->hidden->current_mode.h =
|
||||
- dispd_get_framebuffer_height(device->hidden->fbinfo);
|
||||
-#ifdef DISPLAY
|
||||
- }
|
||||
-#endif
|
||||
device->hidden->mode_list[0] = &device->hidden->current_mode;
|
||||
device->hidden->mode_list[1] = NULL;
|
||||
|
||||
@@ -217,13 +148,8 @@
|
||||
SDL_Rect **DispD_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
|
||||
{
|
||||
// TODO: Return NULL if the format isn't 32-bit supported.
|
||||
-#ifdef DISPLAY
|
||||
- if ( this->hidden->connection ) {
|
||||
- // TODO: qemu seems to pick too little a resolution due to this.
|
||||
- return((SDL_Rect **)-1);
|
||||
- }
|
||||
-#endif
|
||||
- return(this->hidden->mode_list);
|
||||
+ // TODO: qemu seems to pick too little a resolution due to this.
|
||||
+ return((SDL_Rect **)-1);
|
||||
}
|
||||
|
||||
SDL_Surface *DispD_SetVideoMode(_THIS, SDL_Surface *current,
|
||||
@@ -234,28 +160,16 @@
|
||||
|
||||
bpp = 32;
|
||||
|
||||
-#ifdef DISPLAY
|
||||
- if ( this->hidden->connection ) {
|
||||
- current->flags = SDL_RESIZABLE;
|
||||
- size_t size = (size_t)width * (size_t)width * (bpp / 8);
|
||||
- data = SDL_malloc(size);
|
||||
- if ( !data )
|
||||
- return(NULL);
|
||||
- this->hidden->window_width = width;
|
||||
- this->hidden->window_height = height;
|
||||
- display_resize_window(this->hidden->connection,
|
||||
- this->hidden->window_id, width, height);
|
||||
- pitch = (size_t) width * (bpp / 8);
|
||||
- } else {
|
||||
-#endif
|
||||
- data = dispd_get_framebuffer_data(this->hidden->fbinfo);
|
||||
- width = dispd_get_framebuffer_width(this->hidden->fbinfo);
|
||||
- height = dispd_get_framebuffer_height(this->hidden->fbinfo);
|
||||
- pitch = dispd_get_framebuffer_pitch(this->hidden->fbinfo);
|
||||
- current->flags = SDL_FULLSCREEN;
|
||||
-#ifdef DISPLAY
|
||||
- }
|
||||
-#endif
|
||||
+ current->flags = SDL_RESIZABLE;
|
||||
+ size_t size = (size_t)width * (size_t)width * (bpp / 8);
|
||||
+ data = SDL_malloc(size);
|
||||
+ if ( !data )
|
||||
+ return(NULL);
|
||||
+ this->hidden->window_width = width;
|
||||
+ this->hidden->window_height = height;
|
||||
+ display_resize_window(this->hidden->connection,
|
||||
+ this->hidden->window_id, width, height);
|
||||
+ pitch = (size_t) width * (bpp / 8);
|
||||
|
||||
int y;
|
||||
for ( y = 0; y < height; y++ )
|
||||
@@ -270,7 +184,7 @@
|
||||
assert(current->format);
|
||||
assert(current->format->BitsPerPixel == 32);
|
||||
current->pitch = pitch;
|
||||
- // TODO: Memory leak of old buffer?
|
||||
+ free(current->pixels);
|
||||
current->pixels = data;
|
||||
current->w = width;
|
||||
current->h = height;
|
||||
@@ -291,12 +205,8 @@
|
||||
|
||||
static void DispD_SetCaption(_THIS, const char *title, const char *icon)
|
||||
{
|
||||
-#ifdef DISPLAY
|
||||
- if ( this->hidden->connection) {
|
||||
- display_title_window(this->hidden->connection,
|
||||
- this->hidden->window_id, title);
|
||||
- }
|
||||
-#endif
|
||||
+ display_title_window(this->hidden->connection,
|
||||
+ this->hidden->window_id, title);
|
||||
}
|
||||
|
||||
/* We need to wait for vertical retrace on page flipped displays */
|
||||
@@ -312,26 +222,13 @@
|
||||
|
||||
static void DispD_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
|
||||
{
|
||||
-#ifdef DISPLAY
|
||||
- if ( this->hidden->connection) {
|
||||
- for ( size_t i = 3; i < (size_t)SDL_VideoSurface->w * (size_t)SDL_VideoSurface->h * 4; i += 4 )
|
||||
- ((unsigned char*)SDL_VideoSurface->pixels)[i] = 255;
|
||||
- display_render_window(this->hidden->connection, this->hidden->window_id,
|
||||
- 0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h,
|
||||
- SDL_VideoSurface->pixels);
|
||||
- display_show_window(this->hidden->connection, this->hidden->window_id);
|
||||
- return;
|
||||
- }
|
||||
-#endif
|
||||
- uint8_t* old_data = dispd_get_framebuffer_data(this->hidden->fbinfo);
|
||||
- if ( !dispd_finish_render(this->hidden->fbinfo) ) {
|
||||
- abort();
|
||||
- }
|
||||
- if ( !(this->hidden->fbinfo = dispd_begin_render(this->hidden->window)) ) {
|
||||
- abort();
|
||||
- }
|
||||
- uint8_t* new_data = dispd_get_framebuffer_data(this->hidden->fbinfo);
|
||||
- assert(old_data == new_data);
|
||||
+ size_t size = (size_t)SDL_VideoSurface->w * (size_t)SDL_VideoSurface->h * 4;
|
||||
+ for ( size_t i = 3; i < size; i += 4 )
|
||||
+ ((unsigned char*)SDL_VideoSurface->pixels)[i] = 255;
|
||||
+ display_render_window(this->hidden->connection, this->hidden->window_id,
|
||||
+ 0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h,
|
||||
+ SDL_VideoSurface->pixels);
|
||||
+ display_show_window(this->hidden->connection, this->hidden->window_id);
|
||||
}
|
||||
|
||||
int DispD_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
|
||||
@@ -345,6 +242,7 @@
|
||||
*/
|
||||
void DispD_VideoQuit(_THIS)
|
||||
{
|
||||
+ free(this->screen->pixels);
|
||||
this->screen->pixels = NULL;
|
||||
}
|
||||
|
||||
@@ -424,7 +322,6 @@
|
||||
return 0;
|
||||
}
|
||||
|
||||
-#ifdef DISPLAY
|
||||
static void on_disconnect(void* ctx)
|
||||
{
|
||||
struct SDL_PrivateVideoData* hidden = (struct SDL_PrivateVideoData*) ctx;
|
||||
@@ -463,48 +360,19 @@
|
||||
keysym.unicode = 0;
|
||||
SDL_PrivateKeyboard(kbkey < 0 ? SDL_RELEASED : SDL_PRESSED, &keysym);
|
||||
}
|
||||
-#endif
|
||||
|
||||
void DispD_PumpEvents(_THIS)
|
||||
{
|
||||
-#ifdef DISPLAY
|
||||
- if ( this->hidden->connection) {
|
||||
- struct display_event_handlers handlers;
|
||||
- memset(&handlers, 0, sizeof(handlers));
|
||||
- handlers.context = this->hidden;
|
||||
- handlers.disconnect_handler = on_disconnect;
|
||||
- handlers.quit_handler = on_quit;
|
||||
- handlers.resize_handler = on_resize;
|
||||
- handlers.keyboard_handler = on_keyboard;
|
||||
- while ( !this->hidden->disconnected ) {
|
||||
- if ( display_poll_event(this->hidden->connection, &handlers) < 0 )
|
||||
- break;
|
||||
- }
|
||||
- return;
|
||||
- }
|
||||
-#endif
|
||||
-
|
||||
- // Read the keyboard input from the user.
|
||||
- const unsigned termmode = TERMMODE_KBKEY
|
||||
- | TERMMODE_UNICODE
|
||||
- | TERMMODE_SIGNAL
|
||||
- | TERMMODE_NONBLOCK;
|
||||
- if ( settermmode(0, termmode) ) {
|
||||
- return;
|
||||
- }
|
||||
- uint32_t codepoint;
|
||||
- ssize_t numbytes;
|
||||
- while ( 0 < (numbytes = read(0, &codepoint, sizeof(codepoint))) )
|
||||
- {
|
||||
- int kbkey = KBKEY_DECODE(codepoint);
|
||||
- int abskbkey = kbkey < 0 ? -kbkey : kbkey;
|
||||
- int key = TranslateKey(abskbkey);
|
||||
- SDL_keysym keysym;
|
||||
- keysym.scancode = abskbkey;
|
||||
- keysym.sym = key;
|
||||
- keysym.mod = 0;
|
||||
- keysym.unicode = 0;
|
||||
- SDL_PrivateKeyboard(kbkey < 0 ? SDL_RELEASED : SDL_PRESSED, &keysym);
|
||||
+ struct display_event_handlers handlers;
|
||||
+ memset(&handlers, 0, sizeof(handlers));
|
||||
+ handlers.context = this->hidden;
|
||||
+ handlers.disconnect_handler = on_disconnect;
|
||||
+ handlers.quit_handler = on_quit;
|
||||
+ handlers.resize_handler = on_resize;
|
||||
+ handlers.keyboard_handler = on_keyboard;
|
||||
+ while ( !this->hidden->disconnected ) {
|
||||
+ if ( display_poll_event(this->hidden->connection, &handlers) < 0 )
|
||||
+ break;
|
||||
}
|
||||
}
|
||||
|
||||
diff -Paur --no-dereference -- libSDL.upstream/src/video/sortix/SDL_dispd.h libSDL/src/video/sortix/SDL_dispd.h
|
||||
--- libSDL.upstream/src/video/sortix/SDL_dispd.h
|
||||
+++ libSDL/src/video/sortix/SDL_dispd.h
|
||||
@@ -33,19 +33,13 @@
|
||||
/* Private display data */
|
||||
|
||||
struct SDL_PrivateVideoData {
|
||||
-#ifdef DISPLAY
|
||||
struct display_connection *connection;
|
||||
uint32_t window_id;
|
||||
uint32_t window_width;
|
||||
uint32_t window_height;
|
||||
int disconnected;
|
||||
-#endif
|
||||
- struct dispd_session *session;
|
||||
- struct dispd_window *window;
|
||||
- struct dispd_framebuffer *fbinfo;
|
||||
SDL_Rect current_mode;
|
||||
SDL_Rect *mode_list[2];
|
||||
- int tty_fd;
|
||||
};
|
||||
|
||||
#endif /* _SDL_nullvideo_h */
|
||||
|
|
Loading…
Reference in New Issue