2 Copyright 2006 Marten Richter
\r
4 This file is part of VOMP.
\r
6 VOMP is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 VOMP is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with VOMP; if not, write to the Free Software
\r
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
23 #include "surfaceopengl.h"
\r
24 #include "osdopengl.h"
\r
29 inline unsigned int InternalColour(unsigned int c){
\r
30 return (c &0x000000FF)<<16 |
\r
32 (c &0x00FF0000)>>16 |
\r
36 SurfaceOpenGL::SurfaceOpenGL(int id)
\r
46 SurfaceOpenGL::~SurfaceOpenGL()
\r
53 glDeleteTextures(1,&gltexture);
\r
58 int SurfaceOpenGL::create(UINT width, UINT height)
\r
60 OsdOpenGL* osd=((OsdOpenGL*)(Osd::getInstance()));
\r
61 //osd->BeginPainting();
\r
64 if (this == screen) { // We do not need locking here, since the osd calls this
\r
68 glGenTextures(1, &gltexture);
\r
70 glBindTexture(GL_TEXTURE_2D, gltexture);
\r
72 void *image = malloc(sheight * swidth * 4);
\r
73 memset(image, 0, sheight * swidth * 4);
\r
74 /* for (int i=0;i< sheight * swidth * 4; i++) { //fill it with garbage, useful for debugging
\r
75 ((char*)image)[i]=i%255;
\r
77 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, swidth, sheight, 0, GL_RGBA,
\r
78 GL_UNSIGNED_BYTE, image);
\r
83 data=(char*)malloc(sizeof(uint32_t)*width*height);
\r
87 //osd->EndPainting();
\r
92 void SurfaceOpenGL::display()
\r
96 int SurfaceOpenGL::fillblt(int x, int y, int width, int height, const DrawStyle& c) {
\r
98 //since this might be called before surface
\r
99 //allocation we will wait in this case, hopefully without deadlocks
\r
100 if (screen == this || !data ) {
\r
101 //This should not happen!
\r
102 srf_mutex.Unlock();
\r
106 /* OsdWin* osd=((OsdWin*)(Osd::getInstance()));
\r
108 osd->BeginPainting();
\r
110 glViewport(0,0,swidth,sheight);*/
\r
112 //osd->EndPainting();
\r
113 srf_mutex.Unlock();
\r
115 unsigned int my_c=InternalColour(c.rgba());
\r
117 int iheight=height;
\r
118 if (height+y>sheight) iheight=sheight-y;
\r
120 if (width+x>swidth) iwidth=swidth-y;
\r
123 unsigned int column;
\r
124 for (line = y; line < (iheight + y); line++) {
\r
125 uint32_t *row = ((unsigned int*) (((char*) data) + (swidth * line + x)
\r
126 * sizeof(uint32_t)));
\r
127 for (column = 0; column < iwidth; column++) {
\r
128 row[column] = my_c;
\r
132 /* if (d3dsurface->UnlockRect() != D3D_OK) {
\r
133 osd->EndPainting();
\r
136 osd->EndPainting();*/
\r
142 void SurfaceOpenGL::startFastDraw(){
\r
146 void SurfaceOpenGL::endFastDraw(){
\r
147 srf_mutex.Unlock();
\r
150 void SurfaceOpenGL::drawPixel(int x, int y, Colour & colour, bool fastdraw) {
\r
151 int c = ( (0xFF000000 )
\r
152 | (colour.red << 16)
\r
153 | (colour.green << 8)
\r
154 | (colour.blue ) );
\r
156 drawPixel(x, y, c, fastdraw);
\r
159 void SurfaceOpenGL::drawPixel(int x, int y, unsigned int c, bool fastdraw) {
\r
160 //FixMe: locking for every single Pixel will be painfully slow
\r
161 if (screen == this) {
\r
162 //This should not happen!
\r
166 return; //why does this happen
\r
170 srf_mutex.Lock(); //since this might be called before surface
\r
172 //allocation we will wait in this case, hopefully without deadlocks
\r
174 //osd = ((OsdWin*) (Osd::getInstance()));
\r
176 if (x >= swidth || y >= sheight)
\r
177 return; //do not draw outside the surface
\r
179 unsigned int my_c=InternalColour(c);
\r
181 unsigned int*row = (unsigned int*) (((char*) data + (swidth * y + x)
\r
182 * sizeof(uint32_t)));
\r
186 srf_mutex.Unlock(); //since this might be called before surface
\r
191 void SurfaceOpenGL::drawHorzLine(int x1, int x2, int y, const DrawStyle& c)
\r
193 fillblt(x1, y, x2-x1, 1, c);
\r
196 void SurfaceOpenGL::drawVertLine(int x, int y1, int y2, const DrawStyle& c)
\r
198 fillblt(x, y1, 1, y2-y1, c);
\r
201 void SurfaceOpenGL::drawBitmap(int x, int y, const Bitmap& bm,const DisplayRegion & region) //region should not matter for SD
\r
203 // Temporary code? Draw one pixel at a time using drawPixel()
\r
205 for (UINT j = 0; j < bm.getHeight(); ++j)
\r
206 for (UINT i = 0; i < bm.getWidth(); ++i)
\r
207 drawPixel(x+i, y+j, bm.getColour(i,j),true);
\r
211 int SurfaceOpenGL::updateToScreen(int sx, int sy, int w, int h, int dx, int dy) // FIXME new, replace others with this FIXME
\r
213 // Log::getInstance()->log("Surface", Log::WARN, "UTS Mark1");
\r
214 srf_mutex.Lock();//since this might be called before surface
\r
215 //allocation we will wait in this case, hopefully without deadlocks
\r
217 OsdOpenGL* osd=((OsdOpenGL*)(Osd::getInstance()));
\r
218 // Log::getInstance()->log("Surface", Log::WARN, "UTS Mark2");
\r
219 GLuint screengltexture=((SurfaceOpenGL*)screen)->getTexture();
\r
221 osd->BeginPainting();
\r
222 // Log::getInstance()->log("Surface", Log::WARN, "UTS Mark3");
\r
223 glBindTexture(GL_TEXTURE_2D, screengltexture);
\r
224 // Log::getInstance()->log("Surface", Log::WARN, "UTS Mark4 %d",glGetError());
\r
226 for (int y=0;y<h;y++) { //hopefully this is not too slow
\r
227 // Log::getInstance()->log("Surface", Log::WARN, "UTS Mark4a %d %d %d %d %d %d",sx,sy,w,h,dx,dy);
\r
228 glTexSubImage2D(GL_TEXTURE_2D,0,dx,(dy+y),w,1,GL_RGBA,GL_UNSIGNED_BYTE,
\r
229 data+((y+sy)*swidth+sx)*sizeof(uint32_t));
\r
234 osd->EndPainting();
\r
236 srf_mutex.Unlock();
\r
241 int SurfaceOpenGL::blt(int fd, unsigned long shandle, int sx, int sy, int width, int height, unsigned long dhandle, int dx, int dy)
\r
243 //I don't see code using this function, so I skip it, since it is a MVP specific interface
\r
247 void SurfaceOpenGL::screenShot(const char* fileName)
\r
249 //Isn't this for debugging only, so I won't implement it yet
\r
252 void SurfaceOpenGL::readPixel(int x, int y, unsigned char* r, unsigned char* g, unsigned char* b)
\r
254 //Isn't this for debugging only, so I won't implement it yet
\r
258 void SurfaceOpenGL::drawJpeg(const char *fileName,int x, int y,int *width, int *height){
\r
260 WaitForSingleObject(event,INFINITE); //since this might be called before surface
\r
261 //allocation we will wait in this case, hopefully without deadlocks
\r
263 return ; //why does this happen
\r
265 OsdWin* osd=((OsdWin*)(Osd::getInstance()));
\r
268 D3DXIMAGE_INFO image_inf;
\r
269 osd->BeginPainting();
\r
270 // D3DXGetImageInfoFromFile(fileName,&image_inf);
\r
271 D3DXGetImageInfoFromResource(NULL,fileName,&image_inf);
\r
272 RECT dest_rec={x,y,x+image_inf.Width,
\r
273 y+image_inf.Height};
\r
274 /* if (D3DXLoadSurfaceFromFile(
\r
282 &image_inf)!=D3D_OK) {
\r
283 Log::getInstance()->log("Surface", Log::DEBUG, "Could not open jpeg!");
\r
286 if (D3DXLoadSurfaceFromResource(
\r
295 &image_inf)!=D3D_OK) {
\r
296 Log::getInstance()->log("Surface", Log::DEBUG, "Could not open jpeg!");
\r
299 osd->EndPainting();
\r
300 *width=image_inf.Width;
\r
301 *height=image_inf.Height;
\r
306 void SurfaceOpenGL::drawJpeg(char *buffer,ULONG buflength,DWORD x, DWORD y,DWORD *width, DWORD *height){
\r
307 WaitForSingleObject(event,INFINITE); //since this might be called before surface
\r
308 //allocation we will wait in this case, hopefully without deadlocks
\r
310 return ; //why does this happen
\r
312 OsdWin* osd=((OsdWin*)(Osd::getInstance()));
\r
315 D3DXIMAGE_INFO image_inf;
\r
316 osd->BeginPainting();
\r
317 // D3DXGetImageInfoFromFile(fileName,&image_inf);
\r
318 D3DXGetImageInfoFromFileInMemory((void*)buffer,buflength,&image_inf);
\r
319 RECT dest_rec={x,y,x+image_inf.Width,
\r
320 y+image_inf.Height};
\r
321 /* if (D3DXLoadSurfaceFromFile(
\r
329 &image_inf)!=D3D_OK) {
\r
330 Log::getInstance()->log("Surface", Log::DEBUG, "Could not open jpeg!");
\r
333 /* if (D3DXLoadSurfaceFromResource(
\r
342 &image_inf)!=D3D_OK) {
\r
343 Log::getInstance()->log("Surface", Log::DEBUG, "Could not open jpeg!");
\r
346 if (D3DXLoadSurfaceFromFileInMemory(
\r
355 &image_inf)!=D3D_OK) {
\r
356 Log::getInstance()->log("Surface", Log::DEBUG, "Could not open jpeg!");
\r
359 osd->EndPainting();
\r
360 *width=image_inf.Width;
\r
361 *height=image_inf.Height;
\r