Commit | Line | Data |
---|---|---|
d42e7319 JB |
1 | /* |
2 | * Copyright (c) 2012 Carsten Munk <carsten.munk@gmail.com> | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | * | |
16 | */ | |
17 | ||
18 | #include <EGL/egl.h> | |
19 | #include <assert.h> | |
20 | #include <stdio.h> | |
21 | #include "hybris_nativebufferext.h" | |
22 | #include <string.h> | |
23 | #include <EGL/eglext.h> | |
24 | int main(int argc, char **argv) | |
25 | { | |
26 | EGLDisplay display; | |
27 | EGLConfig ecfg; | |
28 | EGLint num_config; | |
29 | EGLint attr[] = { // some attributes to set up our egl-interface | |
30 | EGL_BUFFER_SIZE, 32, | |
31 | EGL_RENDERABLE_TYPE, | |
32 | EGL_OPENGL_ES2_BIT, | |
33 | EGL_NONE | |
34 | }; | |
35 | EGLSurface surface; | |
36 | EGLint ctxattr[] = { | |
37 | EGL_CONTEXT_CLIENT_VERSION, 2, | |
38 | EGL_NONE | |
39 | }; | |
40 | EGLContext context; | |
41 | ||
42 | EGLBoolean rv; | |
43 | PFNEGLHYBRISCREATENATIVEBUFFERPROC eglHybrisCreateNativeBuffer; | |
44 | PFNEGLHYBRISLOCKNATIVEBUFFERPROC eglHybrisLockNativeBuffer; | |
45 | PFNEGLHYBRISUNLOCKNATIVEBUFFERPROC eglHybrisUnlockNativeBuffer; | |
46 | PFNEGLHYBRISRELEASENATIVEBUFFERPROC eglHybrisReleaseNativeBuffer; | |
47 | PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR; | |
48 | PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR; | |
49 | ||
50 | display = eglGetDisplay(EGL_DEFAULT_DISPLAY); | |
51 | assert(eglGetError() == EGL_SUCCESS); | |
52 | assert(display != EGL_NO_DISPLAY); | |
53 | ||
54 | rv = eglInitialize(display, NULL, NULL); | |
55 | assert(eglGetError() == EGL_SUCCESS); | |
56 | assert(rv == EGL_TRUE); | |
57 | ||
58 | rv = eglChooseConfig((EGLDisplay) display, attr, &ecfg, 1, &num_config); | |
59 | assert(eglGetError() == EGL_SUCCESS); | |
60 | assert(rv == EGL_TRUE); | |
61 | ||
62 | surface = eglCreateWindowSurface((EGLDisplay) display, ecfg, (EGLNativeWindowType)NULL, NULL); | |
63 | assert(eglGetError() == EGL_SUCCESS); | |
64 | assert(surface != EGL_NO_SURFACE); | |
65 | ||
66 | context = eglCreateContext((EGLDisplay) display, ecfg, EGL_NO_CONTEXT, ctxattr); | |
67 | assert(eglGetError() == EGL_SUCCESS); | |
68 | assert(context != EGL_NO_CONTEXT); | |
69 | ||
70 | assert(eglMakeCurrent((EGLDisplay) display, surface, surface, context) == EGL_TRUE); | |
71 | ||
72 | if (strstr(eglQueryString(display, EGL_EXTENSIONS), "EGL_HYBRIS_native_buffer") != NULL) | |
73 | { | |
74 | printf("Found EGL_HYBRIS_native_buffer\n"); | |
75 | assert((eglHybrisCreateNativeBuffer = (PFNEGLHYBRISCREATENATIVEBUFFERPROC) eglGetProcAddress("eglHybrisCreateNativeBuffer")) != NULL); | |
76 | printf("Found eglHybrisCreateNativeBuffer\n"); | |
77 | EGLClientBuffer buf; | |
78 | EGLint stride; | |
79 | void *loc; | |
80 | assert(eglHybrisCreateNativeBuffer(320, 480, HYBRIS_USAGE_SW_READ_RARELY|HYBRIS_USAGE_SW_WRITE_RARELY|HYBRIS_USAGE_HW_TEXTURE, HYBRIS_PIXEL_FORMAT_RGBA_8888, &stride, &buf) == EGL_TRUE); | |
81 | printf("Stride is %i\n", stride); | |
82 | assert((eglHybrisLockNativeBuffer = (PFNEGLHYBRISLOCKNATIVEBUFFERPROC) eglGetProcAddress("eglHybrisLockNativeBuffer")) != NULL); | |
83 | printf("Found eglHybrisLockBuffer\n"); | |
84 | assert(eglHybrisLockNativeBuffer(buf, HYBRIS_USAGE_SW_WRITE_RARELY, 0, 0, 320, 480, &loc) == EGL_TRUE); | |
85 | printf("locked at %p\n", loc); | |
86 | printf("Memsetting..\n"); | |
87 | memset(loc, 0xEF, (stride*480)); | |
88 | assert((eglHybrisUnlockNativeBuffer = (PFNEGLHYBRISUNLOCKNATIVEBUFFERPROC) eglGetProcAddress("eglHybrisUnlockNativeBuffer")) != NULL); | |
89 | printf("Found eglHybrisUnlockBuffer\n"); | |
90 | eglHybrisUnlockNativeBuffer(buf); | |
91 | assert((eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC) eglGetProcAddress("eglCreateImageKHR")) != NULL); | |
92 | printf("Found eglCreateImageKHR\n"); | |
93 | EGLImageKHR image = eglCreateImageKHR( | |
94 | display, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_HYBRIS, | |
95 | (EGLClientBuffer)buf, NULL); | |
96 | assert(image != EGL_NO_IMAGE_KHR); | |
97 | assert((eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC) eglGetProcAddress("eglDestroyImageKHR")) != NULL); | |
98 | printf("Found eglDestroyImageKHR\n"); | |
99 | assert(eglDestroyImageKHR(display, image)); | |
100 | ||
101 | assert((eglHybrisReleaseNativeBuffer = (PFNEGLHYBRISRELEASENATIVEBUFFERPROC) eglGetProcAddress("eglHybrisReleaseNativeBuffer")) != NULL); | |
102 | printf("Found eglHybrisReleaseNativeBuffer\n"); | |
103 | eglHybrisReleaseNativeBuffer(buf); | |
104 | } | |
105 | ||
106 | printf("stop\n"); | |
107 | ||
108 | eglDestroyContext((EGLDisplay) display, context); | |
109 | printf("destroyed context\n"); | |
110 | ||
111 | eglDestroySurface((EGLDisplay) display, surface); | |
112 | printf("destroyed surface\n"); | |
113 | eglTerminate((EGLDisplay) display); | |
114 | return 0; | |
115 | } | |
116 | ||
117 | // vim:ts=4:sw=4:noexpandtab |