ScummVM API documentation
display_client.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 PSP_GRAPHICS_H
23 #define PSP_GRAPHICS_H
24 
25 #include "common/singleton.h"
26 #include "graphics/surface.h"
27 #include "common/system.h"
28 #include "backends/platform/psp/memory.h"
29 #include "backends/platform/psp/psppixelformat.h"
30 
31 #define MAX_TEXTURE_SIZE 512
32 
33 class DisplayManager;
34 class GuRenderer;
35 
40 class DisplayClient { // Abstract class
41 public:
42  DisplayClient() {}
43  bool isVisible() { return true; }
44  bool isDirty() { return true; }
45  void setClean() {}
46  void render() {}
47  virtual ~DisplayClient() {}
48 };
49 
53 struct Vertex {
54  float u, v;
55  float x, y, z;
56 };
57 
58 struct Point {
59  int x;
60  int y;
61  Point() : x(0), y(0) {}
62 };
63 
67 struct Dimensions {
68  uint32 width;
69  uint32 height;
70  Dimensions() : width(0), height(0) {}
71 };
72 
78 class Palette {
79 public:
80  Palette() : _values(0), _numOfEntries(0) {}
81  virtual ~Palette() { deallocate(); }
82  bool allocate();
83  void deallocate();
84  void clear();
85  void setPixelFormats(PSPPixelFormat::Type paletteType, PSPPixelFormat::Type bufferType, bool swapRedBlue = false);
86  void setNumOfEntries(uint32 num) { _numOfEntries = num; }
87  uint32 getNumOfEntries() const { return _numOfEntries; }
88  uint32 getSizeInBytes() const { return _pixelFormat.pixelsToBytes(_numOfEntries); }
89  void set(byte *values) { setPartial(values, 0, _numOfEntries); }
90  void setPartial(const byte *colors, uint start, uint num, bool supportsAlpha = false);
91  void getPartial(byte *colors, uint start, uint num) const;
92  uint32 getRawColorAt(uint32 position) const;
93  uint32 getRGBAColorAt(uint32 position) const;
94  void setSingleColorRGBA(uint32 num, byte r, byte g, byte b, byte a);
95  void setColorPositionAlpha(uint32 position, bool alpha);
96  const byte *getRawValues() const { return _values; }
97  byte *getRawValues() { return _values; }
98  bool isAllocated() const { return (_values != 0); }
99  PSPPixelFormat::Type getPixelFormat() const { return _pixelFormat.format; }
100  void print(uint32 numToPrint = 0); // print to screen
101 
102 protected:
103  byte *_values;
104  uint32 _numOfEntries;
106 };
107 
113 class Buffer {
114 public:
115  enum HowToSize {
116  kSizeByTextureSize, // buffer size is determined by power of 2 roundup for texture
117  kSizeBySourceSize // buffer size is determined by source size
118  };
119 
120  Buffer() : _pixels(0), _width(0), _height(0) {}
121  virtual ~Buffer() { deallocate(); }
122 
123  // setters
124  void setSize(uint32 width, uint32 height, HowToSize textureOrSource = kSizeByTextureSize);
125  void setBitsPerPixel(uint32 bits) { _pixelFormat.bitsPerPixel = bits; }
126  void setBytesPerPixel(uint32 bytes) { setBitsPerPixel(bytes << 3); }
127  void setPixelFormat(PSPPixelFormat::Type type, bool swapRedBlue = false);
128 
129  // getters
130  uint32 getWidth() const { return _width; }
131  uint32 getWidthInBytes() const { return _pixelFormat.pixelsToBytes(getWidth()); }
132  uint32 getHeight() const { return _height; }
133  uint32 getSourceWidth() const { return _sourceSize.width; }
134  uint32 getSourceWidthInBytes() const { return _pixelFormat.pixelsToBytes(_sourceSize.width); }
135  uint32 getSourceHeight() const { return _sourceSize.height; }
136  uint32 getTextureWidth() const { return _textureSize.width; }
137  uint32 getTextureHeight() const { return _textureSize.height; }
138  PSPPixelFormat::Type getPixelFormat() const { return _pixelFormat.format; }
139  uint32 getBitsPerPixel() const { return _pixelFormat.bitsPerPixel; }
140  uint32 getBytesPerPixel() const { return getBitsPerPixel() >> 3; } /* won't work for 4-bit */
141  const byte *getPixels() const { return _pixels; }
142  byte *getPixels() { return _pixels; }
143  uint32 getSizeInBytes() const { return _pixelFormat.pixelsToBytes(_width * _height); }
144 
145  bool hasPalette();
146  void copyFromArray(const byte *buffer, int pitch);
147  void copyFromRect(const byte *buf, uint32 pitch, int destX, int destY, uint32 recWidth, uint32 recHeight);
148  void copyToArray(byte *dst, int pitch);
149  bool allocate(bool inVram = false);
150  void deallocate();
151  bool isAllocated() const { return (_pixels != 0) ; }
152  void clear();
153  void flipNibbles(); // To handle peculiarities of PSP's 4 bit textures
154  static uint32 scaleUpToPowerOfTwo(uint32 size);
155  void print(uint32 mask, uint32 numToPrint = 0);
156 
157 protected:
158  friend class GuRenderer;
159  byte *_pixels;
160  uint32 _width;
161  uint32 _height;
165 };
166 
172 class GuRenderer {
173 public:
174  // Constructors
175  GuRenderer() : _useGlobalScaler(false), _buffer(0), _palette(0),
176  _blending(false), _alphaReverse(false), _colorTest(false),
177  _keyColor(0), _fullScreen(false), _stretch(false), _stretchX(1.0f), _stretchY(1.0f) {}
178  GuRenderer(Buffer *buffer, Palette *palette) :
179  _useGlobalScaler(false), _buffer(buffer), _palette(palette),
180  _blending(false), _alphaReverse(false), _colorTest(false),
181  _keyColor(0), _fullScreen(false), _stretch(false), _stretchX(1.0f), _stretchY(1.0f) {}
182  static void setDisplayManager(DisplayManager *dm) { _displayManager = dm; } // Called by the Display Manager
183 
184  // Setters
185  void setDrawSize(uint32 width, uint32 height) { // How big of an area to draw
186  _drawSize.width = width;
187  _drawSize.height = height;
188  }
189  void setDrawWholeBuffer() { // Draw the full size of the current buffer
190  assert(_buffer);
191  _drawSize.width = _buffer->getSourceWidth();
192  _drawSize.height = _buffer->getSourceHeight();
193  }
194  void setBuffer(Buffer *buffer) { _buffer = buffer; }
195  void setPalette(Palette *palette) { _palette = palette; }
196  void setOffsetOnScreen(int x, int y) { _offsetOnScreen.x = x; _offsetOnScreen.y = y; }
197  void setOffsetInBuffer(uint32 x, uint32 y) { _offsetInBuffer.x = x; _offsetInBuffer.y = y; }
198  void setColorTest(bool value) { _colorTest = value; }
199  void setKeyColor(uint32 value) { _keyColor = _buffer->_pixelFormat.convertTo32BitColor(value); }
200  void setAlphaBlending(bool value) { _blending = value; }
201  void setAlphaReverse(bool value) { _alphaReverse = value; }
202  void setFullScreen(bool value) { _fullScreen = value; } // Shortcut for rendering
203  void setUseGlobalScaler(bool value) { _useGlobalScaler = value; } // Scale to screen
204  void setStretch(bool active) { _stretch = active; }
205  void setStretchXY(float x, float y) { _stretchX = x; _stretchY = y; }
206 
207  static void cacheInvalidate(void *pointer, uint32 size);
208 
209  void render(); // Default rendering function. This should be good enough for most purposes
210 
211 protected:
212  // Gu functions
213  void fillVertices(Vertex *vertices); // Fill in vertices with coordinates
214  void guProgramDrawBehavior();
215  Vertex *guGetVertices();
216  void guLoadTexture();
217  void guLoadPalette();
218  void guProgramTextureFormat();
219  void guProgramTextureBitDepth();
220  void guDrawVertices(Vertex *vertices);
221 
222  uint32 convertToGuPixelFormat(PSPPixelFormat::Type format);
223  float scaleSourceToOutput(bool x, float offset);
224  float stretch(bool x, float size);
225 
226  friend class MasterGuRenderer;
227  Point _textureLoadOffset;
232  Palette *_palette;
233  static DisplayManager *_displayManager;
234  Dimensions _drawSize;
235  bool _blending;
236  bool _alphaReverse;
238  uint32 _keyColor;
239  bool _fullScreen;
240  bool _stretch;
241  float _stretchX, _stretchY;
242 };
243 
244 #endif /* PSP_SCREEN_H */
PSPPixelFormat _pixelFormat
pixel format of the palette data
Definition: display_client.h:105
Point _offsetInBuffer
Where on screen to draw
Definition: display_client.h:229
uint32 _height
True allocated height.
Definition: display_client.h:161
bool _stretch
Speeds up for fullscreen rendering
Definition: display_client.h:240
Definition: display_client.h:58
bool _useGlobalScaler
Where in the texture to draw
Definition: display_client.h:230
float _stretchX
Whether zooming is activated
Definition: display_client.h:241
bool _blending
Actual size to draw out of the Buffer
Definition: display_client.h:235
Definition: display_manager.h:72
Dimensions _sourceSize
Original size of the buffer.
Definition: display_client.h:163
bool _colorTest
0 counts as full alpha
Definition: display_client.h:237
Point _offsetOnScreen
For rendering textures > 512 pixels
Definition: display_client.h:228
Definition: display_manager.h:103
Definition: display_client.h:172
uint32 _width
True allocated width.
Definition: display_client.h:160
Definition: display_client.h:53
PSPPixelFormat _pixelFormat
Format of the buffer.
Definition: display_client.h:164
uint32 _numOfEntries
number of palette entries
Definition: display_client.h:104
Definition: display_client.h:113
byte * _values
array of palette data
Definition: display_client.h:103
Definition: display_client.h:67
Dimensions _textureSize
Size rounded up to power of 2. Used for drawing.
Definition: display_client.h:162
Definition: display_client.h:40
bool _fullScreen
Color to test against for color test. in 32 bits.
Definition: display_client.h:239
Definition: psppixelformat.h:34
Buffer * _buffer
Scale to the output size on screen
Definition: display_client.h:231
Definition: atari-screen.h:44