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     int _graphicsMode;
00137     bool _fullscreen;
00138     bool _ar_correction;
00139 
00140     pthread_t _main_thread;
00141 
00142     bool _timer_thread_exit;
00143     pthread_t _timer_thread;
00144     static void *timerThreadFunc(void *arg);
00145 
00146     bool _audio_thread_exit;
00147     pthread_t _audio_thread;
00148     static void *audioThreadFunc(void *arg);
00149 
00150     bool _enable_zoning;
00151     bool _virtkeybd_on;
00152 
00153     Audio::MixerImpl *_mixer;
00154     timeval _startTime;
00155 
00156     Common::String getSystemProperty(const char *name) const;
00157 
00158     void initSurface();
00159     void deinitSurface();
00160     void initViewport();
00161 
00162     void initOverlay();
00163 
00164 #ifdef USE_RGB_COLOR
00165     void initTexture(GLESBaseTexture **texture, uint width, uint height,
00166                         const Graphics::PixelFormat *format);
00167 #endif
00168 
00169     void setupKeymapper();
00170     void setCursorPaletteInternal(const byte *colors, uint start, uint num);
00171 
00172 public:
00173     OSystem_Android(int audio_sample_rate, int audio_buffer_size);
00174     virtual ~OSystem_Android();
00175 
00176     virtual void initBackend();
00177     void enableZoning(bool enable) { _enable_zoning = enable; }
00178 
00179     virtual bool hasFeature(Feature f);
00180     virtual void setFeatureState(Feature f, bool enable);
00181     virtual bool getFeatureState(Feature f);
00182 
00183     virtual const GraphicsMode *getSupportedGraphicsModes() const;
00184     virtual int getDefaultGraphicsMode() const;
00185     virtual bool setGraphicsMode(int mode);
00186     virtual int getGraphicsMode() const;
00187 
00188 #ifdef USE_RGB_COLOR
00189     virtual Graphics::PixelFormat getScreenFormat() const;
00190     virtual Common::List<Graphics::PixelFormat> getSupportedFormats() const;
00191 #endif
00192 
00193     virtual void initSize(uint width, uint height,
00194                             const Graphics::PixelFormat *format);
00195 
00196     enum FixupType {
00197         kClear = 0,     // glClear
00198         kClearSwap,     // glClear + swapBuffers
00199         kClearUpdate    // glClear + updateScreen
00200     };
00201 
00202     void clearScreen(FixupType type, byte count = 1);
00203 
00204     void updateScreenRect();
00205     virtual int getScreenChangeID() const;
00206 
00207     virtual int16 getHeight();
00208     virtual int16 getWidth();
00209 
00210     virtual PaletteManager *getPaletteManager() {
00211         return this;
00212     }
00213 
00214 public:
00215     void pushEvent(int type, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6);
00216     void keyPress(const Common::KeyCode keycode, const KeyReceiver::KeyPressType type);
00217     bool shouldGenerateMouseEvents();
00218 
00219 private:
00220     Common::Queue<Common::Event> _event_queue;
00221     Common::Event _queuedEvent;
00222     uint32 _queuedEventTime;
00223     MutexRef _event_queue_lock;
00224 
00225     Common::Point _touch_pt_down, _touch_pt_scroll, _touch_pt_dt;
00226     int _eventScaleX;
00227     int _eventScaleY;
00228     bool _touchpad_mode;
00229     int _touchpad_scale;
00230     int _trackball_scale;
00231     int _dpad_scale;
00232     int _fingersDown;
00233 
00234     void clipMouse(Common::Point &p);
00235     void scaleMouse(Common::Point &p, int x, int y, bool deductDrawRect = true, bool touchpadMode = false);
00236     void updateEventScale();
00237     void disableCursorPalette();
00238 
00239     TouchControls _touchControls;
00240 
00241     void drawVirtControls();
00242 
00243 protected:
00244     // PaletteManager API
00245     virtual void setPalette(const byte *colors, uint start, uint num);
00246     virtual void grabPalette(byte *colors, uint start, uint num) const;
00247 
00248 public:
00249     virtual void copyRectToScreen(const void *buf, int pitch, int x, int y,
00250                                     int w, int h);
00251     virtual void updateScreen();
00252     virtual Graphics::Surface *lockScreen();
00253     virtual void unlockScreen();
00254     virtual void setShakePos(int shakeOffset);
00255     virtual void fillScreen(uint32 col);
00256     virtual void setFocusRectangle(const Common::Rect& rect);
00257     virtual void clearFocusRectangle();
00258 
00259     virtual void showOverlay();
00260     virtual void hideOverlay();
00261     virtual void clearOverlay();
00262     virtual void grabOverlay(void *buf, int pitch);
00263     virtual void copyRectToOverlay(const void *buf, int pitch,
00264                                     int x, int y, int w, int h);
00265     virtual int16 getOverlayHeight();
00266     virtual int16 getOverlayWidth();
00267     virtual Graphics::PixelFormat getOverlayFormat() const;
00268 
00269     virtual bool showMouse(bool visible);
00270 
00271     virtual void warpMouse(int x, int y);
00272     virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX,
00273                                 int hotspotY, uint32 keycolor,
00274                                 bool dontScale,
00275                                 const Graphics::PixelFormat *format);
00276     virtual void setCursorPalette(const byte *colors, uint start, uint num);
00277 
00278     virtual void pushEvent(const Common::Event &event);
00279     virtual bool pollEvent(Common::Event &event);
00280     virtual uint32 getMillis(bool skipRecord = false);
00281     virtual void delayMillis(uint msecs);
00282 
00283     virtual MutexRef createMutex(void);
00284     virtual void lockMutex(MutexRef mutex);
00285     virtual void unlockMutex(MutexRef mutex);
00286     virtual void deleteMutex(MutexRef mutex);
00287 
00288     virtual void quit();
00289 
00290     virtual void setWindowCaption(const char *caption);
00291     virtual void displayMessageOnOSD(const char *msg);
00292     virtual void showVirtualKeyboard(bool enable);
00293 
00294     virtual Audio::Mixer *getMixer();
00295     virtual void getTimeAndDate(TimeDate &t) const;
00296     virtual void logMessage(LogMessageType::Type type, const char *message);
00297     virtual void addSysArchivesToSearchSet(Common::SearchSet &s,
00298                                             int priority = 0);
00299     virtual bool openUrl(const Common::String &url);
00300     virtual bool hasTextInClipboard();
00301     virtual Common::String getTextFromClipboard();
00302     virtual bool setTextInClipboard(const Common::String &text);
00303     virtual Common::String getSystemLanguage() const;
00304 
00305     // ResidualVM specific method
00306     virtual void launcherInitSize(uint w, uint h);
00307     bool lockMouse(bool lock);
00308     void setupScreen(uint screenW, uint screenH, bool fullscreen, bool accel3d) {
00309         setupScreen(screenW, screenH, fullscreen, accel3d, true);
00310     }
00311     void setupScreen(uint screenW, uint screenH, bool fullscreen, bool accel3d, bool isGame);
00312     Graphics::PixelBuffer getScreenPixelBuffer();
00313 };
00314 
00315 #endif
00316 #endif


Generated on Sat May 25 2019 05:00:38 for ResidualVM by doxygen 1.7.1
curved edge   curved edge