ScummVM API documentation
display_manager.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_DISPLAY_MAN_H
23#define PSP_DISPLAY_MAN_H
24
25#include "backends/platform/psp/thread.h"
26#include "common/list.h"
27
28#define UNCACHED(x) ((byte *)(((uint32)(x)) | 0x40000000)) /* make an uncached access */
29#define CACHED(x) ((byte *)(((uint32)(x)) & 0xBFFFFFFF)) /* make an uncached access into a cached one */
30
34class VramAllocator : public Common::Singleton<VramAllocator> {
35public:
36 VramAllocator() : _bytesAllocated(0) {}
37 void *allocate(int32 size, bool smallAllocation = false); // smallAllocation e.g. palettes
38 void deallocate(void *pointer);
39
40 static inline bool isAddressInVram(void *address) {
41 if ((uint32)(CACHED(address)) >= VRAM_START_ADDRESS && (uint32)(CACHED(address)) < VRAM_END_ADDRESS)
42 return true;
43 return false;
44 }
45
46
47private:
51 struct Allocation {
52 byte *address;
53 uint32 size;
54 void *getEnd() { return address + size; }
55 Allocation(void *Address, uint32 Size) : address((byte *)Address), size(Size) {}
56 Allocation() : address(0), size(0) {}
57 };
58
59 enum {
60 VRAM_START_ADDRESS = 0x04000000,
61 VRAM_END_ADDRESS = 0x04200000,
62 VRAM_SMALL_ADDRESS = VRAM_END_ADDRESS - (4 * 1024) // 4K in the end for small allocations
63 };
64 Common::List <Allocation> _allocList; // List of allocations
65 uint32 _bytesAllocated;
66};
67
68
73public:
74 MasterGuRenderer() : _lastRenderTime(0), _renderFinished(true),
75 _renderSema(1, 1), _callbackId(-1) {}
76 void guInit();
77 void guPreRender();
78 void guPostRender();
79 void guShutDown();
80 bool isRenderFinished() { return _renderFinished; }
81 void sleepUntilRenderFinished();
82 void setupCallbackThread();
83private:
84 virtual void threadFunction(); // for the display callback thread
85 static uint32 _displayList[];
86 uint32 _lastRenderTime; // For measuring rendering time
87 void guProgramDisplayBufferSizes();
88 static int guCallback(int, int, void *__this); // for the display callback
89 bool _renderFinished; // for sync with render callback
90 PspSemaphore _renderSema; // semaphore for syncing
91 int _callbackId; // to keep track of render callback
92};
93
94class Screen;
95class Overlay;
96class Cursor;
97class PSPKeyboard;
98class ImageViewer;
99
104public:
107 FIT_TO_SCREEN,
108 STRETCH_TO_SCREEN
109 };
110 DisplayManager() : _screen(0), _cursor(0), _overlay(0), _keyboard(0),
111 _imageViewer(0), _lastUpdateTime(0), _graphicsMode(0) {}
113
114 void init();
115 bool renderAll(); // return true if rendered or nothing dirty. False otherwise
116 void waitUntilRenderFinished();
117 bool setGraphicsMode(int mode);
118 int getGraphicsMode() const { return _graphicsMode; }
119 uint32 getDefaultGraphicsMode() const { return FIT_TO_SCREEN; }
120 const OSystem::GraphicsMode* getSupportedGraphicsModes() const { return _supportedModes; }
121
122 // Setters for pointers
123 void setScreen(Screen *screen) { _screen = screen; }
124 void setCursor(Cursor *cursor) { _cursor = cursor; }
125 void setOverlay(Overlay *overlay) { _overlay = overlay; }
126 void setKeyboard(PSPKeyboard *keyboard) { _keyboard = keyboard; }
127 void setImageViewer(ImageViewer *imageViewer) { _imageViewer = imageViewer; }
128
129 void setSizeAndPixelFormat(uint width, uint height, const Graphics::PixelFormat *format);
130
131 // Getters
132 float getScaleX() const { return _displayParams.scaleX; }
133 float getScaleY() const { return _displayParams.scaleY; }
134 uint32 getOutputWidth() const { return _displayParams.screenOutput.width; }
135 uint32 getOutputHeight() const { return _displayParams.screenOutput.height; }
136 uint32 getOutputBitsPerPixel() const { return _displayParams.outputBitsPerPixel; }
137 Common::List<Graphics::PixelFormat> getSupportedPixelFormats() const;
138
139private:
140 struct GlobalDisplayParams {
141 Dimensions screenOutput;
142 Dimensions screenSource;
143 float scaleX;
144 float scaleY;
145 uint32 outputBitsPerPixel; // How many bits end up on-screen
146 GlobalDisplayParams() : scaleX(0.0f), scaleY(0.0f), outputBitsPerPixel(0) {}
147 };
148
149 // Pointers to DisplayClients
150 Screen *_screen;
151 Cursor *_cursor;
152 Overlay *_overlay;
153 PSPKeyboard *_keyboard;
154 ImageViewer *_imageViewer;
155
156 MasterGuRenderer _masterGuRenderer;
157 uint32 _lastUpdateTime; // For limiting FPS
158 int _graphicsMode;
159 GlobalDisplayParams _displayParams;
160 static const OSystem::GraphicsMode _supportedModes[];
161
162 void calculateScaleParams(); // calculates scaling factor
163 bool isTimeToUpdate(); // should we update the screen now
164};
165
166
167#endif /* PSP_DISPLAY_MAN_H */
Definition: singleton.h:42
Definition: display_manager.h:103
GraphicsModeID
Definition: display_manager.h:105
@ ORIGINAL_RESOLUTION
‍Possible output formats onscreen
Definition: display_manager.h:106
Definition: image_viewer.h:29
Definition: display_manager.h:72
Definition: default_display_client.h:68
Definition: pspkeyboard.h:37
Definition: thread.h:48
Definition: thread.h:29
Definition: display_manager.h:34
Definition: atari-cursor.h:35
Definition: display_client.h:67
Definition: pixelformat.h:138
Definition: system.h:741
Definition: atari-screen.h:58