2 * Copyright (c) 2012 Carsten Munk <carsten.munk@gmail.com>
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include "hybris_nativebufferext.h"
23 #include <EGL/eglext.h>
24 int main(int argc
, char **argv
)
29 EGLint attr
[] = { // some attributes to set up our egl-interface
37 EGL_CONTEXT_CLIENT_VERSION
, 2,
43 PFNEGLHYBRISCREATENATIVEBUFFERPROC eglHybrisCreateNativeBuffer
;
44 PFNEGLHYBRISLOCKNATIVEBUFFERPROC eglHybrisLockNativeBuffer
;
45 PFNEGLHYBRISUNLOCKNATIVEBUFFERPROC eglHybrisUnlockNativeBuffer
;
46 PFNEGLHYBRISRELEASENATIVEBUFFERPROC eglHybrisReleaseNativeBuffer
;
47 PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR
;
48 PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR
;
50 display
= eglGetDisplay(EGL_DEFAULT_DISPLAY
);
51 assert(eglGetError() == EGL_SUCCESS
);
52 assert(display
!= EGL_NO_DISPLAY
);
54 rv
= eglInitialize(display
, NULL
, NULL
);
55 assert(eglGetError() == EGL_SUCCESS
);
56 assert(rv
== EGL_TRUE
);
58 rv
= eglChooseConfig((EGLDisplay
) display
, attr
, &ecfg
, 1, &num_config
);
59 assert(eglGetError() == EGL_SUCCESS
);
60 assert(rv
== EGL_TRUE
);
62 surface
= eglCreateWindowSurface((EGLDisplay
) display
, ecfg
, (EGLNativeWindowType
)NULL
, NULL
);
63 assert(eglGetError() == EGL_SUCCESS
);
64 assert(surface
!= EGL_NO_SURFACE
);
66 context
= eglCreateContext((EGLDisplay
) display
, ecfg
, EGL_NO_CONTEXT
, ctxattr
);
67 assert(eglGetError() == EGL_SUCCESS
);
68 assert(context
!= EGL_NO_CONTEXT
);
70 assert(eglMakeCurrent((EGLDisplay
) display
, surface
, surface
, context
) == EGL_TRUE
);
72 if (strstr(eglQueryString(display
, EGL_EXTENSIONS
), "EGL_HYBRIS_native_buffer") != NULL
)
74 printf("Found EGL_HYBRIS_native_buffer\n");
75 assert((eglHybrisCreateNativeBuffer
= (PFNEGLHYBRISCREATENATIVEBUFFERPROC
) eglGetProcAddress("eglHybrisCreateNativeBuffer")) != NULL
);
76 printf("Found eglHybrisCreateNativeBuffer\n");
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
));
101 assert((eglHybrisReleaseNativeBuffer
= (PFNEGLHYBRISRELEASENATIVEBUFFERPROC
) eglGetProcAddress("eglHybrisReleaseNativeBuffer")) != NULL
);
102 printf("Found eglHybrisReleaseNativeBuffer\n");
103 eglHybrisReleaseNativeBuffer(buf
);
108 eglDestroyContext((EGLDisplay
) display
, context
);
109 printf("destroyed context\n");
111 eglDestroySurface((EGLDisplay
) display
, surface
);
112 printf("destroyed surface\n");
113 eglTerminate((EGLDisplay
) display
);
117 // vim:ts=4:sw=4:noexpandtab