JeVois  1.17
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
ImGuiBackendMALI.H
Go to the documentation of this file.
1 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2020 by Laurent Itti, the University of Southern
4 // California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5 //
6 // This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7 // redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8 // Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10 // License for more details. You should have received a copy of the GNU General Public License along with this program;
11 // if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12 //
13 // Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14 // Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16 /*! \file */
17 
18 #pragma once
19 
20 #ifdef JEVOIS_PLATFORM_PRO
21 
23 #include <chrono>
24 #include <string>
25 #include <array>
26 
27 #include <wchar.h>
28 #include <wctype.h>
29 
30 //using namespace std::literals;
31 using namespace std::string_literals;
32 //using namespace std::literals::string_literals;
33 
34 //! Helper struct to key track of key states
35 struct input_event_state
36 {
37  int altgr:1;
38  int alt:1;
39  int shift:1;
40  int ctrl:1;
41  int meta:1;
42 };
43 
44 namespace jevois
45 {
46  //! BackendMALI for ImGui on JeVois-Pro
47  /*! This abstract base class provides an interface used by VideoDisplayGUI. Derived implementations are available for
48  SDL2 and Mali framebuffer + evdev.
49 
50  JeVois Pro hardware reports the following:
51 
52  EGL v1.4
53  EGL API is EGL_OPENGL_ES_API
54  OpenGL ES 3.2 git.c8adbf9.122c9daed32dbba4b3056f41a2f23c58 ARM (Mali-G52) GL_VER=3.2
55 
56  OpenGL extensions: GL_ARM_rgba8 GL_ARM_mali_shader_binary GL_OES_depth24 GL_OES_depth_texture
57  GL_OES_depth_texture_cube_map GL_OES_packed_depth_stencil GL_OES_rgb8_rgba8 GL_EXT_read_format_bgra
58  GL_OES_compressed_paletted_texture GL_OES_compressed_ETC1_RGB8_texture GL_OES_standard_derivatives
59  GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_EGL_image_external_essl3 GL_OES_EGL_sync GL_OES_texture_npot
60  GL_OES_vertex_half_float GL_OES_required_internalformat GL_OES_vertex_array_object GL_OES_mapbuffer
61  GL_EXT_texture_format_BGRA8888 GL_EXT_texture_rg GL_EXT_texture_type_2_10_10_10_REV GL_OES_fbo_render_mipmap
62  GL_OES_element_index_uint GL_EXT_shadow_samplers GL_OES_texture_compression_astc
63  GL_KHR_texture_compression_astc_ldr GL_KHR_texture_compression_astc_hdr GL_KHR_texture_compression_astc_sliced_3d
64  GL_EXT_texture_compression_astc_decode_mode GL_EXT_texture_compression_astc_decode_mode_rgb9e5 GL_KHR_debug
65  GL_EXT_occlusion_query_boolean GL_EXT_disjoint_timer_query GL_EXT_blend_minmax GL_EXT_discard_framebuffer
66  GL_OES_get_program_binary GL_OES_texture_3D GL_EXT_texture_storage GL_EXT_multisampled_render_to_texture
67  GL_OES_surfaceless_context GL_OES_texture_stencil8 GL_EXT_shader_pixel_local_storage
68  GL_ARM_shader_framebuffer_fetch GL_ARM_shader_framebuffer_fetch_depth_stencil GL_ARM_mali_program_binary
69  GL_EXT_sRGB GL_EXT_sRGB_write_control GL_EXT_texture_sRGB_decode GL_EXT_texture_sRGB_R8 GL_EXT_texture_sRGB_RG8
70  GL_KHR_blend_equation_advanced GL_KHR_blend_equation_advanced_coherent GL_OES_texture_storage_multisample_2d_array
71  GL_OES_shader_image_atomic GL_EXT_robustness GL_EXT_draw_buffers_indexed GL_OES_draw_buffers_indexed
72  GL_EXT_texture_border_clamp GL_OES_texture_border_clamp GL_EXT_texture_cube_map_array
73  GL_OES_texture_cube_map_array GL_OES_sample_variables GL_OES_sample_shading
74  GL_OES_shader_multisample_interpolation GL_EXT_shader_io_blocks GL_OES_shader_io_blocks GL_EXT_tessellation_shader
75  GL_OES_tessellation_shader GL_EXT_primitive_bounding_box GL_OES_primitive_bounding_box GL_EXT_geometry_shader
76  GL_OES_geometry_shader GL_ANDROID_extension_pack_es31a GL_EXT_gpu_shader5 GL_OES_gpu_shader5 GL_EXT_texture_buffer
77  GL_OES_texture_buffer GL_EXT_copy_image GL_OES_copy_image GL_EXT_shader_non_constant_global_initializers
78  GL_EXT_color_buffer_half_float GL_EXT_color_buffer_float GL_EXT_YUV_target GL_OVR_multiview GL_OVR_multiview2
79  GL_OVR_multiview_multisampled_render_to_texture GL_KHR_robustness GL_KHR_robust_buffer_access_behavior
80  GL_EXT_draw_elements_base_vertex GL_OES_draw_elements_base_vertex GL_EXT_buffer_storage
81  GL_EXT_texture_filter_anisotropic
82 
83  To get correct UTF-8 keyboard translation, you need env var LC_CTYPE to be set, e.g., en_US.UTF-8
84 
85  \ingroup core */
86  class ImGuiBackendMALI : public VideoDisplayBackendMALI
87  {
88  public:
89  //! Constructor
90  ImGuiBackendMALI();
91 
92  //! Virtual destructor for safe inheritance, free resources
93  virtual ~ImGuiBackendMALI();
94 
95  //! Initialize the underlying engine that will process events, create windows, etc
96  /*! The init starts with the given initial window/framebuffer size. If conslock is true, we lock the console and
97  the framebuffer; set to false when running in gdb for debugging, using gdb --args jevoispro-daemon
98  --conslock=false */
99  virtual void init(unsigned short w, unsigned short h, bool fullscreen = false, float scale = 1.0f,
100  bool conslock = true);
101 
102  //! Poll events such as mouse movements, buttons, keyboard, joystick, and pass to ImGui
103  /*! Returns true if some events were received, which can be used to turn on mouse pointer and GUI. */
104  virtual bool pollEvents(bool & shouldclose) override;
105 
106  //! Start a new frame and clear the window/framebuffer
107  virtual void newFrame() override;
108 
109  //! Render the ImGui graphics
110  virtual void render() override;
111 
112  protected:
113  std::chrono::time_point<std::chrono::steady_clock> itsLastNewFrameTime;
114  int itsFd[32];
115  void scanDevices();
116  void addDevice(size_t num, int fd);
117  void removeDevice(size_t num);
118  int itsMouseX, itsMouseY;
119  bool itsMouseButton[5];
120  int itsConsoleFd;
121  int itsTTY;
122  int itsKBmode;
123  int itsWidth = 0, itsHeight = 0;
124 
125  std::array<wchar_t, 49> itsCharKeys { L"1234567890-=qwertyuiop[]asdfghjkl;'`\\zxcvbnm,./<" };
126  std::array<wchar_t, 49> itsShiftKeys { L"!@#$%^&*()_+QWERTYUIOP{}ASDFGHJKL:\"~|ZXCVBNM<>?>" };
127  std::array<wchar_t, 49> itsAltgrKeys = { 0 };
128  static constexpr wchar_t itsFuncKeys[58][8] =
129  {
130  L"<Esc>", L"<BckSp>", L"<Tab>", L"<Enter>", L"<LCtrl>", L"<LShft>",
131  L"<RShft>", L"<KP*>", L"<LAlt>", L" ", L"<CpsLk>", L"<F1>", L"<F2>",
132  L"<F3>", L"<F4>", L"<F5>", L"<F6>", L"<F7>", L"<F8>", L"<F9>", L"<F10>",
133  L"<NumLk>", L"<ScrLk>", L"<KP7>", L"<KP8>", L"<KP9>", L"<KP->", L"<KP4>",
134  L"<KP5>", L"<KP6>", L"<KP+>", L"<KP1>", L"<KP2>", L"<KP3>", L"<KP0>",
135  L"<KP.>", /*"<",*/ L"<F11>", L"<F12>", L"<KPEnt>", L"<RCtrl>", L"<KP/>",
136  L"<PrtSc>", L"<AltGr>", L"<Break>" /*linefeed?*/, L"<Home>", L"<Up>",
137  L"<PgUp>", L"<Left>", L"<Right>", L"<End>", L"<Down>", L"<PgDn>",
138  L"<Ins>", L"<Del>", L"<Pause>", L"<LMeta>", L"<RMeta>", L"<Menu>"
139  };
140 
141  input_event_state itsInputState = { };
142  char itsInputBuffer[256] = { 0 };
143  };
144 
145 } // namespace jevois
146 
147 #endif // JEVOIS_PLATFORM_PRO
jevois
Definition: Concepts.dox:1
VideoDisplayBackendMALI.H
L
#define L(i, x, y, z)
Definition: GUIhelper.C:2158
h
int h
Definition: GUIhelper.C:2157