From 46f7c260dd5e79116e7c6571cacbda1b89495c9e Mon Sep 17 00:00:00 2001 From: zheng_wenlong Date: Mon, 23 Oct 2017 14:38:56 +0900 Subject: Move sample from agl-service-homescreen-2017 This sample is using libhomescren with homescreen sevice, So better move inside of libhomescreen. Related Commit: https://gerrit.automotivelinux.org/gerrit/#/c/11429/ [Patch Sets 2] Rebased to c0e6b4d9496eacabeffc4115fad7c1a288de60c8 [Patch Sets 3] Delete ivi-application-client-protocol.h and some trailing whitespace. [Patch Sets 4] Change temlate/README to README.md [Patch Sets 5] Rebased to 572023336d9573d3d5636d7e61a8dd3ed8878b0d [Patch Sets 6] Add LICENSE.APL-2.0 and LICENSE.MIT to sample. Modify config.xml license to APL 2.0 + MIT. BUG-AGL: SPEC-988 Change-Id: Id9a1a2401a9a0a42442ce84025213036a4fccd78 Signed-off-by: zheng_wenlong --- sample/simple-egl/CMakeLists.txt | 69 +++ sample/simple-egl/LICENSE.APL-2.0 | 204 ++++++++ sample/simple-egl/LICENSE.MIT | 23 + sample/simple-egl/README.md | 27 ++ sample/simple-egl/include/platform.h | 115 +++++ sample/simple-egl/package/hvac/config.xml | 16 + sample/simple-egl/package/hvac/icon.svg | 279 +++++++++++ sample/simple-egl/package/navi/config.xml | 16 + sample/simple-egl/package/navi/icon.svg | 279 +++++++++++ sample/simple-egl/package/root/config.xml | 16 + sample/simple-egl/package/root/icon.svg | 279 +++++++++++ sample/simple-egl/src/simple-egl.cpp | 744 ++++++++++++++++++++++++++++++ 12 files changed, 2067 insertions(+) create mode 100644 sample/simple-egl/CMakeLists.txt create mode 100644 sample/simple-egl/LICENSE.APL-2.0 create mode 100644 sample/simple-egl/LICENSE.MIT create mode 100644 sample/simple-egl/README.md create mode 100644 sample/simple-egl/include/platform.h create mode 100644 sample/simple-egl/package/hvac/config.xml create mode 100644 sample/simple-egl/package/hvac/icon.svg create mode 100644 sample/simple-egl/package/navi/config.xml create mode 100644 sample/simple-egl/package/navi/icon.svg create mode 100644 sample/simple-egl/package/root/config.xml create mode 100644 sample/simple-egl/package/root/icon.svg create mode 100644 sample/simple-egl/src/simple-egl.cpp (limited to 'sample/simple-egl') diff --git a/sample/simple-egl/CMakeLists.txt b/sample/simple-egl/CMakeLists.txt new file mode 100644 index 0000000..3f4a6e9 --- /dev/null +++ b/sample/simple-egl/CMakeLists.txt @@ -0,0 +1,69 @@ +# +# Copyright (c) 2017 TOYOTA MOTOR CORPORATION +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +project(simple-egl C CXX) + +cmake_minimum_required(VERSION 3.0) + +set(PROJECT_NAME "simple-egl") +set(PROJECT_VERSION "1.0") +set(PROJECT_PRETTY_NAME "SE") +set(PROJECT_DESCRIPTION "Sample application for homescreen and windowmanager") +set(PROJECT_URL "") +set(CMAKE_CXX_FLAGS "-Wall -fpermissive") + +#source directory +aux_source_directory(src DIR_SRCS) + +#head file path +include_directories(include) + +#set extern libraries +SET(LIBRARIES + libwindowmanager.so + libEGL.so + libGLESv2.so + libm.so + libwayland-egl.so + libwayland-client.so + libjson-c.so + libhomescreen.so + librt.so + libpthread.so +) + +#add executable file +add_executable(simple-egl ${DIR_SRCS}) + +#add link library +TARGET_LINK_LIBRARIES(simple-egl ${LIBRARIES}) + +add_custom_command(TARGET simple-egl POST_BUILD + COMMAND cp -rf ${CMAKE_CURRENT_SOURCE_DIR}/package ${PROJECT_BINARY_DIR} + COMMAND cp -rf ${PROJECT_BINARY_DIR}/simple-egl ${PROJECT_BINARY_DIR}/package/root/bin) + +add_custom_target(widget DEPENDS ${PROJECT_BINARY_DIR}/package/root + COMMAND wgtpkg-pack -f -o ${PROJECT_BINARY_DIR}/package/${PROJECT_NAME}.wgt ${PROJECT_BINARY_DIR}/package/root) + +add_custom_target(hvac DEPENDS ${PROJECT_BINARY_DIR}/package/root + COMMAND mkdir -p ${PROJECT_BINARY_DIR}/package/hvac/bin + COMMAND cp -rf ${PROJECT_BINARY_DIR}/simple-egl ${PROJECT_BINARY_DIR}/package/hvac/bin/hvac + COMMAND wgtpkg-pack -f -o ${PROJECT_BINARY_DIR}/package/hvac.wgt ${PROJECT_BINARY_DIR}/package/hvac) + +add_custom_target(navi DEPENDS ${PROJECT_BINARY_DIR}/package/root + COMMAND mkdir -p ${PROJECT_BINARY_DIR}/package/navi/bin + COMMAND cp -rf ${PROJECT_BINARY_DIR}/simple-egl ${PROJECT_BINARY_DIR}/package/navi/bin/navi + COMMAND wgtpkg-pack -f -o ${PROJECT_BINARY_DIR}/package/navi.wgt ${PROJECT_BINARY_DIR}/package/navi) diff --git a/sample/simple-egl/LICENSE.APL-2.0 b/sample/simple-egl/LICENSE.APL-2.0 new file mode 100644 index 0000000..b3201ab --- /dev/null +++ b/sample/simple-egl/LICENSE.APL-2.0 @@ -0,0 +1,204 @@ + + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don`t include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/sample/simple-egl/LICENSE.MIT b/sample/simple-egl/LICENSE.MIT new file mode 100644 index 0000000..33f8bef --- /dev/null +++ b/sample/simple-egl/LICENSE.MIT @@ -0,0 +1,23 @@ + +MIT License + +Copyright (c) + +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, sublicense, 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 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 NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS 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. + diff --git a/sample/simple-egl/README.md b/sample/simple-egl/README.md new file mode 100644 index 0000000..42820e1 --- /dev/null +++ b/sample/simple-egl/README.md @@ -0,0 +1,27 @@ +Information +==== +
This is a sample application for homescreen-2017 and windowmanager-2017. + +How to compile and install +==== +
$ mkdir build +
$ cd build +
$ cmake .. +
$ make +
$ make widget + +
Copy package/simple-egl.wgt to rootfs. + +How to use +==== +
afm-util install simple-egl.wgt +
afm-util start simple-egl@0.1 + +Depends +==== +
homescreen-2017 +
agl-service-homescreen-2017 +
agl-service-windowmanger-2017 +
libhomescreen +
libwindowmanager +
wayland-ivi-extension diff --git a/sample/simple-egl/include/platform.h b/sample/simple-egl/include/platform.h new file mode 100644 index 0000000..8fd57b0 --- /dev/null +++ b/sample/simple-egl/include/platform.h @@ -0,0 +1,115 @@ +/* + * Copyright © 2015 Collabora, Ltd. + * + * 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, sublicense, 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 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * 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 WESTON_PLATFORM_H +#define WESTON_PLATFORM_H + +#include + +#include +#include +#include + +#ifndef EGL_PLATFORM_WAYLAND_KHR +#define EGL_PLATFORM_WAYLAND_KHR 0x31D8 +#endif + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifndef EGL_EXT_platform_base +typedef EGLDisplay (*PFNEGLGETPLATFORMDISPLAYEXTPROC) (EGLenum platform, + void *native_display, + const EGLint *attrib_list); +typedef EGLSurface (*PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC) (EGLDisplay dpy, + EGLConfig config, + void *native_window, + const EGLint *attrib_list); +#endif + +static inline void * +weston_platform_get_egl_proc_address(const char *address) +{ + const char *extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); + + if (extensions + && (strstr(extensions, "EGL_EXT_platform_wayland") + || strstr(extensions, "EGL_KHR_platform_wayland"))) { + return (void *) eglGetProcAddress(address); + } + + return NULL; +} + +static inline EGLDisplay +weston_platform_get_egl_display(EGLenum platform, void *native_display, + const EGLint *attrib_list) +{ + static PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display = NULL; + + if (!get_platform_display) { + get_platform_display = (PFNEGLGETPLATFORMDISPLAYEXTPROC) + weston_platform_get_egl_proc_address( + "eglGetPlatformDisplayEXT"); + } + + if (get_platform_display) + return get_platform_display(platform, + native_display, attrib_list); + + return eglGetDisplay((EGLNativeDisplayType) native_display); +} + +static inline EGLSurface +weston_platform_create_egl_surface(EGLDisplay dpy, EGLConfig config, + void *native_window, + const EGLint *attrib_list) +{ + static PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC + create_platform_window = NULL; + + if (!create_platform_window) { + create_platform_window = (PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC) + weston_platform_get_egl_proc_address( + "eglCreatePlatformWindowSurfaceEXT"); + } + + if (create_platform_window) + return create_platform_window(dpy, config, + native_window, + attrib_list); + + return eglCreateWindowSurface(dpy, config, + (EGLNativeWindowType) native_window, + attrib_list); +} + +#ifdef __cplusplus +} +#endif + +#endif /* WESTON_PLATFORM_H */ diff --git a/sample/simple-egl/package/hvac/config.xml b/sample/simple-egl/package/hvac/config.xml new file mode 100644 index 0000000..d903f0e --- /dev/null +++ b/sample/simple-egl/package/hvac/config.xml @@ -0,0 +1,16 @@ + + + HVAC + + + This is a demo application for simple-egl + TOYOA + APL 2.0 + MIT + + + + + + + + diff --git a/sample/simple-egl/package/hvac/icon.svg b/sample/simple-egl/package/hvac/icon.svg new file mode 100644 index 0000000..91661a7 --- /dev/null +++ b/sample/simple-egl/package/hvac/icon.svg @@ -0,0 +1,279 @@ + + + +image/svg+xmlMULTIMEDIA + \ No newline at end of file diff --git a/sample/simple-egl/package/navi/config.xml b/sample/simple-egl/package/navi/config.xml new file mode 100644 index 0000000..33b5b67 --- /dev/null +++ b/sample/simple-egl/package/navi/config.xml @@ -0,0 +1,16 @@ + + + Navigation + + + This is a demo application for simple-egl + TOYOA + APL 2.0 + MIT + + + + + + + + diff --git a/sample/simple-egl/package/navi/icon.svg b/sample/simple-egl/package/navi/icon.svg new file mode 100644 index 0000000..91661a7 --- /dev/null +++ b/sample/simple-egl/package/navi/icon.svg @@ -0,0 +1,279 @@ + + + +image/svg+xmlMULTIMEDIA + \ No newline at end of file diff --git a/sample/simple-egl/package/root/config.xml b/sample/simple-egl/package/root/config.xml new file mode 100644 index 0000000..d6402ad --- /dev/null +++ b/sample/simple-egl/package/root/config.xml @@ -0,0 +1,16 @@ + + + SIMPLE-EGL + + + This is a demo application for simple-egl + TOYOA + APL 2.0 + MIT + + + + + + + + diff --git a/sample/simple-egl/package/root/icon.svg b/sample/simple-egl/package/root/icon.svg new file mode 100644 index 0000000..91661a7 --- /dev/null +++ b/sample/simple-egl/package/root/icon.svg @@ -0,0 +1,279 @@ + + + +image/svg+xmlMULTIMEDIA + \ No newline at end of file diff --git a/sample/simple-egl/src/simple-egl.cpp b/sample/simple-egl/src/simple-egl.cpp new file mode 100644 index 0000000..4494ac8 --- /dev/null +++ b/sample/simple-egl/src/simple-egl.cpp @@ -0,0 +1,744 @@ +/* + * Copyright (c) 2017 TOYOTA MOTOR CORPORATION + * Copyright © 2011 Benjamin Franzke + * + * 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, sublicense, + * 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 NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS 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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include + +#include "libwindowmanager.h" +#include + +#include +using namespace std; + + +uint32_t g_id_ivisurf = 9009; +long port = 1700; +string token = string("wm"); +bool enable_debug = false; + +string app_name = string("Navigation"); + +LibHomeScreen* hs; +LibWindowmanager *wm; + +static const struct wl_interface *types[] = { + NULL, + NULL, + NULL, + &wl_surface_interface, + &ivi_surface_interface, +}; + +static const struct wl_message ivi_surface_requests[] = { + { "destroy", "", types + 0 }, +}; + +static const struct wl_message ivi_surface_events[] = { + { "configure", "ii", types + 0 }, +}; + +const struct wl_interface ivi_surface_interface = { + "ivi_surface", 1, + 1, ivi_surface_requests, + 1, ivi_surface_events, +}; + +static const struct wl_message ivi_application_requests[] = { + { "surface_create", "uon", types + 2 }, +}; + +const struct wl_interface ivi_application_interface = { + "ivi_application", 1, + 1, ivi_application_requests, + 0, NULL, +}; + +#include "platform.h" + +#ifndef EGL_EXT_swap_buffers_with_damage +#define EGL_EXT_swap_buffers_with_damage 1 +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC)(EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint n_rects); +#endif + +#ifndef EGL_EXT_buffer_age +#define EGL_EXT_buffer_age 1 +#define EGL_BUFFER_AGE_EXT 0x313D +#endif + +struct window; +struct seat; + +struct display { + struct wl_display *display; + struct wl_registry *registry; + struct wl_compositor *compositor; + struct wl_seat *seat; + struct { + EGLDisplay dpy; + EGLContext ctx; + EGLConfig conf; + } egl; + struct window *window; + struct ivi_application *ivi_application; + + PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC swap_buffers_with_damage; +}; + +struct geometry { + int width, height; +}; + +struct window { + struct display *display; + struct geometry geometry, window_size; + struct { + GLuint rotation_uniform; + GLuint pos; + GLuint col; + } gl; + + uint32_t benchmark_time, frames; + struct wl_egl_window *native; + struct wl_surface *surface; + struct ivi_surface *ivi_surface; + EGLSurface egl_surface; + struct wl_callback *callback; + int fullscreen, opaque, buffer_size, frame_sync; +}; + +static const char *vert_shader_text = + "uniform mat4 rotation;\n" + "attribute vec4 pos;\n" + "attribute vec4 color;\n" + "varying vec4 v_color;\n" + "void main() {\n" + " gl_Position = rotation * pos;\n" + " v_color = color;\n" + "}\n"; + +static const char *frag_shader_text = + "precision mediump float;\n" + "varying vec4 v_color;\n" + "void main() {\n" + " gl_FragColor = v_color;\n" + "}\n"; + +static int running = 1; + +static void debug_out(const char* str, ...) +{ + if(!enable_debug) + return; + char *out; + va_list arg_ptr; + va_start(arg_ptr, str); + vasprintf(&out, str, arg_ptr); + cout << out; + va_end(arg_ptr); + // cout << endl; +} + +static void +init_egl(struct display *display, struct window *window) +{ + static const EGLint context_attribs[] = { + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE + }; + const char *extensions; + + EGLint config_attribs[] = { + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_RED_SIZE, 1, + EGL_GREEN_SIZE, 1, + EGL_BLUE_SIZE, 1, + EGL_ALPHA_SIZE, 1, + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, + EGL_NONE + }; + + EGLint major, minor, n, count, i, size; + EGLConfig *configs; + EGLBoolean ret; + + if (window->opaque || window->buffer_size == 16) + config_attribs[9] = 0; + + display->egl.dpy = weston_platform_get_egl_display(EGL_PLATFORM_WAYLAND_KHR, display->display, NULL); + assert(display->egl.dpy); + + ret = eglInitialize(display->egl.dpy, &major, &minor); + assert(ret == EGL_TRUE); + ret = eglBindAPI(EGL_OPENGL_ES_API); + assert(ret == EGL_TRUE); + + if (!eglGetConfigs(display->egl.dpy, NULL, 0, &count) || count < 1) + assert(0); + + configs = calloc(count, sizeof *configs); + assert(configs); + + ret = eglChooseConfig(display->egl.dpy, config_attribs, + configs, count, &n); + assert(ret && n >= 1); + + for (i = 0; i < n; i++) { + eglGetConfigAttrib(display->egl.dpy, + configs[i], EGL_BUFFER_SIZE, &size); + if (window->buffer_size == size) { + display->egl.conf = configs[i]; + break; + } + } + free(configs); + if (display->egl.conf == NULL) { + debug_out("did not find config with buffer size %d\n", + window->buffer_size); + exit(EXIT_FAILURE); + } + + display->egl.ctx = eglCreateContext(display->egl.dpy, + display->egl.conf, + EGL_NO_CONTEXT, context_attribs); + assert(display->egl.ctx); + + display->swap_buffers_with_damage = NULL; + extensions = eglQueryString(display->egl.dpy, EGL_EXTENSIONS); + if (extensions && + strstr(extensions, "EGL_EXT_swap_buffers_with_damage") && + strstr(extensions, "EGL_EXT_buffer_age")) + display->swap_buffers_with_damage = + (PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC) + eglGetProcAddress("eglSwapBuffersWithDamageEXT"); + + if (display->swap_buffers_with_damage) + debug_out("has EGL_EXT_buffer_age and EGL_EXT_swap_buffers_with_damage\n"); + +} + +static void +fini_egl(struct display *display) +{ + eglTerminate(display->egl.dpy); + eglReleaseThread(); +} + +static GLuint +create_shader(struct window *window, const char *source, GLenum shader_type) +{ + GLuint shader; + GLint status; + + shader = glCreateShader(shader_type); + assert(shader != 0); + + glShaderSource(shader, 1, (const char **) &source, NULL); + glCompileShader(shader); + + glGetShaderiv(shader, GL_COMPILE_STATUS, &status); + if (!status) { + char log[1000]; + GLsizei len; + glGetShaderInfoLog(shader, 1000, &len, log); + debug_out("Error: compiling %s: %*s\n", + shader_type == GL_VERTEX_SHADER ? "vertex" : "fragment", + len, log); + exit(1); + } + + return shader; +} + +static void +init_gl(struct window *window) +{ + GLuint frag, vert; + GLuint program; + GLint status; + + frag = create_shader(window, frag_shader_text, GL_FRAGMENT_SHADER); + vert = create_shader(window, vert_shader_text, GL_VERTEX_SHADER); + + program = glCreateProgram(); + glAttachShader(program, frag); + glAttachShader(program, vert); + glLinkProgram(program); + + glGetProgramiv(program, GL_LINK_STATUS, &status); + if (!status) { + char log[1000]; + GLsizei len; + glGetProgramInfoLog(program, 1000, &len, log); + debug_out("Error: linking:\n%*s\n", len, log); + exit(1); + } + + glUseProgram(program); + + window->gl.pos = 0; + window->gl.col = 1; + + glBindAttribLocation(program, window->gl.pos, "pos"); + glBindAttribLocation(program, window->gl.col, "color"); + glLinkProgram(program); + + window->gl.rotation_uniform = + glGetUniformLocation(program, "rotation"); +} + +static void +handle_ivi_surface_configure(void *data, struct ivi_surface *ivi_surface, + int32_t width, int32_t height) +{ + struct window *window = data; + + wl_egl_window_resize(window->native, width, height, 0, 0); + + window->geometry.width = width; + window->geometry.height = height; + + if (!window->fullscreen) + window->window_size = window->geometry; +} + +static const struct ivi_surface_listener ivi_surface_listener = { + handle_ivi_surface_configure, +}; + +static void +create_ivi_surface(struct window *window, struct display *display) +{ + uint32_t id_ivisurf = g_id_ivisurf; + window->ivi_surface = + ivi_application_surface_create(display->ivi_application, + id_ivisurf, window->surface); + + if (window->ivi_surface == NULL) { + debug_out("Failed to create ivi_client_surface\n"); + abort(); + } + + ivi_surface_add_listener(window->ivi_surface, + &ivi_surface_listener, window); +} + +static void +create_surface(struct window *window) +{ + struct display *display = window->display; + EGLBoolean ret; + + window->surface = wl_compositor_create_surface(display->compositor); + + window->native = + wl_egl_window_create(window->surface, + window->geometry.width, + window->geometry.height); + window->egl_surface = + weston_platform_create_egl_surface(display->egl.dpy, + display->egl.conf, + window->native, NULL); + + + if (display->ivi_application ) { + create_ivi_surface(window, display); + } else { + assert(0); + } + + ret = eglMakeCurrent(window->display->egl.dpy, window->egl_surface, + window->egl_surface, window->display->egl.ctx); + assert(ret == EGL_TRUE); + + if (!window->frame_sync) + eglSwapInterval(display->egl.dpy, 0); + +} + +static void +destroy_surface(struct window *window) +{ + /* Required, otherwise segfault in egl_dri2.c: dri2_make_current() + * on eglReleaseThread(). */ + eglMakeCurrent(window->display->egl.dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, + EGL_NO_CONTEXT); + + eglDestroySurface(window->display->egl.dpy, window->egl_surface); + wl_egl_window_destroy(window->native); + + if (window->display->ivi_application) + ivi_surface_destroy(window->ivi_surface); + wl_surface_destroy(window->surface); + + if (window->callback) + wl_callback_destroy(window->callback); +} + +static void +redraw(void *data, struct wl_callback *callback, uint32_t time) +{ + struct window *window = data; + struct display *display = window->display; + static const GLfloat verts[3][2] = { + { -0.5, -0.5 }, + { 0.5, -0.5 }, + { 0, 0.5 } + }; + + static const GLfloat colors_H[3][3] = { + { 1, 1, 1 }, + { 1, 1, 1 }, + { 1, 1, 1 } + }; + + static const GLfloat colors_N[3][3] = { + { 1, 0, 0 }, + { 0, 1, 0 }, + { 0, 0, 1 } + }; + + GLfloat angle; + GLfloat rotation[4][4] = { + { 1, 0, 0, 0 }, + { 0, 1, 0, 0 }, + { 0, 0, 1, 0 }, + { 0, 0, 0, 1 } + }; + static const uint32_t speed_div = 5, benchmark_interval = 5; + struct wl_region *region; + EGLint rect[4]; + EGLint buffer_age = 0; + struct timeval tv; + + assert(window->callback == callback); + window->callback = NULL; + + if (callback) + wl_callback_destroy(callback); + + gettimeofday(&tv, NULL); + time = tv.tv_sec * 1000 + tv.tv_usec / 1000; + if (window->frames == 0) + window->benchmark_time = time; + if (time - window->benchmark_time > (benchmark_interval * 1000)) { + debug_out("%d frames in %d seconds: %f fps\n", + window->frames, + benchmark_interval, + (float) window->frames / benchmark_interval); + window->benchmark_time = time; + window->frames = 0; + } + + angle = (time / speed_div) % 360 * M_PI / 180.0; + rotation[0][0] = cos(angle); + rotation[0][2] = sin(angle); + rotation[2][0] = -sin(angle); + rotation[2][2] = cos(angle); + + if (display->swap_buffers_with_damage) + eglQuerySurface(display->egl.dpy, window->egl_surface, + EGL_BUFFER_AGE_EXT, &buffer_age); + + glViewport(0, 0, window->geometry.width, window->geometry.height); + + glUniformMatrix4fv(window->gl.rotation_uniform, 1, GL_FALSE, + (GLfloat *) rotation); + + glClearColor(0.0, 0.0, 0.0, 0.5); + glClear(GL_COLOR_BUFFER_BIT); + + glVertexAttribPointer(window->gl.pos, 2, GL_FLOAT, GL_FALSE, 0, verts); + if(app_name == string("HVAC")){ + glVertexAttribPointer(window->gl.col, 3, GL_FLOAT, GL_FALSE, 0, colors_H); + } + else{ + glVertexAttribPointer(window->gl.col, 3, GL_FLOAT, GL_FALSE, 0, colors_N); + } + glEnableVertexAttribArray(window->gl.pos); + glEnableVertexAttribArray(window->gl.col); + + glDrawArrays(GL_TRIANGLES, 0, 3); + + glDisableVertexAttribArray(window->gl.pos); + glDisableVertexAttribArray(window->gl.col); + + if (window->opaque || window->fullscreen) { + region = wl_compositor_create_region(window->display->compositor); + wl_region_add(region, 0, 0, + window->geometry.width, + window->geometry.height); + wl_surface_set_opaque_region(window->surface, region); + wl_region_destroy(region); + } else { + wl_surface_set_opaque_region(window->surface, NULL); + } + + if (display->swap_buffers_with_damage && buffer_age > 0) { + rect[0] = window->geometry.width / 4 - 1; + rect[1] = window->geometry.height / 4 - 1; + rect[2] = window->geometry.width / 2 + 2; + rect[3] = window->geometry.height / 2 + 2; + display->swap_buffers_with_damage(display->egl.dpy, + window->egl_surface, + rect, 1); + } else { + eglSwapBuffers(display->egl.dpy, window->egl_surface); + } + + window->frames++; +} + +static void +registry_handle_global(void *data, struct wl_registry *registry, + uint32_t name, const char *interface, uint32_t version) +{ + struct display *d = data; + + if (strcmp(interface, "wl_compositor") == 0) { + d->compositor = + wl_registry_bind(registry, name, + &wl_compositor_interface, 1); + } else if (strcmp(interface, "ivi_application") == 0) { + d->ivi_application = + wl_registry_bind(registry, name, + &ivi_application_interface, 1); + } +} + +static void +registry_handle_global_remove(void *data, struct wl_registry *registry, + uint32_t name) +{ +} + +static const struct wl_registry_listener registry_listener = { + registry_handle_global, + registry_handle_global_remove +}; + +static void +signal_int(int signum) +{ + running = 0; +} + +int +init_wm(LibWindowmanager *wm) +{ + char* surfaceIdStr; + + if (wm->init(port, token.c_str()) != 0) { + debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] wm init failed. \n"); + return -1; + } + + if (wm->requestSurface(app_name.c_str()) != 0) { + debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] wm request surface failed \n"); + return -1; + } + + wm->set_event_handler(LibWindowmanager::Event_Active, [](char const *label) { + debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] Surface %s got activated! \n", label); + }); + + wm->set_event_handler(LibWindowmanager::Event_Inactive, [](char const *label) { + debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] Surface %s got inactivated!\n", label); + }); + + wm->set_event_handler(LibWindowmanager::Event_Visible, [wm](char const *label) { + debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] Surface %s got visibled!\n", label); + }); + + wm->set_event_handler(LibWindowmanager::Event_Invisible, [](char const *label) { + debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] Surface %s got invisibled!\n", label); + }); + + wm->set_event_handler(LibWindowmanager::Event_SyncDraw, [wm](char const *label) { + debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] Surface %s got syncdraw!\n", label); + debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] try to endDraw %s \n", app_name.c_str()); + wm->endDraw(app_name.c_str()); + }); + + wm->set_event_handler(LibWindowmanager::Event_FlushDraw, [](char const *label) { + debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] Surface %s got flushdraw! \n", label); + }); + + do + { + surfaceIdStr = getenv("QT_IVI_SURFACE_ID"); + } while (surfaceIdStr == NULL); + + g_id_ivisurf = atoi(surfaceIdStr); + debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] IVI_SURFACE_ID: %d \n", g_id_ivisurf); + + return 0; +} + +int +init_hs(LibHomeScreen* hs){ + if(hs->init(port, token)!=0) + { + debug_out("************** [SIMPLE EGL] [HS SIMPLE >>>>] homescreen init failed. \n"); + return -1; + } + + hs->set_event_handler(LibHomeScreen::Event_TapShortcut, [](const char* application_name){ + debug_out("************** [SIMPLE EGL] [HS SIMPLE >>>>] Event_TapShortcut application_name = %s \n", application_name); + if(strcmp(application_name, app_name.c_str()) == 0) + { + debug_out("************** [SIMPLE EGL] [HS SIMPLE] try to activesurface %s \n", app_name.c_str()); + wm->activateSurface(app_name.c_str()); + } + }); + + hs->set_event_handler(LibHomeScreen::Event_OnScreenMessage, [](const char* display_message){ + debug_out("************** [SIMPLE EGL] [HS SIMPLE >>>>] Event_OnScreenMessage display_message = %s \n", display_message); + }); + + return 0; +} + +int +main(int argc, char **argv) +{ + struct sigaction sigint; + struct window window = { 0 }; + struct display display = { 0 }; + + if(getenv("ENABLE_DEMO_DEBUG")) + { + enable_debug = true; + } + + window.display = &display; + display.window = &window; + window.geometry.width = 1080; + window.geometry.height = 1488; + window.window_size = window.geometry; + window.buffer_size = 32; + window.frame_sync = 1; + + if(argc > 2) + { + if(string(argv[0]).find("hvac") != string::npos) + app_name = string("HVAC"); + port = strtol(argv[1], NULL, 10); + token = argv[2]; + } + + debug_out("************** [SIMPLE EGL] [MAIN] app_name: %s, port: %d, token: %s. \n", app_name.c_str(), port, token.c_str()); + + display.display = wl_display_connect(NULL); + assert(display.display); + + display.registry = wl_display_get_registry(display.display); + wl_registry_add_listener(display.registry, + ®istry_listener, &display); + + wl_display_roundtrip(display.display); + + init_egl(&display, &window); + + wm = new LibWindowmanager(); + hs = new LibHomeScreen(); + + if(init_wm(wm)!=0){ + fini_egl(&display); + if (display.ivi_application) + ivi_application_destroy(display.ivi_application); + if (display.compositor) + wl_compositor_destroy(display.compositor); + wl_registry_destroy(display.registry); + wl_display_flush(display.display); + return -1; + } + + if(init_hs(hs)!=0){ + fini_egl(&display); + if (display.ivi_application) + ivi_application_destroy(display.ivi_application); + if (display.compositor) + wl_compositor_destroy(display.compositor); + wl_registry_destroy(display.registry); + wl_display_flush(display.display); + return -1; + } + + create_surface(&window); + init_gl(&window); + + //Ctrl+C + sigint.sa_handler = signal_int; + sigemptyset(&sigint.sa_mask); + sigint.sa_flags = SA_RESETHAND; + sigaction(SIGINT, &sigint, NULL); + + eglSwapBuffers(display.egl.dpy, window.egl_surface); + wm->activateSurface(app_name.c_str()); + + /* The mainloop here is a little subtle. Redrawing will cause + * EGL to read events so we can just call + * wl_display_dispatch_pending() to handle any events that got + * queued up as a side effect. */ + while (running) { + wl_display_dispatch_pending(display.display); + redraw(&window, NULL, 0); + } + + debug_out("************** [SIMPLE EGL] [MAIN] simple-egl exiting! \n"); + + destroy_surface(&window); + fini_egl(&display); + + if (display.ivi_application) + ivi_application_destroy(display.ivi_application); + + if (display.compositor) + wl_compositor_destroy(display.compositor); + + wl_registry_destroy(display.registry); + wl_display_flush(display.display); + wl_display_disconnect(display.display); + + return 0; +} -- cgit 1.2.3-korg