ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

android.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef _ANDROID_H_
00024 #define _ANDROID_H_
00025 
00026 #if defined(__ANDROID__)
00027 
00028 #include "common/fs.h"
00029 #include "common/archive.h"
00030 #include "audio/mixer_intern.h"
00031 #include "graphics/palette.h"
00032 #include "graphics/surface.h"
00033 #include "graphics/pixelbuffer.h"
00034 #include "graphics/opengl/system_headers.h"
00035 #include "graphics/opengl/framebuffer.h"
00036 #include "backends/base-backend.h"
00037 #include "backends/plugins/posix/posix-provider.h"
00038 #include "backends/fs/posix/posix-fs-factory.h"
00039 
00040 #include "backends/platform/android/events.h"
00041 #include "backends/platform/android/texture.h"
00042 #include "backends/platform/android/touchcontrols.h"
00043 
00044 #include <pthread.h>
00045 
00046 #include <android/log.h>
00047 
00048 // toggles start
00049 //#define ANDROID_DEBUG_ENTER
00050 //#define ANDROID_DEBUG_GL
00051 //#define ANDROID_DEBUG_GL_CALLS
00052 // toggles end
00053 
00054 extern const char *android_log_tag;
00055 
00056 #define _ANDROID_LOG(prio, fmt, args...) __android_log_print(prio, android_log_tag, fmt, ## args)
00057 #define LOGD(fmt, args...) _ANDROID_LOG(ANDROID_LOG_DEBUG, fmt, ##args)
00058 #define LOGI(fmt, args...) _ANDROID_LOG(ANDROID_LOG_INFO, fmt, ##args)
00059 #define LOGW(fmt, args...) _ANDROID_LOG(ANDROID_LOG_WARN, fmt, ##args)
00060 #define LOGE(fmt, args...) _ANDROID_LOG(ANDROID_LOG_ERROR, fmt, ##args)
00061 
00062 #ifdef ANDROID_DEBUG_ENTER
00063 #define ENTER(fmt, args...) LOGD("%s(" fmt ")", __FUNCTION__, ##args)
00064 #else
00065 #define ENTER(fmt, args...) do {  } while (false)
00066 #endif
00067 
00068 #ifdef ANDROID_DEBUG_GL
00069 extern void checkGlError(const char *expr, const char *file, int line);
00070 
00071 #ifdef ANDROID_DEBUG_GL_CALLS
00072 #define GLCALLLOG(x, before) \
00073     do { \
00074         if (before) \
00075             LOGD("calling '%s' (%s:%d)", x, __FILE__, __LINE__); \
00076         else \
00077             LOGD("returned from '%s' (%s:%d)", x, __FILE__, __LINE__); \
00078     } while (false)
00079 #else
00080 #define GLCALLLOG(x, before) do {  } while (false)
00081 #endif
00082 
00083 #define GLCALL(x) \
00084     do { \
00085         GLCALLLOG(#x, true); \
00086         (x); \
00087         GLCALLLOG(#x, false); \
00088         checkGlError(#x, __FILE__, __LINE__); \
00089     } while (false)
00090 
00091 #define GLTHREADCHECK \
00092     do { \
00093         assert(pthread_self() == _main_thread); \
00094     } while (false)
00095 
00096 #else
00097 #define GLCALL(x) do { (x); } while (false)
00098 #define GLTHREADCHECK do {  } while (false)
00099 #endif
00100 
00101 class OSystem_Android : public EventsBaseBackend, public PaletteManager, public KeyReceiver {
00102 private:
00103     // passed from the dark side
00104     int _audio_sample_rate;
00105     int _audio_buffer_size;
00106 
00107     int _screen_changeid;
00108     int _egl_surface_width;
00109     int _egl_surface_height;
00110 
00111     bool _force_redraw;
00112 
00113     bool _opengl;
00114 
00115     // Game layer
00116     GLESBaseTexture *_game_texture;
00117     Graphics::PixelBuffer _game_pbuf;
00118     OpenGL::FrameBuffer *_frame_buffer;
00119 
00120     Common::Rect _focus_rect;
00121 
00122     // Overlay layer
00123     GLES4444Texture *_overlay_texture;
00124     bool _show_overlay;
00125 
00126     // Mouse layer
00127     GLESBaseTexture *_mouse_texture;
00128     GLESBaseTexture *_mouse_texture_palette;
00129     GLES5551Texture *_mouse_texture_rgb;
00130     Common::Point _mouse_hotspot;
00131     uint32 _mouse_keycolor;
00132     int _mouse_targetscale;
00133     bool _show_mouse;
00134     bool _use_mouse_palette;
00135 
00136     bool _virtcontrols_on;
00137 
00138     int _graphicsMode;
00139     bool _fullscreen;
00140     bool _ar_correction;
00141 
00142     pthread_t _main_thread;
00143 
00144     bool _timer_thread_exit;
00145     pthread_t _timer_thread;
00146     static void *timerThreadFunc(void *arg);
00147 
00148     bool _audio_thread_exit;
00149     pthread_t _audio_thread;
00150     static void *audioThreadFunc(void *arg);
00151 
00152     bool _enable_zoning;
00153     bool _virtkeybd_on;
00154 
00155     Audio::MixerImpl *_mixer;
00156     timeval _startTime;
00157 
00158     Common::String getSystemProperty(const char *name) const;
00159 
00160     void initSurface();
00161     void deinitSurface();
00162     void initViewport();
00163 
00164     void initOverlay();
00165 
00166 #ifdef USE_RGB_COLOR
00167     Common::String getPixelFormatName(const Graphics::PixelFormat &format) const;
00168     void initTexture(GLESBaseTexture **texture, uint width, uint height,
00169                         const Graphics::PixelFormat *format);
00170 #endif
00171 
00172     void setupKeymapper();
00173     void setCursorPaletteInternal(const byte *colors, uint start, uint num);
00174 
00175 public:
00176     OSystem_Android(int audio_sample_rate, int audio_buffer_size);
00177     virtual ~OSystem_Android();
00178 
00179     virtual void initBackend();
00180     void enableZoning(bool enable) { _enable_zoning = enable; }
00181 
00182     virtual bool hasFeature(Feature f);
00183     virtual void setFeatureState(Feature f, bool enable);
00184     virtual bool getFeatureState(Feature f);
00185 
00186     virtual const GraphicsMode *getSupportedGraphicsModes() const;
00187     virtual int getDefaultGraphicsMode() const;
00188     virtual bool setGraphicsMode(int mode);
00189     virtual int getGraphicsMode() const;
00190 
00191 #ifdef USE_RGB_COLOR
00192     virtual Graphics::PixelFormat getScreenFormat() const;
00193     virtual Common::List<Graphics::PixelFormat> getSupportedFormats() const;
00194 #endif
00195 
00196     virtual void initSize(uint width, uint height,
00197                             const Graphics::PixelFormat *format);
00198 
00199     enum FixupType {
00200         kClear = 0,     // glClear
00201         kClearSwap,     // glClear + swapBuffers
00202         kClearUpdate    // glClear + updateScreen
00203     };
00204 
00205     void clearScreen(FixupType type, byte count = 1);
00206 
00207     void updateScreenRect();
00208     virtual int getScreenChangeID() const;
00209 
00210     virtual int16 getHeight();
00211     virtual int16 getWidth();
00212 
00213     virtual PaletteManager *getPaletteManager() {
00214         return this;
00215     }
00216 
00217 public:
00218     void pushEvent(int type, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6);
00219     void keyPress(const Common::KeyCode keycode, const KeyReceiver::KeyPressType type);
00220 
00221 private:
00222     Common::Queue<Common::Event> _event_queue;
00223     Common::Event _queuedEvent;
00224     uint32 _queuedEventTime;
00225     MutexRef _event_queue_lock;
00226 
00227     Common::Point _touch_pt_down, _touch_pt_scroll, _touch_pt_dt;
00228     int _eventScaleX;
00229     int _eventScaleY;
00230     bool _touchpad_mode;
00231     int _touchpad_scale;
00232     int _trackball_scale;
00233     int _dpad_scale;
00234     int _fingersDown;
00235 
00236     void clipMouse(Common::Point &p);
00237     void scaleMouse(Common::Point &p, int x, int y, bool deductDrawRect = true);
00238     void updateEventScale();
00239     void disableCursorPalette();
00240 
00241     TouchControls _touchControls;
00242 
00243     void drawVirtControls();
00244 
00245 protected:
00246     // PaletteManager API
00247     virtual void setPalette(const byte *colors, uint start, uint num);
00248     virtual void grabPalette(byte *colors, uint start, uint num) const;
00249 
00250 public:
00251     virtual void copyRectToScreen(const void *buf, int pitch, int x, int y,
00252                                     int w, int h);
00253     virtual void updateScreen();
00254     virtual Graphics::Surface *lockScreen();
00255     virtual void unlockScreen();
00256     virtual void setShakePos(int shakeOffset);
00257     virtual void fillScreen(uint32 col);
00258     virtual void setFocusRectangle(const Common::Rect& rect);
00259     virtual void clearFocusRectangle();
00260 
00261     virtual void showOverlay();
00262     virtual void hideOverlay();
00263     virtual void clearOverlay();
00264     virtual void grabOverlay(void *buf, int pitch);
00265     virtual void copyRectToOverlay(const void *buf, int pitch,
00266                                     int x, int y, int w, int h);
00267     virtual int16 getOverlayHeight();
00268     virtual int16 getOverlayWidth();
00269     virtual Graphics::PixelFormat getOverlayFormat() const;
00270 
00271     virtual bool showMouse(bool visible);
00272 
00273     virtual void warpMouse(int x, int y);
00274     virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX,
00275                                 int hotspotY, uint32 keycolor,
00276                                 bool dontScale,
00277                                 const Graphics::PixelFormat *format);
00278     virtual void setCursorPalette(const byte *colors, uint start, uint num);
00279 
00280     virtual void pushEvent(const Common::Event &event);
00281     virtual bool pollEvent(Common::Event &event);
00282     virtual uint32 getMillis(bool skipRecord = false);
00283     virtual void delayMillis(uint msecs);
00284 
00285     virtual MutexRef createMutex(void);
00286     virtual void lockMutex(MutexRef mutex);
00287     virtual void unlockMutex(MutexRef mutex);
00288     virtual void deleteMutex(MutexRef mutex);
00289 
00290     virtual void quit();
00291 
00292     virtual void setWindowCaption(const char *caption);
00293     virtual void displayMessageOnOSD(const char *msg);
00294     virtual void showVirtualKeyboard(bool enable);
00295 
00296     virtual Audio::Mixer *getMixer();
00297     virtual void getTimeAndDate(TimeDate &t) const;
00298     virtual void logMessage(LogMessageType::Type type, const char *message);
00299     virtual void addSysArchivesToSearchSet(Common::SearchSet &s,
00300                                             int priority = 0);
00301     virtual bool openUrl(const Common::String &url);
00302     virtual Common::String getSystemLanguage() const;
00303 
00304     // ResidualVM specific method
00305     virtual void launcherInitSize(uint w, uint h);
00306     bool lockMouse(bool lock);
00307     void setupScreen(uint screenW, uint screenH, bool fullscreen, bool accel3d) {
00308         setupScreen(screenW, screenH, fullscreen, accel3d, true);
00309     }
00310     void setupScreen(uint screenW, uint screenH, bool fullscreen, bool accel3d, bool isGame);
00311     Graphics::PixelBuffer getScreenPixelBuffer();
00312 };
00313 
00314 #endif
00315 #endif


Generated on Sat Feb 16 2019 05:00:44 for ResidualVM by doxygen 1.7.1
curved edge   curved edge