Panda3D
androidGraphicsWindow.h
1 // Filename: androidGraphicsWindow.h
2 // Created by: rdb (11Jan13)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef ANDROIDGRAPHICSWINDOW_H
16 #define ANDROIDGRAPHICSWINDOW_H
17 
18 #include "pandabase.h"
19 
20 #include "androidGraphicsPipe.h"
21 #include "graphicsWindow.h"
22 #include "buttonHandle.h"
23 
24 #include <android/native_window.h>
25 #include <android/input.h>
26 #include <android/native_activity.h>
27 #include <android/rect.h>
28 
29 struct android_app;
30 
31 ////////////////////////////////////////////////////////////////////
32 // Class : AndroidGraphicsWindow
33 // Description : An interface to manage Android windows and their
34 // appropriate EGL surfaces.
35 ////////////////////////////////////////////////////////////////////
37 public:
39  const string &name,
40  const FrameBufferProperties &fb_prop,
41  const WindowProperties &win_prop,
42  int flags,
44  GraphicsOutput *host);
45  virtual ~AndroidGraphicsWindow();
46 
47  virtual bool begin_frame(FrameMode mode, Thread *current_thread);
48  virtual void end_frame(FrameMode mode, Thread *current_thread);
49  virtual void end_flip();
50 
51  virtual void process_events();
52  virtual void set_properties_now(WindowProperties &properties);
53 
54 protected:
55  virtual void close_window();
56  virtual bool open_window();
57 
58  virtual void destroy_surface();
59  virtual bool create_surface();
60 
61 private:
62  static void handle_command(struct android_app *app, int32_t command);
63  static int32_t handle_input_event(struct android_app *app, AInputEvent *event);
64 
65  void ns_handle_command(int32_t command);
66  int32_t handle_key_event(const AInputEvent *event);
67  int32_t handle_motion_event(const AInputEvent *event);
68 
69  ButtonHandle map_button(int32_t keycode);
70 
71 private:
72  struct android_app* _app;
73 
74  EGLDisplay _egl_display;
75  EGLSurface _egl_surface;
76 
77  const ARect *rect;
78 
79 public:
80  static TypeHandle get_class_type() {
81  return _type_handle;
82  }
83  static void init_type() {
84  GraphicsWindow::init_type();
85  register_type(_type_handle, "AndroidGraphicsWindow",
86  GraphicsWindow::get_class_type());
87  }
88  virtual TypeHandle get_type() const {
89  return get_class_type();
90  }
91  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
92 
93 private:
94  static TypeHandle _type_handle;
95 };
96 
97 #include "androidGraphicsWindow.I"
98 
99 #endif
virtual void end_flip()
This function will be called within the draw thread after begin_flip() has been called on all windows...
virtual void end_frame(FrameMode mode, Thread *current_thread)
This function will be called within the draw thread after rendering is completed for a given frame...
An interface to manage Android windows and their appropriate EGL surfaces.
A window, fullscreen or on a desktop, into which a graphics device sends its output for interactive d...
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:28
A container for the various kinds of properties we might ask to have on a graphics window before we o...
virtual void set_properties_now(WindowProperties &properties)
Applies the requested set of properties to the window, if possible, for instance to request a change ...
An object to create GraphicsOutputs that share a particular 3-D API.
Definition: graphicsPipe.h:58
This is a base class for the various different classes that represent the result of a frame of render...
virtual bool begin_frame(FrameMode mode, Thread *current_thread)
This function will be called within the draw thread before beginning rendering for a given frame...
A thread; that is, a lightweight process.
Definition: thread.h:51
virtual void process_events()
Do whatever processing is necessary to ensure that the window responds to user events.
Encapsulates all the communication with a particular instance of a given rendering backend...
This class is the main interface to controlling the render process.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...