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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "common/scummsys.h"
24 #include "backends/platform/psp/psppixelformat.h"
25 #include "backends/platform/psp/display_client.h"
26 #include "backends/platform/psp/default_display_client.h"
27 
28 //#define __PSP_DEBUG_FUNCS__	/* For debugging the stack */
29 //#define __PSP_DEBUG_PRINT__
30 
31 #include "backends/platform/psp/trace.h"
32 
33 // Class DefaultDisplayClient ---------------------------------------------
34 
allocate(bool bufferInVram,bool paletteInVram)35 bool DefaultDisplayClient::allocate(bool bufferInVram /* = false */, bool paletteInVram /* = false */) {
36 	DEBUG_ENTER_FUNC();
37 
38 	if (!_buffer.allocate(bufferInVram)) {
39 		PSP_ERROR("Couldn't allocate buffer.\n");
40 		return false;
41 	}
42 
43 	if (_buffer.hasPalette()) {
44 		PSP_DEBUG_PRINT("_palette[%p]\n", &_palette);
45 
46 		if (!_palette.allocate()) {
47 			PSP_ERROR("Couldn't allocate palette.\n");
48 			return false;
49 		}
50 	}
51 
52 	return true;
53 }
54 
deallocate()55 void DefaultDisplayClient::deallocate() {
56 	_buffer.deallocate();
57 	if (_buffer.hasPalette())
58 		_palette.deallocate();
59 }
60 
61 
clearBuffer()62 void DefaultDisplayClient::clearBuffer() {
63 	DEBUG_ENTER_FUNC();
64 	_buffer.clear();
65 	setDirty();
66 }
67 
clearPalette()68 inline void DefaultDisplayClient::clearPalette() {
69 	DEBUG_ENTER_FUNC();
70 	_palette.clear();
71 	setDirty();
72 }
73 
init()74 void DefaultDisplayClient::init() {
75 	DEBUG_ENTER_FUNC();
76 	_renderer.setBuffer(&_buffer);
77 	_renderer.setPalette(&_palette);
78 }
79 
copyFromRect(const byte * buf,int pitch,int destX,int destY,int recWidth,int recHeight)80 void DefaultDisplayClient::copyFromRect(const byte *buf, int pitch, int destX, int destY, int recWidth, int recHeight) {
81 	DEBUG_ENTER_FUNC();
82 	_buffer.copyFromRect(buf, pitch, destX, destY, recWidth, recHeight);
83 	setDirty();
84 }
85 
copyToArray(byte * dst,int pitch)86 void DefaultDisplayClient::copyToArray(byte *dst, int pitch) {
87 	DEBUG_ENTER_FUNC();
88 	_buffer.copyToArray(dst, pitch);
89 }
90 
91 // Class Overlay -------------------------------------------------------
92 
init()93 void Overlay::init() {
94 	DEBUG_ENTER_FUNC();
95 
96 	DefaultDisplayClient::init();
97 	_renderer.setAlphaBlending(true);
98 	_renderer.setColorTest(false);
99 	_renderer.setUseGlobalScaler(false);
100 	_renderer.setFullScreen(true);	// speeds up render slightly
101 }
102 
setBytesPerPixel(uint32 size)103 void Overlay::setBytesPerPixel(uint32 size) {
104 	DEBUG_ENTER_FUNC();
105 
106 	switch (size) {
107 	case 1:
108 		_buffer.setPixelFormat(PSPPixelFormat::Type_Palette_8bit);
109 		_palette.setPixelFormats(PSPPixelFormat::Type_4444, PSPPixelFormat::Type_Palette_8bit);
110 		break;
111 	case 2:
112 		_buffer.setPixelFormat(PSPPixelFormat::Type_4444);
113 		break;
114 	case 4:
115 		_buffer.setPixelFormat(PSPPixelFormat::Type_8888);
116 		break;
117 	}
118 }
119 
setSize(uint32 width,uint32 height)120 void Overlay::setSize(uint32 width, uint32 height) {
121 	DEBUG_ENTER_FUNC();
122 	_buffer.setSize(width, height, Buffer::kSizeBySourceSize);
123 	_renderer.setDrawWholeBuffer();	// We need to let the renderer know how much to draw
124 }
125 
copyToArray(void * buf,int pitch)126 void Overlay::copyToArray(void *buf, int pitch) {
127 	DEBUG_ENTER_FUNC();
128 	_buffer.copyToArray((byte *)buf, pitch);
129 }
130 
copyFromRect(const void * buf,int pitch,int x,int y,int w,int h)131 void Overlay::copyFromRect(const void *buf, int pitch, int x, int y, int w, int h) {
132 	DEBUG_ENTER_FUNC();
133 
134 	_buffer.copyFromRect((const byte *)buf, pitch, x, y, w, h);
135 	// debug
136 	//_buffer.print(0xFF);
137 	setDirty();
138 }
139 
allocate()140 bool Overlay::allocate() {
141 	DEBUG_ENTER_FUNC();
142 
143 	bool ret = DefaultDisplayClient::allocate(true, false);	// buffer in VRAM
144 
145 	return ret;
146 }
147 
148 // Class Screen -----------------------------------------------------------
149 
init()150 void Screen::init() {
151 	DEBUG_ENTER_FUNC();
152 
153 	DefaultDisplayClient::init();
154 	_renderer.setAlphaBlending(false);
155 	_renderer.setColorTest(false);
156 	_renderer.setUseGlobalScaler(true);
157 	_renderer.setFullScreen(true);
158 }
159 
setShakePos(int shakeXOffset,int shakeYOffset)160 void Screen::setShakePos(int shakeXOffset, int shakeYOffset) {
161 	_shakeXOffset = shakeXOffset;
162 	_shakeYOffset = shakeYOffset;
163 	_renderer.setOffsetOnScreen(shakeXOffset, shakeYOffset);
164 	setDirty();
165 }
166 
setSize(uint32 width,uint32 height)167 void Screen::setSize(uint32 width, uint32 height) {
168 	DEBUG_ENTER_FUNC();
169 
170 	_buffer.setSize(width, height, Buffer::kSizeBySourceSize);
171 	_renderer.setDrawWholeBuffer();	// We need to let the renderer know how much to draw
172 }
173 
setScummvmPixelFormat(const Graphics::PixelFormat * format)174 void Screen::setScummvmPixelFormat(const Graphics::PixelFormat *format) {
175 	DEBUG_ENTER_FUNC();
176 	PSP_DEBUG_PRINT("format[%p], _buffer[%p], _palette[%p]\n", format, &_buffer, &_palette);
177 
178 	if (!format) {
179 		bzero(&_pixelFormat, sizeof(_pixelFormat));
180 		_pixelFormat.bytesPerPixel = 1;	// default
181 	} else {
182 		_pixelFormat = *format;
183 	}
184 
185 	PSPPixelFormat::Type bufferFormat, paletteFormat;
186 	bool swapRedBlue = false;
187 
188 	PSPPixelFormat::convertFromScummvmPixelFormat(format, bufferFormat, paletteFormat, swapRedBlue);
189 	_buffer.setPixelFormat(bufferFormat, swapRedBlue);
190 	_palette.setPixelFormats(paletteFormat, bufferFormat, swapRedBlue);
191 }
192 
lockAndGetForEditing()193 Graphics::Surface *Screen::lockAndGetForEditing() {
194 	DEBUG_ENTER_FUNC();
195 
196 	_frameBuffer.init(_buffer.getSourceWidth(), _buffer.getSourceHeight(), _buffer.getBytesPerPixel() * _buffer.getWidth(),
197 	                  _buffer.getPixels(), _pixelFormat);
198 	// We'll set to dirty once we unlock the screen
199 
200 	return &_frameBuffer;
201 }
202 
allocate()203 bool Screen::allocate() {
204 	DEBUG_ENTER_FUNC();
205 
206 	return DefaultDisplayClient::allocate(true, false);	// buffer in VRAM
207 }
208