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);
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);
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  const byte *getBasePtr(int x, int y) const { return _pixels + _pixelFormat.pixelsToBytes((y * _width) + x); }
144  byte *getBasePtr(int x, int y) { return _pixels + _pixelFormat.pixelsToBytes((y * _width) + x); }
145  uint32 getSizeInBytes() const { return _pixelFormat.pixelsToBytes(_width * _height); }
146 
147  bool hasPalette();
148  void copyFromArray(const byte *buffer, int pitch);
149  void copyFromRect(const byte *buf, uint32 pitch, int destX, int destY, uint32 recWidth, uint32 recHeight);
150  void copyToArray(byte *dst, int pitch);
151  bool allocate(bool inVram = false);
152  void deallocate();
153  bool isAllocated() const { return (_pixels != 0) ; }
154  void clear();
155  void flipNibbles(); // To handle peculiarities of PSP's 4 bit textures
156  static uint32 scaleUpToPowerOfTwo(uint32 size);
157  void print(uint32 mask, uint32 numToPrint = 0);
158 
159 protected:
160  friend class GuRenderer;
161  byte *_pixels;
162  uint32 _width;
163  uint32 _height;
167 };
168 
174 class GuRenderer {
175 public:
176  // Constructors
177  GuRenderer() : _useGlobalScaler(false), _buffer(0), _palette(0),
178  _blending(false), _alphaReverse(false), _colorTest(false),
179  _keyColor(0), _fullScreen(false), _stretch(false), _stretchX(1.0f), _stretchY(1.0f) {}
180  GuRenderer(Buffer *buffer, Palette *palette) :
181  _useGlobalScaler(false), _buffer(buffer), _palette(palette),
182  _blending(false), _alphaReverse(false), _colorTest(false),
183  _keyColor(0), _fullScreen(false), _stretch(false), _stretchX(1.0f), _stretchY(1.0f) {}
184  static void setDisplayManager(DisplayManager *dm) { _displayManager = dm; } // Called by the Display Manager
185 
186  // Setters
187  void setDrawSize(uint32 width, uint32 height) { // How big of an area to draw
188  _drawSize.width = width;
189  _drawSize.height = height;
190  }
191  void setDrawWholeBuffer() { // Draw the full size of the current buffer
192  assert(_buffer);
193  _drawSize.width = _buffer->getSourceWidth();
194  _drawSize.height = _buffer->getSourceHeight();
195  }
196  void setBuffer(Buffer *buffer) { _buffer = buffer; }
197  void setPalette(Palette *palette) { _palette = palette; }
198  void setOffsetOnScreen(int x, int y) { _offsetOnScreen.x = x; _offsetOnScreen.y = y; }
199  void setOffsetInBuffer(uint32 x, uint32 y) { _offsetInBuffer.x = x; _offsetInBuffer.y = y; }
200  void setColorTest(bool value) { _colorTest = value; }
201  void setKeyColor(uint32 value) { _keyColor = value; }
202  void setAlphaBlending(bool value) { _blending = value; }
203  void setAlphaReverse(bool value) { _alphaReverse = value; }
204  void setFullScreen(bool value) { _fullScreen = value; } // Shortcut for rendering
205  void setUseGlobalScaler(bool value) { _useGlobalScaler = value; } // Scale to screen
206  void setStretch(bool active) { _stretch = active; }
207  void setStretchXY(float x, float y) { _stretchX = x; _stretchY = y; }
208 
209  static void cacheInvalidate(void *pointer, uint32 size);
210 
211  void render(); // Default rendering function. This should be good enough for most purposes
212 
213 protected:
214  // Gu functions
215  void fillVertices(Vertex *vertices); // Fill in vertices with coordinates
216  void guProgramDrawBehavior();
217  Vertex *guGetVertices();
218  void guLoadTexture();
219  void guLoadPalette();
220  void guProgramTextureFormat();
221  void guProgramTextureBitDepth();
222  void guDrawVertices(Vertex *vertices);
223 
224  uint32 convertToGuPixelFormat(PSPPixelFormat::Type format);
225  float scaleSourceToOutput(bool x, float offset);
226  float stretch(bool x, float size);
227 
228  friend class MasterGuRenderer;
229  Point _textureLoadOffset;
234  Palette *_palette;
235  static DisplayManager *_displayManager;
236  Dimensions _drawSize;
237  bool _blending;
238  bool _alphaReverse;
240  uint32 _keyColor;
241  bool _fullScreen;
242  bool _stretch;
243  float _stretchX, _stretchY;
244 };
245 
246 #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:231
uint32 _height
True allocated height.
Definition: display_client.h:163
bool _stretch
Speeds up for fullscreen rendering
Definition: display_client.h:242
Definition: display_client.h:58
bool _useGlobalScaler
Where in the texture to draw
Definition: display_client.h:232
float _stretchX
Whether zooming is activated
Definition: display_client.h:243
bool _blending
Actual size to draw out of the Buffer
Definition: display_client.h:237
Definition: display_manager.h:72
Dimensions _sourceSize
Original size of the buffer.
Definition: display_client.h:165
bool _colorTest
0 counts as full alpha
Definition: display_client.h:239
Point _offsetOnScreen
For rendering textures > 512 pixels
Definition: display_client.h:230
Definition: display_manager.h:103
Definition: display_client.h:174
uint32 _width
True allocated width.
Definition: display_client.h:162
Definition: display_client.h:53
PSPPixelFormat _pixelFormat
Format of the buffer.
Definition: display_client.h:166
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:164
Definition: display_client.h:40
bool _fullScreen
Color to test against for color test. in 32 bits.
Definition: display_client.h:241
Definition: psppixelformat.h:34
Buffer * _buffer
Scale to the output size on screen
Definition: display_client.h:233
Definition: atari-screen.h:42