Commit 20574567 authored by Austin Yuan's avatar Austin Yuan

test/putsurface: more cleanup, remove #ifdef ANDROID from putsurface_common.c

Signed-off-by: default avatarAustin Yuan <shengquan.yuan@gmail.com>
parent 2f5f0962
...@@ -9,7 +9,7 @@ namespace android { ...@@ -9,7 +9,7 @@ namespace android {
}; };
#define SURFACE_CREATE(client,surface_ctrl,android_surface, android_isurface, win_width, win_height) \ #define SURFACE_CREATE(client,surface_ctrl,android_surface, android_isurface, win_width, win_height) \
{\ do {\
client = new SurfaceComposerClient();\ client = new SurfaceComposerClient();\
surface_ctrl = client->createSurface(getpid(), 0, win_width, win_height, PIXEL_FORMAT_RGB_565, ISurfaceComposer::ePushBuffers);\ surface_ctrl = client->createSurface(getpid(), 0, win_width, win_height, PIXEL_FORMAT_RGB_565, ISurfaceComposer::ePushBuffers);\
android_surface = surface_ctrl->getSurface();\ android_surface = surface_ctrl->getSurface();\
...@@ -27,6 +27,6 @@ namespace android { ...@@ -27,6 +27,6 @@ namespace android {
surface_ctrl->setLayer(0x100000);\ surface_ctrl->setLayer(0x100000);\
client->closeTransaction();\ client->closeTransaction();\
\ \
}\ } while (0) \
...@@ -77,7 +77,6 @@ static int display_surface(int frame_id, int *exit_encode); ...@@ -77,7 +77,6 @@ static int display_surface(int frame_id, int *exit_encode);
static int upload_source_YUV_once_for_all() static int upload_source_YUV_once_for_all()
{ {
VAImage surface_image;
void *surface_p=NULL, *U_start,*V_start; void *surface_p=NULL, *U_start,*V_start;
VAStatus va_status; VAStatus va_status;
int box_width=8; int box_width=8;
......
...@@ -36,9 +36,7 @@ ...@@ -36,9 +36,7 @@
#include <assert.h> #include <assert.h>
#include <pthread.h> #include <pthread.h>
#define Display unsigned int static int android_display=0;
static int win_thread0 = 0, win_thread1 = 0;
static int multi_thread = 0;
using namespace android; using namespace android;
#include "../android_winsys.cpp" #include "../android_winsys.cpp"
...@@ -53,8 +51,25 @@ sp<Surface> android_surface1; ...@@ -53,8 +51,25 @@ sp<Surface> android_surface1;
sp<ISurface> android_isurface1; sp<ISurface> android_isurface1;
sp<SurfaceControl> surface_ctrl1; sp<SurfaceControl> surface_ctrl1;
static void *open_display(void);
static void close_display(void *win_display);
static int create_window(void *win_display, int width, int height);
static int check_window_event(void *x11_display, void *win, int *width, int *height, int *quit);
static int create_window(int width, int height) #define CAST_DRAWABLE(a) static_cast<ISurface*>((void *)(*(unsigned int *)a))
#include "putsurface_common.c"
static void *open_display()
{
return &android_display;
}
static void close_display(void *win_display)
{
return;
}
static int create_window(void *win_display, int width, int height)
{ {
sp<ProcessState> proc(ProcessState::self()); sp<ProcessState> proc(ProcessState::self());
ProcessState::self()->startThreadPool(); ProcessState::self()->startThreadPool();
...@@ -62,16 +77,21 @@ static int create_window(int width, int height) ...@@ -62,16 +77,21 @@ static int create_window(int width, int height)
printf("Create window0 for thread0\n"); printf("Create window0 for thread0\n");
SURFACE_CREATE(client,surface_ctrl,android_surface, android_isurface, width, height); SURFACE_CREATE(client,surface_ctrl,android_surface, android_isurface, width, height);
win_thread0 = 1; drawable_thread0 = static_cast<void*>(&android_isurface);
if (multi_thread == 0) if (multi_thread == 0)
return 0; return 0;
printf("Create window1 for thread1\n"); printf("Create window1 for thread1\n");
/* need to modify here jgl*/ /* need to modify here jgl*/
SURFACE_CREATE(client1,surface_ctrl1,android_surface1, android_isurface1, width, height); SURFACE_CREATE(client1,surface_ctrl1,android_surface1, android_isurface1, width, height);
drawable_thread1 = static_cast<void *>(&android_isurface);
win_thread1 = 2;
return 0; return 0;
} }
#include "putsurface_common.c" int check_window_event(void *win_display, void *drawble, int *width, int *height, int *quit)
{
return 0;
}
...@@ -22,8 +22,6 @@ ...@@ -22,8 +22,6 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -36,13 +34,6 @@ ...@@ -36,13 +34,6 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <va/va.h>
#ifdef ANDROID
#include <va/va_android.h>
#else
#include <va/va_x11.h>
#endif
#include <assert.h> #include <assert.h>
#include <pthread.h> #include <pthread.h>
...@@ -64,25 +55,25 @@ if (va_status != VA_STATUS_SUCCESS) { \ ...@@ -64,25 +55,25 @@ if (va_status != VA_STATUS_SUCCESS) { \
} }
#include "../loadsurface.h" #include "../loadsurface.h"
#define SURFACE_NUM 5 #define SURFACE_NUM 16
static void *win_display;
static VADisplay va_dpy;
static VASurfaceID surface_id[SURFACE_NUM]; static VASurfaceID surface_id[SURFACE_NUM];
static pthread_mutex_t surface_mutex[SURFACE_NUM];
static void *drawable_thread0, *drawable_thread1;
static int surface_width = 352, surface_height = 288; static int surface_width = 352, surface_height = 288;
static int win_width=352, win_height=288; static int win_width=352, win_height=288;
static Display *x11_display; static unsigned long long frame_num_total = ~0;
static VADisplay va_dpy;
static int check_event = 1; static int check_event = 1;
static int put_pixmap = 0; static int put_pixmap = 0;
static int test_clip = 0; static int test_clip = 0;
static int display_field = VA_FRAME_PICTURE; static int display_field = VA_FRAME_PICTURE;
static int verbose = 0;
static pthread_mutex_t surface_mutex[SURFACE_NUM];
static pthread_mutex_t gmutex; static pthread_mutex_t gmutex;
static int box_width = 32; static int box_width = 32;
static int multi_thread = 0;
#ifndef ANDROID static int verbose = 0;
static Pixmap create_pixmap(int width, int height);
#endif
static int create_window(int width, int height);
static VASurfaceID get_next_free_surface(int *index) static VASurfaceID get_next_free_surface(int *index)
{ {
...@@ -91,6 +82,16 @@ static VASurfaceID get_next_free_surface(int *index) ...@@ -91,6 +82,16 @@ static VASurfaceID get_next_free_surface(int *index)
assert(index); assert(index);
if (multi_thread == 0) {
i = *index;
i++;
if (i == SURFACE_NUM)
i = 0;
*index = i;
return surface_id[i];
}
for (i=0; i<SURFACE_NUM; i++) { for (i=0; i<SURFACE_NUM; i++) {
surface_status = (VASurfaceStatus)0; surface_status = (VASurfaceStatus)0;
vaQuerySurfaceStatus(va_dpy, surface_id[i], &surface_status); vaQuerySurfaceStatus(va_dpy, surface_id[i], &surface_status);
...@@ -110,6 +111,27 @@ static VASurfaceID get_next_free_surface(int *index) ...@@ -110,6 +111,27 @@ static VASurfaceID get_next_free_surface(int *index)
return surface_id[i]; return surface_id[i];
} }
static int upload_source_YUV_once_for_all()
{
VAImage surface_image;
void *surface_p=NULL, *U_start,*V_start;
VAStatus va_status;
int box_width_loc=8;
int row_shift_loc=0;
int i;
for (i=0; i<SURFACE_NUM; i++) {
printf("\rLoading data into surface %d.....", i);
upload_surface(va_dpy, surface_id[i], box_width_loc, row_shift_loc, 0);
row_shift_loc++;
if (row_shift_loc==(2*box_width_loc)) row_shift_loc= 0;
}
printf("\n");
return 0;
}
/* /*
* Helper function for profiling purposes * Helper function for profiling purposes
*/ */
...@@ -124,53 +146,18 @@ static unsigned long get_tick_count(void) ...@@ -124,53 +146,18 @@ static unsigned long get_tick_count(void)
static void* putsurface_thread(void *data) static void* putsurface_thread(void *data)
{ {
int width=win_width, height=win_height; int width=win_width, height=win_height;
#ifdef ANDROID void *drawable = data;
int win = (int)data;
#else
Window win = (Window)data;
Pixmap pixmap = 0;
GC context = NULL;
Bool is_event;
XEvent event;
Drawable draw;
#endif
int quit = 0; int quit = 0;
VAStatus vaStatus; VAStatus vaStatus;
int row_shift = 0; int row_shift = 0;
int index = 0; int index = 0;
unsigned int frame_num=0, start_time, putsurface_time; unsigned int frame_num=0, start_time, putsurface_time;
VARectangle cliprects[2]; /* client supplied clip list */ VARectangle cliprects[2]; /* client supplied clip list */
#ifdef ANDROID
sp<ISurface> win_isurface;
if (win == win_thread0) {
printf("Enter into thread0\n\n");
win_isurface = android_isurface;
}
if (win == win_thread1) { if (drawable == drawable_thread0)
printf("Enter into thread1\n\n");
win_isurface = android_isurface1;
}
#else
if (win == win_thread0) {
printf("Enter into thread0\n\n"); printf("Enter into thread0\n\n");
pixmap = pixmap_thread0; if (drawable == drawable_thread1)
context = context_thread0;
}
if (win == win_thread1) {
printf("Enter into thread1\n\n"); printf("Enter into thread1\n\n");
pixmap = pixmap_thread1;
context = context_thread1;
}
if (put_pixmap)
draw = pixmap;
else
draw = win;
#endif
printf("vaPutSurface into a Window directly\n\n");
putsurface_time = 0; putsurface_time = 0;
while (!quit) { while (!quit) {
...@@ -179,38 +166,29 @@ static void* putsurface_thread(void *data) ...@@ -179,38 +166,29 @@ static void* putsurface_thread(void *data)
while (surface_id == VA_INVALID_SURFACE) while (surface_id == VA_INVALID_SURFACE)
surface_id = get_next_free_surface(&index); surface_id = get_next_free_surface(&index);
if (verbose) printf("Thread %x Display surface 0x%p,\n", (unsigned int)win, (void *)surface_id); if (verbose) printf("Thread %x Display surface 0x%p,\n", (unsigned int)drawable, (void *)surface_id);
if (multi_thread)
upload_surface(va_dpy, surface_id, box_width, row_shift, display_field); upload_surface(va_dpy, surface_id, box_width, row_shift, display_field);
start_time = get_tick_count(); start_time = get_tick_count();
#ifdef ANDROID if (check_event)
vaStatus = vaPutSurface(va_dpy, surface_id, win_isurface,
0,0,surface_width,surface_height,
0,0,width,height,
(test_clip==0)?NULL:&cliprects[0],
(test_clip==0)?0:2,
display_field);
#else
if (check_event) {
pthread_mutex_lock(&gmutex); pthread_mutex_lock(&gmutex);
} vaStatus = vaPutSurface(va_dpy, surface_id, CAST_DRAWABLE(drawable),
vaStatus = vaPutSurface(va_dpy, surface_id, draw,
0,0,surface_width,surface_height, 0,0,surface_width,surface_height,
0,0,width,height, 0,0,width,height,
(test_clip==0)?NULL:&cliprects[0], (test_clip==0)?NULL:&cliprects[0],
(test_clip==0)?0:2, (test_clip==0)?0:2,
display_field); display_field);
if (check_event) { if (check_event)
pthread_mutex_unlock(&gmutex); pthread_mutex_unlock(&gmutex);
}
#endif pthread_mutex_unlock(&surface_mutex[index]); /* locked in get_next_free_surface */
CHECK_VASTATUS(vaStatus,"vaPutSurface"); CHECK_VASTATUS(vaStatus,"vaPutSurface");
putsurface_time += (get_tick_count() - start_time); putsurface_time += (get_tick_count() - start_time);
if ((frame_num % 0xff) == 0) { if ((frame_num % 0xff) == 0) {
fprintf(stderr, "%.2f FPS \r", 256000.0 / (float)putsurface_time); fprintf(stderr, "%.2f FPS \r", 256000.0 / (float)putsurface_time);
putsurface_time = 0; putsurface_time = 0;
...@@ -232,42 +210,21 @@ static void* putsurface_thread(void *data) ...@@ -232,42 +210,21 @@ static void* putsurface_thread(void *data)
cliprects[1].x, cliprects[1].y, cliprects[1].width, cliprects[1].height); cliprects[1].x, cliprects[1].y, cliprects[1].width, cliprects[1].height);
} }
} }
if (check_event)
check_window_event(win_display, drawable, &width, &height, &quit);
pthread_mutex_unlock(&surface_mutex[index]);
#ifndef ANDROID
if (check_event) {
pthread_mutex_lock(&gmutex);
is_event = XCheckWindowEvent(x11_display, win, StructureNotifyMask|KeyPressMask,&event);
pthread_mutex_unlock(&gmutex);
if (is_event) {
/* bail on any focused key press */
if(event.type == KeyPress) {
quit = 1;
break;
}
#if 0
/* rescale the video to fit the window */
if(event.type == ConfigureNotify) {
width = event.xconfigure.width;
height = event.xconfigure.height;
printf("Scale window to %dx%d\n", width, height);
}
#endif
}
}
#endif
row_shift++; row_shift++;
if (row_shift==(2*box_width)) row_shift= 0; if (row_shift==(2*box_width)) row_shift= 0;
frame_num++; frame_num++;
if( frame_num == 0x200 ) if (frame_num >= frame_num_total)
quit = 1; quit = 1;
} }
if(win == win_thread1)
if (drawable == drawable_thread1)
pthread_exit(NULL); pthread_exit(NULL);
return 0; return 0;
} }
...@@ -285,6 +242,7 @@ int main(int argc,char **argv) ...@@ -285,6 +242,7 @@ int main(int argc,char **argv)
switch (c) { switch (c) {
case '?': case '?':
printf("putsurface <options>\n"); printf("putsurface <options>\n");
printf(" -w/-h the window width/height\n");
printf(" -d the dimension of black/write square box, default is 32\n"); printf(" -d the dimension of black/write square box, default is 32\n");
printf(" -t multi-threads\n"); printf(" -t multi-threads\n");
printf(" -c test clipbox\n"); printf(" -c test clipbox\n");
...@@ -298,6 +256,9 @@ int main(int argc,char **argv) ...@@ -298,6 +256,9 @@ int main(int argc,char **argv)
case 'h': case 'h':
win_height = atoi(optarg); win_height = atoi(optarg);
break; break;
case 'n':
frame_num_total = atoi(optarg);
break;
case 'd': case 'd':
box_width = atoi(optarg); box_width = atoi(optarg);
break; break;
...@@ -305,14 +266,12 @@ int main(int argc,char **argv) ...@@ -305,14 +266,12 @@ int main(int argc,char **argv)
multi_thread = 1; multi_thread = 1;
printf("Two threads to do vaPutSurface\n"); printf("Two threads to do vaPutSurface\n");
break; break;
#ifndef ANDROID
case 'e': case 'e':
check_event = 0; check_event = 0;
break; break;
case 'p': case 'p':
put_pixmap = 1; put_pixmap = 1;
break; break;
#endif
case 'c': case 'c':
test_clip = 1; test_clip = 1;
break; break;
...@@ -333,21 +292,14 @@ int main(int argc,char **argv) ...@@ -333,21 +292,14 @@ int main(int argc,char **argv)
} }
} }
#ifdef ANDROID win_display = (void *)open_display();
x11_display = (Display*)malloc(sizeof(Display)); if (win_display == NULL) {
*(x11_display) = 0x18c34078; fprintf(stderr, "Can't open the connection of display!\n");
#else
x11_display = XOpenDisplay(":0.0");
#endif
if (x11_display == NULL) {
fprintf(stderr, "Can't connect X server!\n");
exit(-1); exit(-1);
} }
create_window(win_display, win_width, win_height);
create_window(win_width, win_height); va_dpy = vaGetDisplay(win_display);
va_dpy = vaGetDisplay(x11_display);
va_status = vaInitialize(va_dpy, &major_ver, &minor_ver); va_status = vaInitialize(va_dpy, &major_ver, &minor_ver);
CHECK_VASTATUS(va_status, "vaInitialize"); CHECK_VASTATUS(va_status, "vaInitialize");
...@@ -356,6 +308,8 @@ int main(int argc,char **argv) ...@@ -356,6 +308,8 @@ int main(int argc,char **argv)
va_status = vaCreateSurfaces(va_dpy,surface_width, surface_height, va_status = vaCreateSurfaces(va_dpy,surface_width, surface_height,
VA_RT_FORMAT_YUV420, SURFACE_NUM, &surface_id[0]); VA_RT_FORMAT_YUV420, SURFACE_NUM, &surface_id[0]);
CHECK_VASTATUS(va_status, "vaCreateSurfaces"); CHECK_VASTATUS(va_status, "vaCreateSurfaces");
if (multi_thread == 0) /* upload the content for all surfaces */
upload_source_YUV_once_for_all();
if (check_event) if (check_event)
pthread_mutex_init(&gmutex, NULL); pthread_mutex_init(&gmutex, NULL);
...@@ -364,15 +318,18 @@ int main(int argc,char **argv) ...@@ -364,15 +318,18 @@ int main(int argc,char **argv)
pthread_mutex_init(&surface_mutex[i], NULL); pthread_mutex_init(&surface_mutex[i], NULL);
if (multi_thread == 1) if (multi_thread == 1)
ret = pthread_create(&thread1, NULL, putsurface_thread, (void*)win_thread1); ret = pthread_create(&thread1, NULL, putsurface_thread, (void*)drawable_thread1);
putsurface_thread((void *)win_thread0); putsurface_thread((void *)drawable_thread0);
if (multi_thread == 1) if (multi_thread == 1)
pthread_join(thread1, (void **)&ret); pthread_join(thread1, (void **)&ret);
printf("thread1 is free\n"); printf("thread1 is free\n");
vaDestroySurfaces(va_dpy,&surface_id[0],SURFACE_NUM); vaDestroySurfaces(va_dpy,&surface_id[0],SURFACE_NUM);
vaTerminate(va_dpy); vaTerminate(va_dpy);
close_display(win_display);
return 0; return 0;
} }
...@@ -26,16 +26,32 @@ ...@@ -26,16 +26,32 @@
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <va/va_x11.h> #include <va/va_x11.h>
static Window win_thread0, win_thread1; static Window window_thread0, window_thread1;
static int multi_thread = 0;
static Pixmap pixmap_thread0, pixmap_thread1;
static GC context_thread0, context_thread1; static GC context_thread0, context_thread1;
static pthread_mutex_t gmutex; static pthread_mutex_t gmutex;
static void *open_display(void);
static void close_display(void *win_display);
static int create_window(void *win_display, int width, int height);
static int check_window_event(void *x11_display, void *drawable, int *width, int *height, int *quit);
#define CAST_DRAWABLE(a) (Drawable)(a)
#include "putsurface_common.c" #include "putsurface_common.c"
static Pixmap create_pixmap(int width, int height) static void *open_display(void)
{
return XOpenDisplay(":0.0");
}
static void close_display(void *win_display)
{
XCloseDisplay(win_display);
}
static Pixmap create_pixmap(void *win_display, int width, int height)
{ {
Display *x11_display = (Display *)win_display;
int screen = DefaultScreen(x11_display); int screen = DefaultScreen(x11_display);
Window root; Window root;
Pixmap pixmap; Pixmap pixmap;
...@@ -52,17 +68,18 @@ static Pixmap create_pixmap(int width, int height) ...@@ -52,17 +68,18 @@ static Pixmap create_pixmap(int width, int height)
return pixmap; return pixmap;
} }
static int create_window(int width, int height) static int create_window(void *win_display, int width, int height)
{ {
Display *x11_display = (Display *)win_display;
int screen = DefaultScreen(x11_display); int screen = DefaultScreen(x11_display);
Window root, win; Window root, win;
root = RootWindow(x11_display, screen); root = RootWindow(x11_display, screen);
printf("Create window0 for thread0\n"); printf("Create window0 for thread0\n");
win_thread0 = win = XCreateSimpleWindow(x11_display, root, 0, 0, width, height, drawable_thread0 = (void *)XCreateSimpleWindow(x11_display, root, 0, 0, width, height,
0, 0, WhitePixel(x11_display, 0)); 0, 0, WhitePixel(x11_display, 0));
if (win) { if (drawable_thread0) {
XSizeHints sizehints; XSizeHints sizehints;
sizehints.width = width; sizehints.width = width;
sizehints.height = height; sizehints.height = height;
...@@ -77,17 +94,19 @@ static int create_window(int width, int height) ...@@ -77,17 +94,19 @@ static int create_window(int width, int height)
XSelectInput(x11_display, win, KeyPressMask | StructureNotifyMask); XSelectInput(x11_display, win, KeyPressMask | StructureNotifyMask);
XSync(x11_display, False); XSync(x11_display, False);
if (put_pixmap) if (put_pixmap) {
pixmap_thread0 = create_pixmap(width, height); window_thread0 = (Window)drawable_thread0;
drawable_thread0 = (void *)create_pixmap(x11_display, width, height);
}
if (multi_thread == 0) if (multi_thread == 0)
return 0; return 0;
printf("Create window1 for thread1\n"); printf("Create window1 for thread1\n");
win_thread1 = win = XCreateSimpleWindow(x11_display, root, width, 0, width, height, drawable_thread1 = (void *)XCreateSimpleWindow(x11_display, root, width, 0, width, height,
0, 0, WhitePixel(x11_display, 0)); 0, 0, WhitePixel(x11_display, 0));
if (win) { if (drawable_thread1) {
XSizeHints sizehints; XSizeHints sizehints;
sizehints.width = width; sizehints.width = width;
sizehints.height = height; sizehints.height = height;
...@@ -98,8 +117,10 @@ static int create_window(int width, int height) ...@@ -98,8 +117,10 @@ static int create_window(int width, int height)
XMapWindow(x11_display, win); XMapWindow(x11_display, win);
} }
if (put_pixmap) if (put_pixmap) {
pixmap_thread1 = create_pixmap(width, height); window_thread1 = (Window)drawable_thread1;
drawable_thread1 = (void *)create_pixmap(x11_display, width, height);
}
context_thread1 = XCreateGC(x11_display, win, 0, 0); context_thread1 = XCreateGC(x11_display, win, 0, 0);
XSelectInput(x11_display, win, KeyPressMask | StructureNotifyMask); XSelectInput(x11_display, win, KeyPressMask | StructureNotifyMask);
...@@ -107,3 +128,40 @@ static int create_window(int width, int height) ...@@ -107,3 +128,40 @@ static int create_window(int width, int height)
return 0; return 0;
} }
static int check_window_event(void *win_display, void *drawable, int *width, int *height, int *quit)
{
int is_event = 0;
XEvent event;
Window win = (Window)drawable;
Display *x11_display = (Display *)win_display;
if (check_event == 0)
return 0;
pthread_mutex_lock(&gmutex);
is_event = XCheckWindowEvent(x11_display, win, StructureNotifyMask|KeyPressMask,&event);
pthread_mutex_unlock(&gmutex);
if (is_event == 0)
return 0;
/* bail on any focused key press */
if(event.type == KeyPress) {
*quit = 1;
return 0;
}
#if 0
/* rescale the video to fit the window */
if(event.type == ConfigureNotify) {
*width = event.xconfigure.width;
*height = event.xconfigure.height;
printf("Scale window to %dx%d\n", width, height);
}
#endif
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment