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  enum DrawFlags : uint32 {
40  kHiResMode = 1 << 0,
41  kMovieMode = 1 << 1
42  };
43 
44  GfxDriver(uint16 screenWidth, uint16 screenHeight, int numColors) : _screenW(screenWidth), _screenH(screenHeight), _numColors(numColors), _ready(false), _pixelSize(1) {}
45  virtual ~GfxDriver() {}
46  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)
47  virtual void setPalette(const byte *colors, uint start, uint num, bool update, const PaletteMod *palMods, const byte *palModMapping) = 0;
48  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;
49  virtual void replaceCursor(const void *cursor, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor) = 0;
50  virtual void replaceMacCursor(const Graphics::Cursor *cursor) = 0;
51  virtual Common::Point getMousePos() const;
52  virtual void setMousePos(const Common::Point &pos) const;
53  virtual void setShakePos(int shakeXOffset, int shakeYOffset) const;
54  virtual void clearRect(const Common::Rect &r) const;
55  virtual void copyCurrentBitmap(byte *dest, uint32 size) const = 0;
56  virtual void copyCurrentPalette(byte *dest, int start, int num) const;
57  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;
58  virtual byte remapTextColor(byte color) const { return color; }
59  virtual void setColorMap(const byte *colorMap) {}
60  virtual Common::Point getRealCoords(Common::Point &pos) const { return pos; }
61  virtual void setFlags(uint32 flags) {}
62  virtual void clearFlags(uint32 flags) {}
63  virtual bool supportsPalIntensity() const = 0;
64  virtual bool supportsHiResGraphics() const = 0;
65  virtual bool driverBasedTextRendering() const = 0;
66  uint16 numColors() const { return _numColors; }
67  byte pixelSize() const { return _pixelSize; }
68 
69 protected:
70  bool _ready;
71  static bool checkDriver(const char *const *driverNames, int listSize);
72  const uint16 _screenW;
73  const uint16 _screenH;
74  uint16 _numColors;
75  byte _pixelSize;
76 };
77 
78 class GfxDefaultDriver : public GfxDriver {
79 public:
80  GfxDefaultDriver(uint16 screenWidth, uint16 screenHeight, bool isSCI0, bool rgbRendering);
81  ~GfxDefaultDriver() override;
82  void initScreen(const Graphics::PixelFormat *srcRGBFormat) override; // srcRGBFormat: expect incoming data to have the specified rgb pixel format (used for Mac hicolor videos)
83  void setPalette(const byte *colors, uint start, uint num, bool update, const PaletteMod *palMods, const byte *palModMapping) override;
84  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;
85  void replaceCursor(const void *cursor, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor) override;
86  void replaceMacCursor(const Graphics::Cursor*) override;
87  void copyCurrentBitmap(byte *dest, uint32 size) const override;
88  void copyCurrentPalette(byte *dest, int start, int num) const override;
89  void drawTextFontGlyph(const byte*, int, int, int, int, int, int, const PaletteMod*, const byte*) override; // Only for HiRes fonts. Not implemented here.
90  bool supportsPalIntensity() const override { return true; }
91  bool supportsHiResGraphics() const override { return false; }
92  bool driverBasedTextRendering() const override { return false; }
93 protected:
94  void updatePalette(const byte *colors, uint start, uint num);
95  byte *_compositeBuffer;
96  byte *_currentBitmap;
97  byte *_currentPalette;
98  byte *_internalPalette;
99  uint16 _virtualW;
100  uint16 _virtualH;
101  Graphics::PixelFormat _format;
102  byte _srcPixelSize;
103  bool _cursorUsesScreenPalette;
104  const bool _alwaysCreateBmpBuffer;
105  const bool _requestRGBMode;
106  typedef void (*ColorConvProc)(byte*, const byte*, int, int, int, const byte*);
107  ColorConvProc _colorConv;
108  typedef void (*ColorConvModProc)(byte*, const byte*, int, int, int, const byte*, const byte*, Graphics::PixelFormat&, const PaletteMod*, const byte*);
109  ColorConvModProc _colorConvMod;
110 private:
111  void generateOutput(byte *dst, const byte *src, int pitch, int w, int h, const PaletteMod *palMods, const byte *palModMapping);
112 };
113 
115 public:
116  SCI0_DOSPreVGADriver(int numColors, int screenW, int screenH, bool rgbRendering);
117  ~SCI0_DOSPreVGADriver() override;
118  void initScreen(const Graphics::PixelFormat*) override;
119  void setPalette(const byte*, uint, uint, bool, const PaletteMod*, const byte*) override {}
120  void replaceMacCursor(const Graphics::Cursor*) override;
121  void copyCurrentBitmap(byte*, uint32) const override;
122  void drawTextFontGlyph(const byte*, int, int, int, int, int, int, const PaletteMod*, const byte*) override; // Only for HiRes fonts. Not implemented here.
123  void copyCurrentPalette(byte *dest, int start, int num) const override;
124  bool supportsPalIntensity() const override { return false; }
125  bool supportsHiResGraphics() const override { return false; }
126  bool driverBasedTextRendering() const override { return false; }
127 protected:
128  void assignPalette(const byte *colors);
129  byte *_compositeBuffer;
130  const byte *_internalPalette;
131 private:
132  virtual void setupRenderProc() = 0;
133  const bool _requestRGBMode;
134  const byte *_colors;
135 };
136 
137 class SCI0_CGADriver final : public SCI0_DOSPreVGADriver {
138 public:
139  SCI0_CGADriver(bool emulateCGAModeOnEGACard, bool rgbRendering);
140  ~SCI0_CGADriver() override;
141  void copyRectToScreen(const byte *src, int srcX, int srcY, int pitch, int destX, int destY, int w, int h, const PaletteMod*, const byte*) override;
142  void replaceCursor(const void *cursor, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor) override;
143  static bool validateMode(Common::Platform p) { return (p == Common::kPlatformDOS) && checkDriver(&_driverFile, 1); }
144 private:
145  void setupRenderProc() override;
146  uint16 *_cgaPatterns;
147  byte _palette[12];
148  const bool _disableMode5;
149  typedef void (*LineProc)(byte*&, const byte*, int, int, int, const uint16*, const byte*);
150  LineProc _renderLine;
151  static const char *_driverFile;
152 };
153 
155 public:
156  SCI0_CGABWDriver(uint32 monochromeColor, bool rgbRendering);
157  ~SCI0_CGABWDriver() override;
158  void copyRectToScreen(const byte *src, int srcX, int srcY, int pitch, int destX, int destY, int w, int h, const PaletteMod*, const byte*) override;
159  void replaceCursor(const void *cursor, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor) override;
160  Common::Point getMousePos() const override;
161  void setMousePos(const Common::Point &pos) const override;
162  void setShakePos(int shakeXOffset, int shakeYOffset) const override;
163  void clearRect(const Common::Rect &r) const override;
164  Common::Point getRealCoords(Common::Point &pos) const override;
165  static bool validateMode(Common::Platform p) { return (p == Common::kPlatformDOS) && checkDriver(_driverFiles, 2); }
166 private:
167  void setupRenderProc() override;
168  byte _monochromePalette[6];
169  const byte *_monochromePatterns;
170  bool _earlyVersion;
171  typedef void (*LineProc)(byte*&, const byte*, int, int, int, const byte*, const byte*);
172  LineProc _renderLine;
173  static const char *_driverFiles[2];
174 };
175 
177 public:
178  SCI0_HerculesDriver(uint32 monochromeColor, bool rgbRendering, bool cropImage);
179  ~SCI0_HerculesDriver() override;
180  void copyRectToScreen(const byte *src, int srcX, int srcY, int pitch, int destX, int destY, int w, int h, const PaletteMod*, const byte*) override;
181  void replaceCursor(const void *cursor, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor) override;
182  Common::Point getMousePos() const override;
183  void setMousePos(const Common::Point &pos) const override;
184  void setShakePos(int shakeXOffset, int shakeYOffset) const override;
185  void clearRect(const Common::Rect &r) const override;
186  Common::Point getRealCoords(Common::Point &pos) const override;
187  static bool validateMode(Common::Platform p) { return (p == Common::kPlatformDOS) && checkDriver(&_driverFile, 1); }
188 private:
189  void setupRenderProc() override;
190  const uint16 _centerX;
191  const uint16 _centerY;
192  byte _monochromePalette[6];
193  const byte *_monochromePatterns;
194  typedef void (*LineProc)(byte*&, const byte*, int, int, int, const byte*, const byte*);
195  LineProc _renderLine;
196  static const char *_driverFile;
197 };
198 
200 public:
201  SCI1_VGAGreyScaleDriver(bool rgbRendering);
202  ~SCI1_VGAGreyScaleDriver() override;
203  void setPalette(const byte *colors, uint start, uint num, bool update, const PaletteMod *palMods, const byte *palModMapping) override;
204  static bool validateMode(Common::Platform p) { return (p == Common::kPlatformDOS || p == Common::kPlatformWindows) && checkDriver(&_driverFile, 1); }
205 private:
206  byte *_greyScalePalette;
207  static const char *_driverFile;
208 };
209 
210 class SCI1_EGADriver : public GfxDriver {
211 public:
212  SCI1_EGADriver(bool rgbRendering);
213  ~SCI1_EGADriver() override;
214  void initScreen(const Graphics::PixelFormat*) override;
215  void setPalette(const byte *colors, uint start, uint num, bool update, const PaletteMod*, const byte*) override;
216  void copyRectToScreen(const byte *src, int srcX, int srcY, int pitch, int destX, int destY, int w, int h, const PaletteMod*, const byte*) override;
217  void replaceCursor(const void *cursor, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor) override;
218  void replaceMacCursor(const Graphics::Cursor *cursor) override {}
219  void copyCurrentBitmap(byte *dest, uint32 size) const override;
220  void copyCurrentPalette(byte *dest, int start, int num) const override;
221  void drawTextFontGlyph(const byte*, int, int, int, int, int, int, const PaletteMod*, const byte*) override; // Only for HiRes fonts. Not implemented here.
222  Common::Point getMousePos() const override;
223  void setMousePos(const Common::Point &pos) const override;
224  void setShakePos(int shakeXOffset, int shakeYOffset) const override;
225  void clearRect(const Common::Rect &r) const override;
226  Common::Point getRealCoords(Common::Point &pos) const override;
227  bool supportsPalIntensity() const override { return false; }
228  bool supportsHiResGraphics() const override { return false; }
229  bool driverBasedTextRendering() const override { return false; }
230  static bool validateMode(Common::Platform p) { return (p == Common::kPlatformDOS || p == Common::kPlatformWindows) && checkDriver(&_driverFile, 1); }
231 protected:
232  typedef void (*LineProc)(byte*&, const byte*, int, const byte*, const byte*, bool);
233  LineProc _renderLine;
234  const byte *_convPalette;
235  uint16 _vScaleMult, _vScaleDiv;
236  const byte *_egaMatchTable;
237  byte *_egaColorPatterns;
238  byte *_compositeBuffer;
239  byte *_currentPalette;
240 private:
241  virtual void loadData();
242  virtual void renderBitmap(byte *dst, const byte *src, int pitch, int y, int w, int h, const byte *patterns, const byte *palette, uint16 &realWidth, uint16 &realHeight);
243  byte *_currentBitmap;
244  uint8 _colAdjust;
245  const byte *_internalPalette;
246  const bool _requestRGBMode;
247  static const char *_driverFile;
248 };
249 
251 public:
252  UpscaledGfxDriver(int16 textAlignX, bool scaleCursor, bool rgbRendering);
253  ~UpscaledGfxDriver() override;
254  void initScreen(const Graphics::PixelFormat *format) override;
255  void setPalette(const byte *colors, uint start, uint num, bool update, const PaletteMod *palMods, const byte *palModMapping) override;
256  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;
257  void replaceCursor(const void *cursor, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor) override;
258  Common::Point getMousePos() const override;
259  void setMousePos(const Common::Point &pos) const override;
260  void setShakePos(int shakeXOffset, int shakeYOffset) const override;
261  void clearRect(const Common::Rect &r) const override;
262  Common::Point getRealCoords(Common::Point &pos) const override;
263  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.
264  bool driverBasedTextRendering() const override { return true; }
265 protected:
266  UpscaledGfxDriver(uint16 scaledW, uint16 scaledH, int16 textAlignX, bool scaleCursor, bool rgbRendering);
267  void updateScreen(int destX, int destY, int w, int h, const PaletteMod *palMods, const byte *palModMapping);
268  void adjustCursorBuffer(uint16 newWidth, uint16 newHeight);
269  typedef void (*GlyphRenderProc)(byte*, int, const byte*, int, int, int, int);
270  GlyphRenderProc _renderGlyph;
271  typedef void (*ScaledRenderProc)(byte*, const byte*, int, int, int);
272  ScaledRenderProc _renderScaled;
273  uint16 _textAlignX;
274  uint16 _hScaleMult;
275  uint16 _vScaleMult;
276  uint16 _vScaleDiv;
277  byte *_scaledBitmap;
278 private:
279  virtual void renderBitmap(const byte *src, int pitch, int dx, int dy, int w, int h, int &realWidth, int &realHeight);
280  const bool _scaleCursor;
281  uint16 _cursorWidth;
282  uint16 _cursorHeight;
283  bool _needCursorBuffer;
284 };
285 
286 class KQ6WinGfxDriver final : public UpscaledGfxDriver {
287 public:
288  KQ6WinGfxDriver(bool dosStyleCursors, bool smallWindow, bool rgbRendering);
289  ~KQ6WinGfxDriver() override {}
290  void initScreen(const Graphics::PixelFormat *format) override;
291  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;
292  void replaceCursor(const void *cursor, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor) override;
293  Common::Point getRealCoords(Common::Point &pos) const override;
294  void setColorMap(const byte *colorMap) override { _colorMap = colorMap; }
295  void setFlags(uint32 flags) override;
296  void clearFlags(uint32 flags) override;
297  bool supportsHiResGraphics() const override { return !_smallWindow; }
298 protected:
299  typedef void (*LineProc)(byte*&, const byte*, int, int, int);
300  LineProc _renderLine;
301 private:
302  typedef void (*LineProcSpec)(byte*&, const byte*, int, int, const byte*);
303  LineProcSpec _renderLine2;
304  void renderBitmap(const byte *src, int pitch, int dx, int dy, int w, int h, int &realWidth, int &realHeight) override;
305  uint32 _flags;
306  const byte *_colorMap;
307  const bool _smallWindow;
308  const bool _dosStyleCursors;
309  uint16 _vScaleMult2;
310 };
311 
313 public:
314  // The original does not take into account the extra lines required for the 200->440 vertical scaling. There is a noticeable dithering glitch every 11th line, as the
315  // two pixels of the checkerbox pattern appear in the wrong order. I have implemented a fix for this which can be activated with the fixDithering parameter.
316  KQ6WinGfx16ColorsDriver(bool fixDithering, bool rgbRendering);
317  ~KQ6WinGfx16ColorsDriver() override;
318  void initScreen(const Graphics::PixelFormat *format) override;
319  void replaceCursor(const void *cursor, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor) override;
320  Common::Point getRealCoords(Common::Point &pos) const override;
321  static bool validateMode(Common::Platform p) { return (p == Common::kPlatformDOS || p == Common::kPlatformWindows); }
322 private:
323  void loadData() override;
324  void renderBitmap(byte *dst, const byte *src, int pitch, int y, int w, int h, const byte *patterns, const byte *palette, uint16 &realWidth, uint16 &realHeight) override;
325  LineProc _renderLine2;
326  const bool _enhancedDithering;
327  static const byte _win16ColorsDitherPatterns[512];
328 };
329 
331 public:
332  enum SjisFontStyle {
333  kFontStyleNone,
334  kFontStyleTextMode,
335  kFontStyleSpecialSCI1
336  };
337 
338  PC98Gfx16ColorsDriver(int textAlignX, bool cursorScaleWidth, bool cursorScaleHeight, SjisFontStyle sjisFontStyle, bool rgbRendering, bool needsUnditheringPalette);
339  ~PC98Gfx16ColorsDriver() override;
340  void initScreen(const Graphics::PixelFormat *format) override;
341  void setPalette(const byte*, uint, uint, bool, const PaletteMod*, const byte*) override {}
342  void replaceCursor(const void *cursor, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor) override;
343  byte remapTextColor(byte color) const override;
344 private:
345  const byte *_convPalette;
346  const byte *_textModePalette;
347  const bool _cursorScaleHeightOnly;
348  SjisFontStyle _fontStyle;
349 };
350 
352 public:
353  SCI0_PC98Gfx8ColorsDriver(bool cursorScaleHeight, bool useTextModeForSJISChars, bool rgbRendering);
354  ~SCI0_PC98Gfx8ColorsDriver() override;
355  void initScreen(const Graphics::PixelFormat *format) override;
356  void setPalette(const byte*, uint, uint, bool, const PaletteMod*, const byte*) override {}
357  void replaceCursor(const void *cursor, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor) override;
358  byte remapTextColor(byte color) const override;
359  static bool validateMode(Common::Platform p) { return (p == Common::kPlatformPC98) && checkDriver(_driverFiles, 2); }
360 private:
361  const byte *_convPalette;
362  const bool _cursorScaleHeightOnly;
363  const bool _useTextMode;
364  static const char *_driverFiles[2];
365 };
366 
368 public:
369  SCI1_PC98Gfx8ColorsDriver(bool rgbRendering);
370  ~SCI1_PC98Gfx8ColorsDriver() override;
371  void initScreen(const Graphics::PixelFormat *format) override;
372  void setPalette(const byte*, uint, uint, bool, const PaletteMod*, const byte*) override {}
373  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;
374  void replaceCursor(const void *cursor, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor) override;
375  byte remapTextColor(byte) const override;
376  static bool validateMode(Common::Platform p) { return (p == Common::kPlatformPC98) && checkDriver(&_driverFile, 1); }
377 private:
378  const byte *_ditheringTable;
379  const byte *_convPalette;
380  static const char *_driverFile;
381 };
382 
383 } // End of namespace Sci
384 
385 #endif // SCI_GRAPHICS_GFXDRIVERS_H
Definition: gfxdrivers.h:137
Definition: gfxdrivers.h:176
Definition: gfxdrivers.h:199
Definition: gfxdrivers.h:114
Definition: gfxdrivers.h:330
Definition: pixelformat.h:138
Definition: gfxdrivers.h:286
Definition: rect.h:144
Definition: gfxdrivers.h:250
Definition: gfxdrivers.h:312
Definition: atari-cursor.h:38
Definition: gfxdrivers.h:210
Definition: cursor.h:42
Definition: gfxdrivers.h:78
Definition: gfxdrivers.h:37
Definition: formatinfo.h:28
Definition: rect.h:45
Definition: gfxdrivers.h:367
Definition: console.h:28
Definition: helpers.h:269
Definition: gfxdrivers.h:154
Definition: gfxdrivers.h:351
Platform
Definition: platform.h:46