1 /*
2  * Copyright (c) 2008-2009 Intel Corporation. All Rights Reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sub license, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #include <stdio.h>
25 #include <va/va.h>
26 #include <va/va_android.h>
27 #include <gui/Surface.h>
28 #include <gui/SurfaceComposerClient.h>
29 #include <gui/ISurfaceComposer.h>
30 #include <assert.h>
31 #include <pthread.h>
32 
33 using namespace android;
34 
35 static  int android_display=0;
36 
37 static sp<SurfaceComposerClient> client0 = NULL;
38 static sp<SurfaceControl> surface_ctrl0 = NULL;
39 static sp<ANativeWindow> anw0 = NULL;
40 
41 static sp<SurfaceComposerClient> client1 = NULL;
42 static sp<SurfaceControl> surface_ctrl1 = NULL;
43 static sp<ANativeWindow> anw1 = NULL;
44 
45 static void *open_display(void);
46 static void close_display(void *win_display);
47 static int create_window(void *win_display, int x, int y, int width, int height);
48 static int check_window_event(void *x11_display, void *win, int *width, int *height, int *quit);
49 
50 #define CAST_DRAWABLE(a)  static_cast<ANativeWindow *>((void *)(*(unsigned int *)a))
51 #include "putsurface_common.c"
52 
open_display()53 static void *open_display()
54 {
55     return &android_display;
56 }
57 
close_display(void * win_display)58 static void close_display(void *win_display)
59 {
60     return;
61 }
62 
create_window(void * win_display,int x,int y,int width,int height)63 static int create_window(void *win_display, int x, int y, int width, int height)
64 {
65     client0 = new SurfaceComposerClient();
66 
67     surface_ctrl0 = client1->createSurface(
68         String8("Test Surface"),
69         width, height,
70         PIXEL_FORMAT_RGB_888, 0);
71 
72     SurfaceComposerClient::openGlobalTransaction();
73     surface_ctrl0->setLayer(0x7FFFFFFF);
74     surface_ctrl0->show();
75     SurfaceComposerClient::closeGlobalTransaction();
76 
77     SurfaceComposerClient::openGlobalTransaction();
78     surface_ctrl0->setPosition(x, y);
79     SurfaceComposerClient::closeGlobalTransaction();
80 
81     SurfaceComposerClient::openGlobalTransaction();
82     surface_ctrl0->setSize(width, height);
83     SurfaceComposerClient::closeGlobalTransaction();
84 
85     anw0 = surface_ctrl0->getSurface();
86 
87     drawable_thread0 = static_cast<void*>(&anw0);
88     if (multi_thread == 0)
89         return 0;
90 
91     printf("Create window1 for thread1\n");
92     client1 = new SurfaceComposerClient();
93 
94     surface_ctrl1 = client1->createSurface(
95         String8("Test Surface"),
96         width, height,
97         PIXEL_FORMAT_RGB_888, 0);
98 
99     SurfaceComposerClient::openGlobalTransaction();
100     surface_ctrl1->setLayer(0x7FFFFFFF);
101     surface_ctrl1->show();
102     SurfaceComposerClient::closeGlobalTransaction();
103 
104     SurfaceComposerClient::openGlobalTransaction();
105     surface_ctrl1->setPosition(x*2, y*2);
106     SurfaceComposerClient::closeGlobalTransaction();
107 
108     SurfaceComposerClient::openGlobalTransaction();
109     surface_ctrl1->setSize(width, height);
110     SurfaceComposerClient::closeGlobalTransaction();
111 
112     anw1 = surface_ctrl1->getSurface();
113 
114     drawable_thread1 = static_cast<void *>(&anw1);
115 
116     return 0;
117 }
118 
check_window_event(void * win_display,void * drawble,int * width,int * height,int * quit)119 int check_window_event(void *win_display, void *drawble, int *width, int *height, int *quit)
120 {
121     return 0;
122 }
123 
124 
125