[Libva] [PATCH 07/16] test: simplify va display construction
Zhao Halley
halley.zhao at intel.com
Tue Jun 5 02:06:55 PDT 2012
From: Gwenole Beauchesne <gwenole.beauchesne at intel.com>
---
configure.ac | 1 +
test/Makefile.am | 2 +-
test/common/Makefile.am | 48 +++++++++++++++
test/common/va_display.c | 89 ++++++++++++++++++++++++++++
test/common/va_display.h | 60 +++++++++++++++++++
test/common/va_display_android.cpp | 90 ++++++++++++++++++++++++++++
test/common/va_display_x11.c | 113 ++++++++++++++++++++++++++++++++++++
test/decode/Android.mk | 4 +-
test/decode/Makefile.am | 28 +++++++--
test/decode/mpeg2vldemo.cpp | 84 +++++---------------------
test/decode/tinyjpeg.c | 41 +++++---------
test/vainfo/Android.mk | 4 +-
test/vainfo/Makefile.am | 26 ++++++--
test/vainfo/vainfo.c | 28 +--------
14 files changed, 483 insertions(+), 135 deletions(-)
mode change 100644 => 100755 test/Makefile.am
create mode 100644 test/common/Makefile.am
create mode 100644 test/common/va_display.c
create mode 100644 test/common/va_display.h
create mode 100644 test/common/va_display_android.cpp
create mode 100644 test/common/va_display_x11.c
mode change 100644 => 100755 test/decode/Makefile.am
mode change 100644 => 100755 test/decode/mpeg2vldemo.cpp
mode change 100644 => 100755 test/decode/tinyjpeg.c
mode change 100644 => 100755 test/vainfo/Android.mk
mode change 100644 => 100755 test/vainfo/Makefile.am
mode change 100644 => 100755 test/vainfo/vainfo.c
diff --git a/configure.ac b/configure.ac
index 2762c4e..c58f923 100755
--- a/configure.ac
+++ b/configure.ac
@@ -265,6 +265,7 @@ AC_OUTPUT([
pkgconfig/libva.pc
test/Makefile
test/basic/Makefile
+ test/common/Makefile
test/decode/Makefile
test/encode/Makefile
test/putsurface/Makefile
diff --git a/test/Makefile.am b/test/Makefile.am
old mode 100644
new mode 100755
index ad95136..ae3805f
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -23,6 +23,6 @@
AM_CFLAGS = -I$(top_srcdir)/va -I$(top_srcdir)/test/basic -I$(top_srcdir)/src/x11
-SUBDIRS = basic decode encode putsurface vainfo transcode
+SUBDIRS = common basic decode encode putsurface vainfo transcode
EXTRA_DIST = loadsurface.h loadsurface_yuv.h
diff --git a/test/common/Makefile.am b/test/common/Makefile.am
new file mode 100644
index 0000000..c348fd7
--- /dev/null
+++ b/test/common/Makefile.am
@@ -0,0 +1,48 @@
+# Copyright (c) 2012 Intel Corporation. All Rights Reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sub license, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice (including the
+# next paragraph) shall be included in all copies or substantial portions
+# of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+# IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+noinst_LTLIBRARIES = libva-display.la
+
+libva_display_cflags = \
+ -I$(top_srcdir) \
+ -I$(top_builddir) \
+ $(NULL)
+
+libva_display_libs = \
+ $(top_builddir)/va/$(libvacorelib) \
+ $(top_builddir)/va/$(libvabackendlib) \
+ $(NULL)
+
+source_c = va_display.c
+source_h = va_display.h
+
+source_c += va_display_x11.c
+libva_display_cflags += $(X11_CFLAGS)
+libva_display_libs += $(X11_LIBS)
+
+libva_display_la_SOURCES= $(source_c)
+noinst_HEADERS = $(source_h)
+libva_display_la_CFLAGS = $(libva_display_cflags)
+libva_display_la_LIBADD = $(libva_display_libs)
+
+# Extra clean files so that maintainer-clean removes *everything*
+MAINTAINERCLEANFILES = Makefile.in
diff --git a/test/common/va_display.c b/test/common/va_display.c
new file mode 100644
index 0000000..dd560c8
--- /dev/null
+++ b/test/common/va_display.c
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2012 Intel Corporation. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+#include <stddef.h>
+#include <va/va.h>
+#include "va_display.h"
+
+#ifdef ANDROID
+extern const VADisplayHooks va_display_hooks_android;
+#else
+extern const VADisplayHooks va_display_hooks_x11;
+#endif
+
+static const VADisplayHooks *g_display_hooks;
+static const VADisplayHooks *g_display_hooks_available[] = {
+#ifdef ANDROID
+ &va_display_hooks_android,
+#else
+ &va_display_hooks_x11,
+#endif
+ NULL
+};
+
+VADisplay
+va_open_display(void)
+{
+ VADisplay va_dpy = NULL;
+ unsigned int i;
+
+ for (i = 0; !va_dpy && g_display_hooks_available[i]; i++) {
+ g_display_hooks = g_display_hooks_available[i];
+ if (!g_display_hooks->open_display)
+ continue;
+ va_dpy = g_display_hooks->open_display();
+ }
+ /* XXX: perform vaInitalize() in vainfo.c so that to get more
+ information and debug tools */
+ return va_dpy;
+}
+
+void
+va_close_display(VADisplay va_dpy)
+{
+ if (!va_dpy)
+ return;
+
+ vaTerminate(va_dpy);
+
+ if (g_display_hooks && g_display_hooks->close_display)
+ g_display_hooks->close_display(va_dpy);
+}
+
+VAStatus
+va_put_surface(
+ VADisplay va_dpy,
+ VASurfaceID surface,
+ const VARectangle *src_rect,
+ const VARectangle *dst_rect
+)
+{
+ if (!va_dpy)
+ return VA_STATUS_ERROR_INVALID_DISPLAY;
+
+ if (g_display_hooks && g_display_hooks->put_surface)
+ return g_display_hooks->put_surface(va_dpy, surface, src_rect, dst_rect);
+ return VA_STATUS_ERROR_UNIMPLEMENTED;
+}
diff --git a/test/common/va_display.h b/test/common/va_display.h
new file mode 100644
index 0000000..12992f5
--- /dev/null
+++ b/test/common/va_display.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2012 Intel Corporation. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef VA_DISPLAY_H
+#define VA_DISPLAY_H
+
+#include <va/va.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct {
+ VADisplay (*open_display) (void);
+ void (*close_display) (VADisplay va_dpy);
+ VAStatus (*put_surface) (VADisplay va_dpy, VASurfaceID surface,
+ const VARectangle *src_rect,
+ const VARectangle *dst_rect);
+} VADisplayHooks;
+
+VADisplay
+va_open_display(void);
+
+void
+va_close_display(VADisplay va_dpy);
+
+VAStatus
+va_put_surface(
+ VADisplay va_dpy,
+ VASurfaceID surface,
+ const VARectangle *src_rect,
+ const VARectangle *dst_rect
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* VA_DISPLAY_H */
diff --git a/test/common/va_display_android.cpp b/test/common/va_display_android.cpp
new file mode 100644
index 0000000..33b510d
--- /dev/null
+++ b/test/common/va_display_android.cpp
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2012 Intel Corporation. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <va/va_android.h>
+#include "va_display.h"
+
+#include <binder/IPCThreadState.h>
+#include <binder/ProcessState.h>
+#include <binder/IServiceManager.h>
+#include <utils/Log.h>
+#include <surfaceflinger/ISurfaceComposer.h>
+#include <surfaceflinger/Surface.h>
+#include <surfaceflinger/ISurface.h>
+#include <surfaceflinger/SurfaceComposerClient.h>
+#include <binder/MemoryHeapBase.h>
+
+static unsigned int fake_display = 0xdeada01d;
+
+using namespace android;
+sp<SurfaceComposerClient> client;
+sp<Surface> android_surface;
+sp<ISurface> android_isurface;
+sp<SurfaceControl> surface_ctrl;
+#include "../android_winsys.cpp"
+
+static VADisplay
+va_open_display_android(void)
+{
+ return vaGetDisplay(&fake_display);
+}
+
+static void
+va_close_display_android(VADisplay va_dpy)
+{
+}
+
+static VAStatus
+va_put_surface_android(
+ VADisplay va_dpy,
+ VASurfaceID surface,
+ const VARectangle *src_rect,
+ const VARectangle *dst_rect
+)
+{
+ sp<ProcessState> proc(ProcessState::self());
+ ProcessState::self()->startThreadPool();
+
+ printf("Create window0 for thread0\n");
+ SURFACE_CREATE(
+ client,
+ surface_ctrl,
+ android_surface,
+ android_isurface,
+ dst_rect->x, dst_rect->y, dst_rect->width, dst_rect->height);
+
+ return vaPutSurface(va_dpy, surface, android_isurface,
+ src_rect->x, src_rect->y,
+ src_rect->width, src_rect->height,
+ dst_rect->x, dst_rect->y,
+ dst_rect->width, dst_rect->height,
+ NULL, 0,
+ VA_FRAME_PICTURE);
+}
+
+const VADisplayHooks va_display_hooks_android = {
+ va_open_display_android,
+ va_close_display_android,
+ va_put_surface_android
+};
diff --git a/test/common/va_display_x11.c b/test/common/va_display_x11.c
new file mode 100644
index 0000000..ef81fec
--- /dev/null
+++ b/test/common/va_display_x11.c
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2012 Intel Corporation. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <va/va_x11.h>
+#include "va_display.h"
+
+static Display *x11_display;
+static Window x11_window;
+
+static VADisplay
+va_open_display_x11(void)
+{
+ x11_display = XOpenDisplay(NULL);
+ if (!x11_display)
+ return NULL;
+ return vaGetDisplay(x11_display);
+}
+
+static void
+va_close_display_x11(VADisplay va_dpy)
+{
+ if (!x11_display)
+ return;
+
+ if (x11_window) {
+ XUnmapWindow(x11_display, x11_window);
+ XDestroyWindow(x11_display, x11_window);
+ x11_window = None;
+ }
+ XCloseDisplay(x11_display);
+ x11_display = NULL;
+}
+
+static int
+ensure_window(unsigned int width, unsigned int height)
+{
+ Window win, rootwin;
+ unsigned int black_pixel, white_pixel;
+ int screen;
+
+ if (!x11_display)
+ return 0;
+
+ if (x11_window) {
+ XResizeWindow(x11_display, x11_window, width, height);
+ return 1;
+ }
+
+ screen = DefaultScreen(x11_display);
+ rootwin = RootWindow(x11_display, screen);
+ black_pixel = BlackPixel(x11_display, screen);
+ white_pixel = WhitePixel(x11_display, screen);
+
+ win = XCreateSimpleWindow(
+ x11_display,
+ rootwin,
+ 0, 0, width, height,
+ 1, black_pixel, white_pixel
+ );
+ if (!win)
+ return 0;
+ x11_window = win;
+
+ XMapWindow(x11_display, x11_window);
+ XSync(x11_display, False);
+ return 1;
+}
+
+static VAStatus
+va_put_surface_x11(
+ VADisplay va_dpy,
+ VASurfaceID surface,
+ const VARectangle *src_rect,
+ const VARectangle *dst_rect
+)
+{
+ if (!ensure_window(dst_rect->width, dst_rect->height))
+ return VA_STATUS_ERROR_ALLOCATION_FAILED;
+ return vaPutSurface(va_dpy, surface, x11_window,
+ src_rect->x, src_rect->y,
+ src_rect->width, src_rect->height,
+ dst_rect->x, dst_rect->y,
+ dst_rect->width, dst_rect->height,
+ NULL, 0,
+ VA_FRAME_PICTURE);
+}
+
+const VADisplayHooks va_display_hooks_x11 = {
+ va_open_display_x11,
+ va_close_display_x11,
+ va_put_surface_x11,
+};
diff --git a/test/decode/Android.mk b/test/decode/Android.mk
index 3541ee2..cbbd007 100755
--- a/test/decode/Android.mk
+++ b/test/decode/Android.mk
@@ -6,7 +6,9 @@ LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
- mpeg2vldemo.cpp \
+ mpeg2vldemo.cpp \
+ ../common/va_display.c \
+ ../common/va_display_android.cpp
LOCAL_CFLAGS += \
-DANDROID
diff --git a/test/decode/Makefile.am b/test/decode/Makefile.am
old mode 100644
new mode 100755
index c1d3798..7637c4b
--- a/test/decode/Makefile.am
+++ b/test/decode/Makefile.am
@@ -22,15 +22,31 @@
bin_PROGRAMS = mpeg2vldemo loadjpeg
-INCLUDES = -I$(top_srcdir)
+libva_helpers = \
+ $(top_builddir)/test/common/libva-display.la \
+ $(NULL)
-TEST_LIBS = $(top_builddir)/va/$(libvabackendlib) $(top_builddir)/va/$(libvacorelib) -lX11
+INCLUDES = \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/test/common \
+ $(NULL)
-mpeg2vldemo_LDADD = $(TEST_LIBS)
-mpeg2vldemo_SOURCES = mpeg2vldemo.cpp
+TEST_LIBS = \
+ $(top_builddir)/va/$(libvabackendlib) \
+ $(top_builddir)/va/$(libvacorelib) \
+ $(libva_helpers) \
+ $(NULL)
-loadjpeg_LDADD = $(TEST_LIBS)
-loadjpeg_SOURCES = loadjpeg.c tinyjpeg.c
+INCLUDES += $(X11_CFLAGS)
+TEST_LIBS += $(X11_LIBS)
+
+mpeg2vldemo_LDADD = $(TEST_LIBS)
+mpeg2vldemo_SOURCES = mpeg2vldemo.cpp
+mpeg2vldemo_DEPENDENCIES = $(libva_helpers)
+
+loadjpeg_LDADD = $(TEST_LIBS)
+loadjpeg_SOURCES = loadjpeg.c tinyjpeg.c
+loadjpeg_DEPENDENCIES = $(libva_helpers)
valgrind: $(bin_PROGRAMS)
for a in $(bin_PROGRAMS); do \
diff --git a/test/decode/mpeg2vldemo.cpp b/test/decode/mpeg2vldemo.cpp
old mode 100644
new mode 100755
index 9246dfe..cb66a68
--- a/test/decode/mpeg2vldemo.cpp
+++ b/test/decode/mpeg2vldemo.cpp
@@ -43,30 +43,7 @@
#include <fcntl.h>
#include <assert.h>
#include <va/va.h>
-
-#ifdef ANDROID
-#include <va/va_android.h>
-#include <binder/IPCThreadState.h>
-#include <binder/ProcessState.h>
-#include <binder/IServiceManager.h>
-#include <utils/Log.h>
-#include <surfaceflinger/ISurfaceComposer.h>
-#include <surfaceflinger/Surface.h>
-#include <surfaceflinger/ISurface.h>
-#include <surfaceflinger/SurfaceComposerClient.h>
-#include <binder/MemoryHeapBase.h>
-#define Display unsigned int
-
-using namespace android;
-sp<SurfaceComposerClient> client;
-sp<Surface> android_surface;
-sp<ISurface> android_isurface;
-sp<SurfaceControl> surface_ctrl;
-#include "../android_winsys.cpp"
-#else
-#include <va/va_x11.h>
-#include <X11/Xlib.h>
-#endif
+#include "va_display.h"
#define CHECK_VASTATUS(va_status,func) \
if (va_status != VA_STATUS_SUCCESS) { \
@@ -169,28 +146,14 @@ int main(int argc,char **argv)
VAContextID context_id;
VABufferID pic_param_buf,iqmatrix_buf,slice_param_buf,slice_data_buf;
int major_ver, minor_ver;
- Display *x11_display;
VADisplay va_dpy;
VAStatus va_status;
int putsurface=0;
if (argc > 1)
putsurface=1;
-#ifdef ANDROID
- x11_display = (Display*)malloc(sizeof(Display));
- *(x11_display ) = 0x18c34078;
-#else
- x11_display = XOpenDisplay(":0.0");
-#endif
-
- if (x11_display == NULL) {
- fprintf(stderr, "Can't connect X server!\n");
- exit(-1);
- }
-
- assert(x11_display);
- va_dpy = vaGetDisplay(x11_display);
+ va_dpy = va_open_display();
va_status = vaInitialize(va_dpy, &major_ver, &minor_ver);
assert(va_status == VA_STATUS_SUCCESS);
@@ -226,6 +189,7 @@ int main(int argc,char **argv)
&surface_id, 1,
NULL, 0
);
+
CHECK_VASTATUS(va_status, "vaCreateSurfaces");
/* Create a context for this decode pipe */
@@ -289,29 +253,20 @@ int main(int argc,char **argv)
CHECK_VASTATUS(va_status, "vaSyncSurface");
if (putsurface) {
-#ifdef ANDROID
- sp<ProcessState> proc(ProcessState::self());
- ProcessState::self()->startThreadPool();
+ VARectangle src_rect, dst_rect;
- printf("Create window0 for thread0\n");
- SURFACE_CREATE(client,surface_ctrl,android_surface, android_isurface, 0, 0, WIN_WIDTH, WIN_HEIGHT);
+ src_rect.x = 0;
+ src_rect.y = 0;
+ src_rect.width = CLIP_WIDTH;
+ src_rect.height = CLIP_HEIGHT;
- va_status = vaPutSurface(va_dpy, surface_id, android_isurface,
- 0,0,CLIP_WIDTH,CLIP_HEIGHT,
- 0,0,WIN_WIDTH,WIN_HEIGHT,
- NULL,0,0);
-#else
- Window win;
- win = XCreateSimpleWindow(x11_display, RootWindow(x11_display, 0), 0, 0,
- WIN_WIDTH,WIN_HEIGHT, 0, 0, WhitePixel(x11_display, 0));
- XMapWindow(x11_display, win);
- XSync(x11_display, False);
- va_status = vaPutSurface(va_dpy, surface_id, win,
- 0,0,CLIP_WIDTH,CLIP_HEIGHT,
- 0,0,WIN_WIDTH,WIN_HEIGHT,
- NULL,0,0);
-#endif
- CHECK_VASTATUS(va_status, "vaPutSurface");
+ dst_rect.x = 0;
+ dst_rect.y = 0;
+ dst_rect.width = WIN_WIDTH;
+ dst_rect.height = WIN_HEIGHT;
+
+ va_status = va_put_surface(va_dpy, surface_id, &src_rect, &dst_rect);
+ CHECK_VASTATUS(va_status, "vaPutSurface");
}
printf("press any key to exit\n");
getchar();
@@ -319,13 +274,6 @@ int main(int argc,char **argv)
vaDestroySurfaces(va_dpy,&surface_id,1);
vaDestroyConfig(va_dpy,config_id);
vaDestroyContext(va_dpy,context_id);
-
- vaTerminate(va_dpy);
-#ifdef ANDROID
- free(x11_display);
-#else
- XCloseDisplay(x11_display);
-#endif
-
+ va_close_display(va_dpy);
return 0;
}
diff --git a/test/decode/tinyjpeg.c b/test/decode/tinyjpeg.c
old mode 100644
new mode 100755
index fe9435b..8b82b55
--- a/test/decode/tinyjpeg.c
+++ b/test/decode/tinyjpeg.c
@@ -49,8 +49,8 @@
#include <assert.h>
#include <va/va.h>
#include <va/va_dec_jpeg.h>
-#include <va/va_x11.h>
-#include <X11/Xlib.h>
+#include "va_display.h"
+
#define cY 0
@@ -542,23 +542,13 @@ int tinyjpeg_decode(struct jdec_private *priv)
VAContextID context_id;
VABufferID pic_param_buf,iqmatrix_buf,huffmantable_buf,slice_param_buf,slice_data_buf;
int major_ver, minor_ver;
- Display *x11_display;
VADisplay va_dpy;
VAStatus va_status;
int max_h_factor, max_v_factor;
int putsurface=1;
unsigned int i, j;
- x11_display = XOpenDisplay(":0.0");
-
- if (x11_display == NULL) {
- fprintf(stderr, "Can't connect X server!\n");
- exit(-1);
- }
-
- assert(x11_display);
-
- va_dpy = vaGetDisplay(x11_display);
+ va_dpy = va_open_display();
va_status = vaInitialize(va_dpy, &major_ver, &minor_ver);
assert(va_status == VA_STATUS_SUCCESS);
@@ -737,16 +727,16 @@ int tinyjpeg_decode(struct jdec_private *priv)
CHECK_VASTATUS(va_status, "vaSyncSurface");
if (putsurface) {
- Window win;
- win = XCreateSimpleWindow(x11_display, RootWindow(x11_display, 0), 0, 0,
- priv->width,priv->height, 0, 0, WhitePixel(x11_display, 0));
- XMapWindow(x11_display, win);
- XSync(x11_display, False);
- va_status = vaPutSurface(va_dpy, surface_id, win,
- 0,0,priv->width,priv->height,
- 0,0,priv->width,priv->height,
- NULL,0,0);
- CHECK_VASTATUS(va_status, "vaPutSurface");
+ VARectangle src_rect, dst_rect;
+
+ src_rect.x = 0;
+ src_rect.y = 0;
+ src_rect.width = priv->width;
+ src_rect.height = priv->height;
+ dst_rect = src_rect;
+
+ va_status = va_put_surface(va_dpy, surface_id, &src_rect, &dst_rect);
+ CHECK_VASTATUS(va_status, "vaPutSurface");
}
printf("press any key to exit\n");
getchar();
@@ -754,10 +744,7 @@ int tinyjpeg_decode(struct jdec_private *priv)
vaDestroySurfaces(va_dpy,&surface_id,1);
vaDestroyConfig(va_dpy,config_id);
vaDestroyContext(va_dpy,context_id);
-
- vaTerminate(va_dpy);
- XCloseDisplay(x11_display);
-
+ va_close_display(va_dpy);
return 0;
}
const char *tinyjpeg_get_errorstring(struct jdec_private *priv)
diff --git a/test/vainfo/Android.mk b/test/vainfo/Android.mk
old mode 100644
new mode 100755
index 0aac2cf..91ea526
--- a/test/vainfo/Android.mk
+++ b/test/vainfo/Android.mk
@@ -6,7 +6,9 @@ LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
- vainfo.c
+ vainfo.c \
+ ../common/va_display.c \
+ ../common/va_display_android.cpp
LOCAL_CFLAGS += \
-DANDROID
diff --git a/test/vainfo/Makefile.am b/test/vainfo/Makefile.am
old mode 100644
new mode 100755
index 190aa8b..e0db1a3
--- a/test/vainfo/Makefile.am
+++ b/test/vainfo/Makefile.am
@@ -20,18 +20,30 @@
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
bin_PROGRAMS = vainfo
-INCLUDES = \
- -I$(top_srcdir) \
- -I$(top_srcdir)/test/basic \
- -DLIBVA_VERSION_S="\"${LIBVA_VERSION}\"" \
+libva_helpers = \
+ $(top_builddir)/test/common/libva-display.la \
+ $(NULL)
+
+vainfo_cflags = \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/test/common \
+ -I$(top_builddir) \
+ -DLIBVA_VERSION_S="\"$(LIBVA_VERSION)\"" \
$(NULL)
-vainfo_LDADD = $(top_builddir)/va/$(libvacorelib) $(top_builddir)/va/$(libvabackendlib) -lX11
+vainfo_libs = \
+ $(top_builddir)/va/$(libvacorelib) \
+ $(top_builddir)/va/$(libvabackendlib) \
+ $(libva_helpers) \
+ $(NULL)
-vainfo_DEPENDENCIES = $(top_builddir)/va/$(libvacorelib) $(top_builddir)/va/$(libvabackendlib)
+vainfo_SOURCES = vainfo.c
+noinst_HEADERS = $(source_h)
+vainfo_CFLAGS = $(vainfo_cflags)
+vainfo_LDADD = $(vainfo_libs)
+vainfo_DEPENDENCIES = $(libva_helpers)
valgrind: vainfo
valgrind --leak-check=full --show-reachable=yes .libs/vainfo;
diff --git a/test/vainfo/vainfo.c b/test/vainfo/vainfo.c
old mode 100644
new mode 100755
index c386b5e..40030fe
--- a/test/vainfo/vainfo.c
+++ b/test/vainfo/vainfo.c
@@ -22,18 +22,11 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#ifndef ANDROID
-#include <va/va_x11.h>
-#else
-#include "va/va_android.h"
-#define Display unsigned int
-#endif
-
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-
+#include "va_display.h"
#define CHECK_VASTATUS(va_status,func, ret) \
if (va_status != VA_STATUS_SUCCESS) { \
@@ -85,12 +78,10 @@ static char * entrypoint_string(VAEntrypoint entrypoint)
int main(int argc, const char* argv[])
{
- Display *dpy;
VADisplay va_dpy;
VAStatus va_status;
int major_version, minor_version;
const char *driver;
- const char *display = getenv("DISPLAY");
const char *name = strrchr(argv[0], '/');
VAProfile profile;
VAEntrypoint entrypoint, entrypoints[10];
@@ -101,18 +92,7 @@ int main(int argc, const char* argv[])
else
name = argv[0];
-#ifndef ANDROID
- dpy = XOpenDisplay(NULL);
-#else
- dpy = (Display*)malloc(sizeof(Display));
-#endif
- if (NULL == dpy)
- {
- fprintf(stderr, "%s: Error, can't open display: '%s'\n", name, display ? display : "");
- return 1;
- }
-
- va_dpy = vaGetDisplay(dpy);
+ va_dpy = va_open_display();
if (NULL == va_dpy)
{
fprintf(stderr, "%s: vaGetDisplay() failed\n", name);
@@ -143,8 +123,8 @@ int main(int argc, const char* argv[])
for (entrypoint = 0; entrypoint < num_entrypoint; entrypoint++)
printf(" %-32s: %s\n", profile_str, entrypoint_string(entrypoints[entrypoint]));
}
-
- vaTerminate(va_dpy);
+
+ va_close_display(va_dpy);
return 0;
}
--
1.7.5.4
More information about the Libva
mailing list