ScummVM API documentation
gfxdrivers.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 SCI_GRAPHICS_GFXDRIVERS_H
23 #define SCI_GRAPHICS_GFXDRIVERS_H
24 
25 #include "common/platform.h"
26 #include "common/rect.h"
27 #include "graphics/pixelformat.h"
28 
29 namespace Graphics {
30  class Cursor;
31 }
32 
33 namespace Sci {
34 
35 struct PaletteMod;
36 
37 class GfxDriver {
38 public:
39  GfxDriver(uint16 screenWidth, uint16 screenHeight, int numColors) : _screenW(screenWidth), _screenH(screenHeight), _numColors(numColors), _ready(false), _pixelSize(1) {}
40  virtual ~GfxDriver() {}
41  virtual void initScreen(const Graphics::PixelFormat *srcRGBFormat = nullptr) = 0; // srcRGBFormat: expect incoming data to have the specified rgb pixel format (used for Mac hicolor videos)
42  virtual void setPalette(const byte *colors, uint start, uint num, bool update, const PaletteMod *palMods, const byte *palModMapping) = 0;
43  virtual void copyRectToScreen(const byte *src, int srcX, int srcY, int pitch, int destX, int destY, int w, int h, const PaletteMod *palMods, const byte *palModMapping) = 0;
44  virtual void replaceCursor(const void *cursor, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor) = 0;
45  virtual void replaceMacCursor(const Graphics::Cursor *cursor) = 0;
46  virtual Common::Point getMousePos() const;
47  virtual void setMousePos(const Common::Point &pos) const;
48  virtual void clearRect(const Common::Rect &r) const;
49  virtual void copyCurrentBitmap(byte *dest, uint32 size) const = 0;
50  virtual void copyCurrentPalette(byte *dest, int start, int num) const;
51  virtual void drawTextFontGlyph(const byte *src, int pitch, int hiresDestX, int hiresDestY, int hiresW, int hiresH, int transpColor, const PaletteMod *palMods, const byte *palModMapping) = 0;
52  virtual byte remapTextColor(byte color) const { return color; }
53  virtual bool supportsPalIntensity() const = 0;
54  virtual bool driverBasedTextRendering() const = 0;
55  uint16 numColors() const { return _numColors; }
56  byte pixelSize() const { return _pixelSize; }
57 protected:
58  bool _ready;
59  static bool checkDriver(const char *const *driverNames, int listSize);
60  const uint16 _screenW;
61  const uint16 _screenH;
62  uint16 _numColors;
63  byte _pixelSize;
64 };
65 
66 class GfxDefaultDriver : public GfxDriver {
67 public:
68  GfxDefaultDriver(uint16 screenWidth, uint16 screenHeight, bool isSCI0, bool rgbRendering);
69  ~GfxDefaultDriver() override;
70  void initScreen(const Graphics::PixelFormat *srcRGBFormat) override; // srcRGBFormat: expect incoming data to have the specified rgb pixel format (used for Mac hicolor videos)
71  void setPalette(const byte *colors, uint start, uint num, bool update, const PaletteMod *palMods, const byte *palModMapping) override;
72  void copyRectToScreen(const byte *src, int srcX, int srcY, int pitch, int destX, int destY, int w, int h, const PaletteMod *palMods, const byte *palModMapping) override;
73  void replaceCursor(const void *cursor, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor) override;
74  void replaceMacCursor(const Graphics::Cursor*) override;
75  void copyCurrentBitmap(byte *dest, uint32 size) const override;
76  void copyCurrentPalette(byte *dest, int start, int num) const override;
77  void drawTextFontGlyph(const byte*, int, int, int, int, int, int, const PaletteMod*, const byte*) override; // Only for HiRes fonts. Not implemented here.
78  bool supportsPalIntensity() const override { return true; }
79  bool driverBasedTextRendering() const override { return false; }
80 protected:
81  void updatePalette(const byte *colors, uint start, uint num);
82  byte *_compositeBuffer;
83  byte *_currentBitmap;
84  byte *_currentPalette;
85  byte *_internalPalette;
86  uint16 _virtualW;
87  uint16 _virtualH;
88  Graphics::PixelFormat _format;
89  byte _srcPixelSize;
90  bool _cursorUsesScreenPalette;
91  const bool _alwaysCreateBmpBuffer;
92  const bool _requestRGBMode;
93  typedef void (*ColorConvProc)(byte*, const byte*, int, int, int, const byte*);
94  ColorConvProc _colorConv;
95  typedef void (*ColorConvModProc)(byte*, const byte*, int, int, int, const byte*, const byte*, Graphics::PixelFormat&, const PaletteMod*, const byte*);
96  ColorConvModProc _colorConvMod;
97 private:
98  void generateOutput(byte *dst, const byte *src, int pitch, int w, int h, const PaletteMod *palMods, const byte *palModMapping);
99 };
100 
102 public:
103  SCI0_DOSPreVGADriver(int numColors, int screenW, int screenH, bool rgbRendering);
104  ~SCI0_DOSPreVGADriver() override;
105  void initScreen(const Graphics::PixelFormat*) override;
106  void setPalette(const byte*, uint, uint, bool, const PaletteMod*, const byte*) override {}
107  void replaceMacCursor(const Graphics::Cursor*) override;
108  void copyCurrentBitmap(byte*, uint32) const override;
109  void drawTextFontGlyph(const byte*, int, int, int, int, int, int, const PaletteMod*, const byte*) override; // Only for HiRes fonts. Not implemented here.
110  void copyCurrentPalette(byte *dest, int start, int num) const override;
111  bool supportsPalIntensity() const override { return false; }
112  bool driverBasedTextRendering() const override { return false; }
113 protected:
114  void assignPalette(const byte *colors);
115  byte *_compositeBuffer;
116  const byte *_internalPalette;
117 private:
118  virtual void setupRenderProc() = 0;
119  const bool _requestRGBMode;
120  const byte *_colors;
121 };
122 
123 class SCI0_CGADriver final : public SCI0_DOSPreVGADriver {
124 public:
125  SCI0_CGADriver(bool emulateCGAModeOnEGACard, bool rgbRendering);
126  ~SCI0_CGADriver() override;
127  void copyRectToScreen(const byte *src, int srcX, int srcY, int pitch, int destX, int destY, int w, int h, const PaletteMod*, const byte*) override;
128  void replaceCursor(const void *cursor, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor) override;
129  static bool validateMode(Common::Platform p) { return (p == Common::kPlatformDOS) && checkDriver(&_driverFile, 1); }
130 private:
131  void setupRenderProc() override;
132  uint16 *_cgaPatterns;
133  byte _palette[12];
134  const bool _disableMode5;
135  typedef void (*LineProc)(byte*&, const byte*, int, int, int, const uint16*, const byte*);
136  LineProc _renderLine;
137  static const char *_driverFile;
138 };
139 
141 public:
142  SCI0_CGABWDriver(uint32 monochromeColor, bool rgbRendering);
143  ~SCI0_CGABWDriver() override;
144  void copyRectToScreen(const byte *src, int srcX, int srcY, int pitch, int destX, int destY, int w, int h, const PaletteMod*, const byte*) override;
145  void replaceCursor(const void *cursor, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor) override;
146  Common::Point getMousePos() const override;
147  void setMousePos(const Common::Point &pos) const override;
148  void clearRect(const Common::Rect &r) const override;
149  static bool validateMode(Common::Platform p) { return (p == Common::kPlatformDOS) && checkDriver(_driverFiles, 2); }
150 private:
151  void setupRenderProc() override;
152  byte _monochromePalette[6];
153  const byte *_monochromePatterns;
154  bool _earlyVersion;
155  typedef void (*LineProc)(byte*&, const byte*, int, int, int, const byte*, const byte*);
156  LineProc _renderLine;
157  static const char *_driverFiles[2];
158 };
159 
161 public:
162  SCI0_HerculesDriver(uint32 monochromeColor, bool rgbRendering, bool cropImage);
163  ~SCI0_HerculesDriver() override;
164  void copyRectToScreen(const byte *src, int srcX, int srcY, int pitch, int destX, int destY, int w, int h, const PaletteMod*, const byte*) override;
165  void replaceCursor(const void *cursor, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor) override;
166  Common::Point getMousePos() const override;
167  void setMousePos(const Common::Point &pos) const override;
168  void clearRect(const Common::Rect &r) const override;
169  static bool validateMode(Common::Platform p) { return (p == Common::kPlatformDOS) && checkDriver(&_driverFile, 1); }
170 private:
171  void setupRenderProc() override;
172  const uint16 _centerX;
173  const uint16 _centerY;
174  byte _monochromePalette[6];
175  const byte *_monochromePatterns;
176  typedef void (*LineProc)(byte*&, const byte*, int, int, int, const byte*, const byte*);
177  LineProc _renderLine;
178  static const char *_driverFile;
179 };
180 
182 public:
183  SCI1_VGAGreyScaleDriver(bool rgbRendering);
184  ~SCI1_VGAGreyScaleDriver() override;
185  void setPalette(const byte *colors, uint start, uint num, bool update, const PaletteMod *palMods, const byte *palModMapping) override;
186  static bool validateMode(Common::Platform p) { return (p == Common::kPlatformDOS || p == Common::kPlatformWindows) && checkDriver(&_driverFile, 1); }
187 private:
188  byte *_greyScalePalette;
189  static const char *_driverFile;
190 };
191 
192 class SCI1_EGADriver final : public GfxDriver {
193 public:
194  SCI1_EGADriver(bool rgbRendering);
195  ~SCI1_EGADriver() override;
196  void initScreen(const Graphics::PixelFormat*) override;
197  void setPalette(const byte *colors, uint start, uint num, bool update, const PaletteMod*, const byte*) override;
198  void copyRectToScreen(const byte *src, int srcX, int srcY, int pitch, int destX, int destY, int w, int h, const PaletteMod*, const byte*) override;
199  void replaceCursor(const void *cursor, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor) override;
200  void replaceMacCursor(const Graphics::Cursor *cursor) override {}
201  void copyCurrentBitmap(byte *dest, uint32 size) const override;
202  void copyCurrentPalette(byte *dest, int start, int num) const override;
203  void drawTextFontGlyph(const byte*, int, int, int, int, int, int, const PaletteMod*, const byte*) override; // Only for HiRes fonts. Not implemented here.
204  Common::Point getMousePos() const override;
205  void setMousePos(const Common::Point &pos) const override;
206  void clearRect(const Common::Rect &r) const override;
207  bool supportsPalIntensity() const override { return false; }
208  bool driverBasedTextRendering() const override { return false; }
209  static bool validateMode(Common::Platform p) { return (p == Common::kPlatformDOS || p == Common::kPlatformWindows) && checkDriver(&_driverFile, 1); }
210 private:
211  byte *_compositeBuffer;
212  byte *_currentBitmap;
213  byte *_currentPalette;
214  byte *_egaColorPatterns;
215  uint8 _colAdjust;
216  const byte *_internalPalette;
217  const byte *_egaMatchTable;
218  const bool _requestRGBMode;
219  typedef void (*LineProc)(byte*&, const byte*, int, const byte*, const byte*);
220  LineProc _renderLine;
221  static const char *_driverFile;
222 };
223 
225 public:
226  UpscaledGfxDriver(uint16 screenWidth, uint16 screenHeight, uint16 textAlignX, bool scaleCursor, bool rgbRendering);
227  ~UpscaledGfxDriver() override;
228  void initScreen(const Graphics::PixelFormat *format) override;
229  void setPalette(const byte *colors, uint start, uint num, bool update, const PaletteMod *palMods, const byte *palModMapping) override;
230  void copyRectToScreen(const byte *src, int srcX, int srcY, int pitch, int destX, int destY, int w, int h, const PaletteMod *palMods, const byte *palModMapping) override;
231  void replaceCursor(const void *cursor, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor) override;
232  Common::Point getMousePos() const override;
233  void setMousePos(const Common::Point &pos) const override;
234  void clearRect(const Common::Rect &r) const override;
235  void drawTextFontGlyph(const byte *src, int pitch, int hiresDestX, int hiresDestY, int hiresW, int hiresH, int transpColor, const PaletteMod *palMods, const byte *palModMapping) override; // For HiRes fonts. PC-98 versions bypass the video driver for this and render directly on top of the vram.
236  bool driverBasedTextRendering() const override { return true; }
237 protected:
238  void updateScreen(int destX, int destY, int w, int h, const PaletteMod *palMods, const byte *palModMapping);
239  void adjustCursorBuffer(uint16 newWidth, uint16 newHeight);
240  typedef void (*GlyphRenderProc)(byte*, int, const byte*, int, int, int, int);
241  GlyphRenderProc _renderGlyph;
242  typedef void (*ScaledRenderProc)(byte*, const byte*, int, int, int);
243  ScaledRenderProc _renderScaled;
244  uint16 _textAlignX;
245  byte *_scaledBitmap;
246 private:
247  const bool _scaleCursor;
248  uint16 _cursorWidth;
249  uint16 _cursorHeight;
250  bool _needCursorBuffer;
251 };
252 
254 public:
255  enum SjisFontStyle {
256  kFontStyleNone,
257  kFontStyleTextMode,
258  kFontStyleSpecialSCI1
259  };
260 
261  PC98Gfx16ColorsDriver(int textAlignX, bool cursorScaleWidth, bool cursorScaleHeight, SjisFontStyle sjisFontStyle, bool rgbRendering, bool needsUnditheringPalette);
262  ~PC98Gfx16ColorsDriver() override;
263  void initScreen(const Graphics::PixelFormat *format) override;
264  void setPalette(const byte*, uint, uint, bool, const PaletteMod*, const byte*) override {}
265  void replaceCursor(const void *cursor, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor) override;
266  byte remapTextColor(byte color) const override;
267 private:
268  const byte *_convPalette;
269  const byte *_textModePalette;
270  const bool _cursorScaleHeightOnly;
271  const bool _needsUnditheringPalette;
272  SjisFontStyle _fontStyle;
273 };
274 
276 public:
277  SCI0_PC98Gfx8ColorsDriver(bool cursorScaleHeight, bool useTextModeForSJISChars, bool rgbRendering);
278  ~SCI0_PC98Gfx8ColorsDriver() override;
279  void initScreen(const Graphics::PixelFormat *format) override;
280  void setPalette(const byte*, uint, uint, bool, const PaletteMod*, const byte*) override {}
281  void replaceCursor(const void *cursor, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor) override;
282  byte remapTextColor(byte color) const override;
283  static bool validateMode(Common::Platform p) { return (p == Common::kPlatformPC98) && checkDriver(_driverFiles, 2); }
284 private:
285  const byte *_convPalette;
286  const bool _cursorScaleHeightOnly;
287  const bool _useTextMode;
288  static const char *_driverFiles[2];
289 };
290 
292 public:
293  SCI1_PC98Gfx8ColorsDriver(bool rgbRendering);
294  ~SCI1_PC98Gfx8ColorsDriver() override;
295  void initScreen(const Graphics::PixelFormat *format) override;
296  void setPalette(const byte*, uint, uint, bool, const PaletteMod*, const byte*) override {}
297  void copyRectToScreen(const byte *src, int srcX, int srcY, int pitch, int destX, int destY, int w, int h, const PaletteMod *palMods, const byte *palModMapping) override;
298  void replaceCursor(const void *cursor, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor) override;
299  static bool validateMode(Common::Platform p) { return (p == Common::kPlatformPC98) && checkDriver(&_driverFile, 1); }
300 private:
301  const byte *_ditheringTable;
302  const byte *_convPalette;
303  static const char *_driverFile;
304 };
305 
306 } // End of namespace Sci
307 
308 #endif // SCI_GRAPHICS_GFXDRIVERS_H
Definition: gfxdrivers.h:123
Definition: gfxdrivers.h:160
Definition: gfxdrivers.h:181
Definition: gfxdrivers.h:101
Definition: gfxdrivers.h:253
Definition: pixelformat.h:138
Definition: rect.h:144
Definition: gfxdrivers.h:224
Definition: atari-cursor.h:38
Definition: gfxdrivers.h:192
Definition: cursor.h:42
Definition: gfxdrivers.h:66
Definition: gfxdrivers.h:37
Definition: formatinfo.h:28
Definition: rect.h:45
Definition: gfxdrivers.h:291
Definition: console.h:28
Definition: helpers.h:268
Definition: gfxdrivers.h:140
Definition: gfxdrivers.h:275
Platform
Definition: platform.h:46