summaryrefslogtreecommitdiff
path: root/EGL/yagl_offscreen_surface.c
diff options
context:
space:
mode:
authorStanislav Vorobiov <s.vorobiov@samsung.com>2013-07-29 18:29:07 +0400
committerStanislav Vorobiov <s.vorobiov@samsung.com>2013-08-01 14:12:21 +0400
commit7262ded6ba6abcfe57286a438e8610cf4d5072f5 (patch)
treef56273a273effdfce00053a51e64e6e732dcb263 /EGL/yagl_offscreen_surface.c
parent5b9dd324588c5f969a9bb8f5fd00632a2c0ae3d8 (diff)
downloademulator-yagl-7262ded6ba6abcfe57286a438e8610cf4d5072f5.tar.gz
emulator-yagl-7262ded6ba6abcfe57286a438e8610cf4d5072f5.tar.bz2
emulator-yagl-7262ded6ba6abcfe57286a438e8610cf4d5072f5.zip
YaGL: Separated windowing system related stuff
Change-Id: I26b4dfbccd33e7c8ca89e5ef0bddb6d634220ad6
Diffstat (limited to 'EGL/yagl_offscreen_surface.c')
-rw-r--r--EGL/yagl_offscreen_surface.c232
1 files changed, 108 insertions, 124 deletions
diff --git a/EGL/yagl_offscreen_surface.c b/EGL/yagl_offscreen_surface.c
index 6e90a5e..f1c348a 100644
--- a/EGL/yagl_offscreen_surface.c
+++ b/EGL/yagl_offscreen_surface.c
@@ -1,25 +1,67 @@
#include "yagl_offscreen_surface.h"
#include "yagl_host_egl_calls.h"
#include "yagl_egl_state.h"
-#include "yagl_bimage.h"
#include "yagl_malloc.h"
#include "yagl_log.h"
#include "yagl_display.h"
#include "yagl_mem_egl.h"
+#include "yagl_native_display.h"
+#include "yagl_native_drawable.h"
+#include "yagl_native_image.h"
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
+#include <sys/mman.h>
+#include <errno.h>
+
+static struct yagl_native_image
+ *yagl_offscreen_surface_create_bi(struct yagl_native_display *dpy,
+ uint32_t width,
+ uint32_t height,
+ uint32_t depth)
+{
+ struct yagl_native_image *bi = dpy->create_image(dpy,
+ width,
+ height,
+ depth);
+
+ if (!bi) {
+ return NULL;
+ }
+
+ if (mlock(bi->pixels, bi->width * bi->height * bi->bpp) == -1) {
+ fprintf(stderr, "Critical error! Unable to lock YaGL bi memory: %s!\n", strerror(errno));
+ exit(1);
+ }
+
+ /*
+ * Probe in immediately.
+ */
+
+ yagl_mem_probe_write(bi->pixels, bi->width * bi->height * bi->bpp);
+
+ return bi;
+}
+
+static void yagl_offscreen_surface_destroy_bi(struct yagl_native_image *bi)
+{
+ if (munlock(bi->pixels, bi->width * bi->height * bi->bpp) == -1) {
+ fprintf(stderr, "Critical error! Unable to unlock YaGL bi memory: %s!\n", strerror(errno));
+ exit(1);
+ }
+
+ bi->destroy(bi);
+}
static int yagl_offscreen_surface_resize(struct yagl_offscreen_surface *surface)
{
int res = 0;
EGLBoolean retval = EGL_FALSE;
- unsigned int width = 0;
- unsigned int height = 0;
- unsigned int depth = 0;
- union { Window w; int i; unsigned int ui; } tmp_geom;
- struct yagl_bimage *bi = NULL;
+ uint32_t width = 0;
+ uint32_t height = 0;
+ uint32_t depth = 0;
+ struct yagl_native_image *bi = NULL;
YAGL_LOG_FUNC_SET(yagl_offscreen_surface_resize);
@@ -27,17 +69,10 @@ static int yagl_offscreen_surface_resize(struct yagl_offscreen_surface *surface)
return 1;
}
- memset(&tmp_geom, 0, sizeof(tmp_geom));
-
- XGetGeometry(surface->base.dpy->x_dpy,
- surface->base.x_drawable.win,
- &tmp_geom.w,
- &tmp_geom.i,
- &tmp_geom.i,
- &width,
- &height,
- &tmp_geom.ui,
- &depth);
+ surface->base.native_drawable->get_geometry(surface->base.native_drawable,
+ &width,
+ &height,
+ &depth);
if ((width != surface->bi->width) ||
(height != surface->bi->height) ||
@@ -50,17 +85,17 @@ static int yagl_offscreen_surface_resize(struct yagl_offscreen_surface *surface)
* First of all, create new backing image.
*/
- bi = yagl_bimage_create(surface->base.dpy, width, height, depth);
+ bi = yagl_offscreen_surface_create_bi(surface->base.dpy->native_dpy,
+ width, height, depth);
if (!bi) {
- YAGL_LOG_ERROR("yagl_bimage_create failed");
+ YAGL_LOG_ERROR("create_bi failed");
yagl_set_error(EGL_BAD_ALLOC);
goto out;
}
/*
* Tell the host that it should use new backing image from now on.
- * No need to probe in 'bi->pixels', it's already 'mlock'ed.
*/
YAGL_HOST_CALL_ASSERT(yagl_host_eglResizeOffscreenSurfaceYAGL(&retval,
@@ -82,7 +117,7 @@ static int yagl_offscreen_surface_resize(struct yagl_offscreen_surface *surface)
* we can safely replace surface's backing image with a new one.
*/
- yagl_bimage_destroy(surface->bi);
+ yagl_offscreen_surface_destroy_bi(surface->bi);
surface->bi = bi;
bi = NULL;
}
@@ -91,7 +126,7 @@ static int yagl_offscreen_surface_resize(struct yagl_offscreen_surface *surface)
out:
if (bi) {
- yagl_bimage_destroy(bi);
+ yagl_offscreen_surface_destroy_bi(bi);
}
return res;
@@ -129,37 +164,28 @@ static int yagl_offscreen_surface_swap_buffers(struct yagl_surface *sfc)
* Host has updated our image, update the window.
*/
- yagl_bimage_draw(osfc->bi, sfc->x_drawable.win, osfc->x_gc);
+ osfc->bi->draw(osfc->bi, sfc->native_drawable);
return 1;
}
static int yagl_offscreen_surface_copy_buffers(struct yagl_surface *sfc,
- Pixmap target)
+ yagl_os_pixmap target)
{
struct yagl_offscreen_surface *osfc = (struct yagl_offscreen_surface*)sfc;
EGLBoolean retval = EGL_FALSE;
- GC x_gc;
YAGL_LOG_FUNC_SET(eglCopyBuffers);
if (sfc->type == EGL_WINDOW_BIT) {
- unsigned int width = 0;
- unsigned int height = 0;
- unsigned int depth = 0;
- union { Window w; int i; unsigned int ui; } tmp_geom;
-
- memset(&tmp_geom, 0, sizeof(tmp_geom));
-
- XGetGeometry(sfc->dpy->x_dpy,
- sfc->x_drawable.win,
- &tmp_geom.w,
- &tmp_geom.i,
- &tmp_geom.i,
- &width,
- &height,
- &tmp_geom.ui,
- &depth);
+ uint32_t width = 0;
+ uint32_t height = 0;
+ uint32_t depth = 0;
+
+ sfc->native_drawable->get_geometry(sfc->native_drawable,
+ &width,
+ &height,
+ &depth);
if ((width != osfc->bi->width) ||
(height != osfc->bi->height) ||
@@ -186,20 +212,12 @@ static int yagl_offscreen_surface_copy_buffers(struct yagl_surface *sfc,
}
/*
- * Host has updated our image, update the surface.
+ * Host has updated our image, update the target.
*/
- x_gc = XCreateGC(sfc->dpy->x_dpy, target, 0, NULL);
+ osfc->bi->draw_to_pixmap(osfc->bi, target);
- if (x_gc) {
- yagl_bimage_draw(osfc->bi, target, x_gc);
- XFreeGC(sfc->dpy->x_dpy, x_gc);
- } else {
- YAGL_LOG_ERROR("XCreateGC failed");
- yagl_set_error(EGL_BAD_ALLOC);
- }
-
- return x_gc ? 1 : 0;
+ return 1;
}
static void yagl_offscreen_surface_wait_x(struct yagl_surface *sfc)
@@ -244,10 +262,8 @@ static void yagl_offscreen_surface_unmap(struct yagl_surface *sfc)
case EGL_PBUFFER_BIT:
break;
case EGL_WINDOW_BIT:
- yagl_bimage_draw(osfc->bi, sfc->x_drawable.win, osfc->x_gc);
- break;
case EGL_PIXMAP_BIT:
- yagl_bimage_draw(osfc->bi, sfc->x_drawable.pixmap, osfc->x_gc);
+ osfc->bi->draw(osfc->bi, sfc->native_drawable);
break;
default:
assert(0);
@@ -264,12 +280,7 @@ static void yagl_offscreen_surface_destroy(struct yagl_ref *ref)
{
struct yagl_offscreen_surface *sfc = (struct yagl_offscreen_surface*)ref;
- if (sfc->x_gc) {
- XFreeGC(sfc->base.dpy->x_dpy, sfc->x_gc);
- sfc->x_gc = 0;
- }
-
- yagl_bimage_destroy(sfc->bi);
+ yagl_offscreen_surface_destroy_bi(sfc->bi);
sfc->bi = NULL;
yagl_surface_cleanup(&sfc->base);
@@ -280,37 +291,29 @@ static void yagl_offscreen_surface_destroy(struct yagl_ref *ref)
struct yagl_offscreen_surface
*yagl_offscreen_surface_create_window(struct yagl_display *dpy,
yagl_host_handle host_config,
- Window x_win,
+ struct yagl_native_drawable *native_window,
const EGLint* attrib_list)
{
struct yagl_offscreen_surface *sfc;
- XWindowAttributes x_wa;
+ uint32_t width = 0;
+ uint32_t height = 0;
+ uint32_t depth = 0;
yagl_host_handle host_surface = 0;
- struct yagl_bimage *bi = NULL;
- GC x_gc = NULL;
+ struct yagl_native_image *bi = NULL;
YAGL_LOG_FUNC_SET(eglCreateWindowSurface);
sfc = yagl_malloc0(sizeof(*sfc));
- if (!XGetWindowAttributes(dpy->x_dpy, x_win, &x_wa)) {
- YAGL_LOG_ERROR("XGetWindowAttributes failed");
- yagl_set_error(EGL_BAD_NATIVE_WINDOW);
- goto fail;
- }
+ native_window->get_geometry(native_window,
+ &width,
+ &height,
+ &depth);
- bi = yagl_bimage_create(dpy, x_wa.width, x_wa.height, x_wa.depth);
+ bi = yagl_offscreen_surface_create_bi(dpy->native_dpy, width, height, depth);
if (!bi) {
- YAGL_LOG_ERROR("yagl_bimage_create failed");
- yagl_set_error(EGL_BAD_ALLOC);
- goto fail;
- }
-
- x_gc = XCreateGC(dpy->x_dpy, x_win, 0, NULL);
-
- if (!x_gc) {
- YAGL_LOG_ERROR("XCreateGC failed");
+ YAGL_LOG_ERROR("create_bi failed");
yagl_set_error(EGL_BAD_ALLOC);
goto fail;
}
@@ -334,7 +337,7 @@ struct yagl_offscreen_surface
&yagl_offscreen_surface_destroy,
host_surface,
dpy,
- x_win);
+ native_window);
sfc->base.invalidate = &yagl_offscreen_surface_invalidate;
sfc->base.finish = &yagl_offscreen_surface_finish;
@@ -347,17 +350,15 @@ struct yagl_offscreen_surface
sfc->base.set_swap_interval = &yagl_offscreen_surface_set_swap_interval;
sfc->bi = bi;
- sfc->x_gc = x_gc;
return sfc;
fail:
if (bi) {
- yagl_bimage_destroy(bi);
- }
- if (x_gc) {
- XFreeGC(dpy->x_dpy, x_gc);
+ yagl_offscreen_surface_destroy_bi(bi);
+ bi = NULL;
}
+
yagl_free(sfc);
return NULL;
@@ -366,46 +367,29 @@ fail:
struct yagl_offscreen_surface
*yagl_offscreen_surface_create_pixmap(struct yagl_display *dpy,
yagl_host_handle host_config,
- Pixmap x_pixmap,
+ struct yagl_native_drawable *native_pixmap,
const EGLint* attrib_list)
{
struct yagl_offscreen_surface *sfc;
- unsigned int width = 0;
- unsigned int height = 0;
- unsigned int depth = 0;
- union { Window w; int i; unsigned int ui; } tmp_geom;
+ uint32_t width = 0;
+ uint32_t height = 0;
+ uint32_t depth = 0;
yagl_host_handle host_surface = 0;
- struct yagl_bimage *bi = NULL;
- GC x_gc = NULL;
+ struct yagl_native_image *bi = NULL;
YAGL_LOG_FUNC_SET(eglCreatePixmapSurface);
sfc = yagl_malloc0(sizeof(*sfc));
- memset(&tmp_geom, 0, sizeof(tmp_geom));
+ native_pixmap->get_geometry(native_pixmap,
+ &width,
+ &height,
+ &depth);
- XGetGeometry(dpy->x_dpy,
- x_pixmap,
- &tmp_geom.w,
- &tmp_geom.i,
- &tmp_geom.i,
- &width,
- &height,
- &tmp_geom.ui,
- &depth);
-
- bi = yagl_bimage_create(dpy, width, height, depth);
+ bi = yagl_offscreen_surface_create_bi(dpy->native_dpy, width, height, depth);
if (!bi) {
- YAGL_LOG_ERROR("yagl_bimage_create failed");
- yagl_set_error(EGL_BAD_ALLOC);
- goto fail;
- }
-
- x_gc = XCreateGC(dpy->x_dpy, x_pixmap, 0, NULL);
-
- if (!x_gc) {
- YAGL_LOG_ERROR("XCreateGC failed");
+ YAGL_LOG_ERROR("create_bi failed");
yagl_set_error(EGL_BAD_ALLOC);
goto fail;
}
@@ -429,7 +413,7 @@ struct yagl_offscreen_surface
&yagl_offscreen_surface_destroy,
host_surface,
dpy,
- x_pixmap);
+ native_pixmap);
sfc->base.invalidate = &yagl_offscreen_surface_invalidate;
sfc->base.finish = &yagl_offscreen_surface_finish;
@@ -442,17 +426,15 @@ struct yagl_offscreen_surface
sfc->base.set_swap_interval = &yagl_offscreen_surface_set_swap_interval;
sfc->bi = bi;
- sfc->x_gc = x_gc;
return sfc;
fail:
if (bi) {
- yagl_bimage_destroy(bi);
- }
- if (x_gc) {
- XFreeGC(dpy->x_dpy, x_gc);
+ yagl_offscreen_surface_destroy_bi(bi);
+ bi = NULL;
}
+
yagl_free(sfc);
return NULL;
@@ -467,7 +449,7 @@ struct yagl_offscreen_surface
uint32_t width = 0;
uint32_t height = 0;
yagl_host_handle host_surface = 0;
- struct yagl_bimage *bi = NULL;
+ struct yagl_native_image *bi = NULL;
int i = 0;
YAGL_LOG_FUNC_SET(eglCreatePbufferSurface);
@@ -491,10 +473,10 @@ struct yagl_offscreen_surface
}
}
- bi = yagl_bimage_create(dpy, width, height, 24);
+ bi = yagl_offscreen_surface_create_bi(dpy->native_dpy, width, height, 24);
if (!bi) {
- YAGL_LOG_ERROR("yagl_bimage_create failed");
+ YAGL_LOG_ERROR("create_bi failed");
yagl_set_error(EGL_BAD_ALLOC);
goto fail;
}
@@ -535,8 +517,10 @@ struct yagl_offscreen_surface
fail:
if (bi) {
- yagl_bimage_destroy(bi);
+ yagl_offscreen_surface_destroy_bi(bi);
+ bi = NULL;
}
+
yagl_free(sfc);
return NULL;