ScummVM API documentation
osys_main.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef BACKENDS_PLATFORM_IPHONE_OSYS_MAIN_H
23 #define BACKENDS_PLATFORM_IPHONE_OSYS_MAIN_H
24 
25 #include "graphics/surface.h"
26 #include "backends/platform/iphone/iphone_common.h"
27 #include "backends/modular-backend.h"
28 #include "common/events.h"
29 #include "audio/mixer_intern.h"
30 #include "backends/fs/posix/posix-fs-factory.h"
31 #include "graphics/palette.h"
32 
33 #include <AudioToolbox/AudioQueue.h>
34 
35 #define AUDIO_BUFFERS 3
36 #define WAVE_BUFFER_SIZE 2048
37 #define AUDIO_SAMPLE_RATE 44100
38 
39 #define SCUMMVM_ROOT_PATH "/var/mobile/Library/ScummVM"
40 #define SCUMMVM_SAVE_PATH SCUMMVM_ROOT_PATH "/Savegames"
41 #define SCUMMVM_PREFS_PATH SCUMMVM_ROOT_PATH "/Preferences"
42 
43 typedef void (*SoundProc)(void *param, byte *buf, int len);
44 typedef int (*TimerProc)(int interval);
45 
46 struct AQCallbackStruct {
47  AudioQueueRef queue;
48  uint32 frameCount;
49  AudioQueueBufferRef buffers[AUDIO_BUFFERS];
50  AudioStreamBasicDescription dataFormat;
51 };
52 
54 protected:
55  static AQCallbackStruct s_AudioQueue;
56  static SoundProc s_soundCallback;
57  static void *s_soundParam;
58 
59  Audio::MixerImpl *_mixer;
60 
61  VideoContext *_videoContext;
62 
63  Graphics::Surface _framebuffer;
64 
65  // For signaling that screen format set up might have failed.
66  TransactionError _gfxTransactionError;
67 
68  // For use with the game texture
69  uint16 _gamePalette[256];
70  // For use with the mouse texture
71  uint16 _gamePaletteRGBA5551[256];
72 
73  struct timeval _startTime;
74  uint32 _timeSuspended;
75 
76  bool _mouseCursorPaletteEnabled;
77  uint16 _mouseCursorPalette[256];
78  Graphics::Surface _mouseBuffer;
79  uint16 _mouseKeyColor;
80  bool _mouseDirty;
81  bool _mouseNeedTextureUpdate;
82 
83  long _lastMouseDown;
84  long _lastMouseTap;
85  long _queuedEventTime;
86  Common::Event _queuedInputEvent;
87  bool _secondaryTapped;
88  long _lastSecondaryDown;
89  long _lastSecondaryTap;
90  int _gestureStartX, _gestureStartY;
91  bool _mouseClickAndDragEnabled;
92  bool _touchpadModeEnabled;
93  int _lastPadX;
94  int _lastPadY;
95  int _lastDragPosX;
96  int _lastDragPosY;
97 
98  int _timerCallbackNext;
99  int _timerCallbackTimer;
100  TimerProc _timerCallback;
101 
102  Common::Array<Common::Rect> _dirtyRects;
103  Common::Array<Common::Rect> _dirtyOverlayRects;
104  ScreenOrientation _screenOrientation;
105  bool _fullScreenIsDirty;
106  bool _fullScreenOverlayIsDirty;
107  int _screenChangeCount;
108 
109 public:
110 
111  OSystem_IPHONE();
112  virtual ~OSystem_IPHONE();
113 
114  virtual void initBackend();
115 
116  virtual void engineInit();
117  virtual void engineDone();
118 
119  virtual bool hasFeature(Feature f);
120  virtual void setFeatureState(Feature f, bool enable);
121  virtual bool getFeatureState(Feature f);
122  virtual void initSize(uint width, uint height, const Graphics::PixelFormat *format);
123 
124  virtual void beginGFXTransaction();
125  virtual TransactionError endGFXTransaction();
126 
127  virtual int16 getHeight();
128  virtual int16 getWidth();
129 
130 #ifdef USE_RGB_COLOR
131  virtual Graphics::PixelFormat getScreenFormat() const { return _framebuffer.format; }
132  virtual Common::List<Graphics::PixelFormat> getSupportedFormats() const;
133 #endif
134 
135  virtual PaletteManager *getPaletteManager() { return this; }
136 protected:
137  // PaletteManager API
138  virtual void setPalette(const byte *colors, uint start, uint num);
139  virtual void grabPalette(byte *colors, uint start, uint num) const;
140 
141 public:
142  virtual void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h);
143  virtual void updateScreen();
144  virtual Graphics::Surface *lockScreen();
145  virtual void unlockScreen();
146  virtual void setShakePos(int shakeXOffset, int shakeYOffset);
147 
148  virtual void showOverlay();
149  virtual void hideOverlay();
150  virtual bool isOverlayVisible() const { return _videoContext->overlayVisible; }
151  virtual void clearOverlay();
152  virtual void grabOverlay(Graphics::Surface &surface);
153  virtual void copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h);
154  virtual int16 getOverlayHeight();
155  virtual int16 getOverlayWidth();
156  virtual Graphics::PixelFormat getOverlayFormat() const;
157 
158  virtual bool showMouse(bool visible);
159 
160  virtual void warpMouse(int x, int y);
161  virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 255, bool dontScale = false, const Graphics::PixelFormat *format = NULL);
162  virtual void setCursorPalette(const byte *colors, uint start, uint num);
163 
164  virtual bool pollEvent(Common::Event &event);
165  virtual uint32 getMillis(bool skipRecord = false);
166  virtual void delayMillis(uint msecs);
167  virtual Common::MutexInternal *createMutex();
168 
169  static void mixCallback(void *sys, byte *samples, int len);
170  virtual void setupMixer(void);
171  virtual void setTimerCallback(TimerProc callback, int interval);
172  virtual int getScreenChangeID() const { return _screenChangeCount; }
173  virtual void quit();
174 
175  virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0);
176  virtual void getTimeAndDate(TimeDate &td, bool skipRecord = false) const;
177 
178  virtual Audio::Mixer *getMixer();
179 
180  void startSoundsystem();
181  void stopSoundsystem();
182 
183  virtual Common::String getDefaultConfigFileName();
184 
185  virtual void logMessage(LogMessageType::Type type, const char *message);
186 
187 protected:
188  void initVideoContext();
189  void updateOutputSurface();
190 
191  void internUpdateScreen();
192  void dirtyFullScreen();
193  void dirtyFullOverlayScreen();
194  void suspendLoop();
195  void drawDirtyRect(const Common::Rect &dirtyRect);
196  void updateMouseTexture();
197  static void AQBufferCallback(void *in, AudioQueueRef inQ, AudioQueueBufferRef outQB);
198  static int timerHandler(int t);
199 
200  bool handleEvent_swipe(Common::Event &event, int direction);
201  void handleEvent_keyPressed(Common::Event &event, int keyPressed);
202  void handleEvent_orientationChanged(int orientation);
203 
204  bool handleEvent_mouseDown(Common::Event &event, int x, int y);
205  bool handleEvent_mouseUp(Common::Event &event, int x, int y);
206 
207  bool handleEvent_secondMouseDown(Common::Event &event, int x, int y);
208  bool handleEvent_secondMouseUp(Common::Event &event, int x, int y);
209 
210  bool handleEvent_mouseDragged(Common::Event &event, int x, int y);
211  bool handleEvent_mouseSecondDragged(Common::Event &event, int x, int y);
212 };
213 
214 #endif
virtual PaletteManager * getPaletteManager()
Definition: osys_main.h:135
Definition: system.h:98
Definition: str.h:59
virtual int getScreenChangeID() const
Definition: osys_main.h:172
Definition: surface.h:53
Definition: pixelformat.h:138
virtual bool isOverlayVisible() const
Definition: osys_main.h:150
Feature
Definition: system.h:334
Definition: list.h:44
Definition: rect.h:144
Type
Definition: system.h:114
Definition: mixer_intern.h:58
Definition: mixer.h:61
TransactionError
Definition: system.h:1036
Definition: archive.h:151
Definition: ios7_osys_main.h:49
Definition: events.h:195
Definition: base-backend.h:43
PixelFormat format
Definition: surface.h:81
Definition: osys_main.h:53
Definition: mutex.h:40
Definition: palette.h:47
Definition: ios7_common.h:70