/*\r
- Copyright 2004-2005 Chris Tallon\r
- Portions copyright 2004 Jon Gettler\r
+ Copyright 2006 Marten Richter\r
\r
This file is part of VOMP.\r
\r
SurfaceWin::SurfaceWin(int id)\r
: Surface(id)\r
{\r
- d3dtexture=NULL;\r
- d3dsurface=NULL;\r
- sheight=swidth=0;\r
- event = CreateEvent(NULL,/*FALSE*/TRUE,FALSE,NULL);\r
+ d3dtexture=NULL;\r
+ d3dsurface=NULL;\r
+ sheight=swidth=0;\r
+ event = CreateEvent(NULL,/*FALSE*/TRUE,FALSE,NULL);\r
}\r
\r
SurfaceWin::~SurfaceWin()\r
{\r
- if (d3dsurface) d3dsurface->Release();\r
- if (d3dtexture) d3dtexture->Release();\r
- CloseHandle(event);\r
+ if (d3dsurface) d3dsurface->Release();\r
+ if (d3dtexture) d3dtexture->Release();\r
+ CloseHandle(event);\r
}\r
\r
int SurfaceWin::create(UINT width, UINT height)\r
{\r
- LPDIRECT3DDEVICE9 d3ddev=((OsdWin*)(Osd::getInstance()))->getD3dDev();\r
- while (true) {\r
- if (screen==this) {\r
- if (d3ddev->CreateTexture(1024,1024,0,0,D3DFMT_A8R8G8B8,\r
- // Does every adapter with alpha blending support this?\r
- D3DPOOL_DEFAULT,&d3dtexture ,NULL)!=D3D_OK) {\r
- MILLISLEEP(50);//wait maybe next time it will work\r
- continue;\r
- }\r
- if (d3dtexture->GetSurfaceLevel(0,&d3dsurface)!=D3D_OK) {\r
- d3dtexture->Release();\r
- d3dtexture=NULL;\r
- MILLISLEEP(50);\r
- continue;\r
- }\r
- } else {\r
- HRESULT hres;\r
- if (hres=d3ddev->CreateOffscreenPlainSurface(width,height,D3DFMT_A8R8G8B8,\r
- D3DPOOL_SYSTEMMEM,&d3dsurface,NULL)!=D3D_OK) {\r
- MILLISLEEP(50);//wait maybe next time it will work\r
- continue;\r
- }\r
-\r
- }\r
- sheight=height;\r
- swidth=width;\r
- /* If someone does high performance Animations on the OSD, we have to change the types\r
- of surface in order to address these performance issues, if we have only very few updates \r
- per second this would be fast enough !*/\r
- break;\r
- }\r
- SetEvent(event);\r
- return 1;\r
+ LPDIRECT3DDEVICE9 d3ddev=((OsdWin*)(Osd::getInstance()))->getD3dDev();\r
+ while (true) {\r
+ if (screen==this) {\r
+ if (d3ddev->CreateTexture(1024,1024,0,0,D3DFMT_A8R8G8B8,\r
+ // Does every adapter with alpha blending support this?\r
+ D3DPOOL_DEFAULT,&d3dtexture ,NULL)!=D3D_OK) {\r
+ MILLISLEEP(50);//wait maybe next time it will work\r
+ continue;\r
+ }\r
+ if (d3dtexture->GetSurfaceLevel(0,&d3dsurface)!=D3D_OK) {\r
+ d3dtexture->Release();\r
+ d3dtexture=NULL;\r
+ MILLISLEEP(50);\r
+ continue;\r
+ }\r
+ } else {\r
+ HRESULT hres;\r
+ if (hres=d3ddev->CreateOffscreenPlainSurface(width,height,D3DFMT_A8R8G8B8,\r
+ D3DPOOL_SYSTEMMEM,&d3dsurface,NULL)!=D3D_OK) {\r
+ MILLISLEEP(50);//wait maybe next time it will work\r
+ continue;\r
+ }\r
+\r
+ }\r
+ sheight=height;\r
+ swidth=width;\r
+ /* If someone does high performance Animations on the OSD, we have to change the types\r
+ of surface in order to address these performance issues, if we have only very few updates\r
+ per second this would be fast enough !*/\r
+ break;\r
+ }\r
+ SetEvent(event);\r
+ return 1;\r
}\r
\r
void SurfaceWin::display()\r
WaitForSingleObject(event,INFINITE); //since this might be called before surface\r
//allocation we will wait in this case, hopefully without deadlocks\r
OsdWin* osd=((OsdWin*)(Osd::getInstance()));\r
- \r
+\r
if (!d3dsurface) {\r
- return 0; //why does this happen\r
+ return 0; //why does this happen\r
}\r
\r
LPDIRECT3DDEVICE9 d3ddev=osd->getD3dDev();\r
- \r
+\r
if (screen==this) {\r
- //This should not happen!\r
- return 0;\r
+ //This should not happen!\r
+ return 0;\r
\r
} else {\r
- osd->BeginPainting();\r
- D3DLOCKED_RECT lockrect;\r
- int cx,cy,cwidth,cheight;\r
- cx=min(max(x,0),swidth);\r
- cy=min(max(y,0),sheight);\r
- cwidth=min(width,swidth-x);\r
- cheight=min(height,sheight-y);\r
- RECT rect={cx,cy,cwidth,cheight};\r
- \r
- if (d3dsurface->LockRect(&lockrect,&rect,D3DLOCK_DISCARD)!=D3D_OK) {\r
- return 0;\r
- }\r
- unsigned int line;\r
- unsigned int column;\r
- for (line=0;line<cheight;line++) {\r
- unsigned int*row=((unsigned int*)(((char*)lockrect.pBits)+lockrect.Pitch*line));\r
- for (column=0;column<cwidth;column++) {\r
- row[column]=c;\r
- }\r
- }\r
-\r
- if (d3dsurface->UnlockRect()!=D3D_OK) {\r
- osd->EndPainting();\r
- return 0;\r
- }\r
- osd->EndPainting();\r
+ osd->BeginPainting();\r
+ D3DLOCKED_RECT lockrect;\r
+ int cx,cy,cwidth,cheight;\r
+ cx=min(max(x,0),swidth);\r
+ cy=min(max(y,0),sheight);\r
+ cwidth=min(width,swidth-x);\r
+ cheight=min(height,sheight-y);\r
+ RECT rect={cx,cy,cwidth,cheight};\r
+\r
+ if (d3dsurface->LockRect(&lockrect,&rect,D3DLOCK_DISCARD)!=D3D_OK) {\r
+ return 0;\r
+ }\r
+ unsigned int line;\r
+ unsigned int column;\r
+ for (line=0;line<cheight;line++) {\r
+ unsigned int*row=((unsigned int*)(((char*)lockrect.pBits)+lockrect.Pitch*line));\r
+ for (column=0;column<cwidth;column++) {\r
+ row[column]=c;\r
+ }\r
+ }\r
+\r
+ if (d3dsurface->UnlockRect()!=D3D_OK) {\r
+ osd->EndPainting();\r
+ return 0;\r
+ }\r
+ osd->EndPainting();\r
}\r
\r
return 0;\r
WaitForSingleObject(event,INFINITE); //since this might be called before surface\r
//allocation we will wait in this case, hopefully without deadlocks\r
if (!d3dsurface) {\r
- return; //why does this happen\r
+ return; //why does this happen\r
}\r
OsdWin* osd=((OsdWin*)(Osd::getInstance()));\r
LPDIRECT3DDEVICE9 d3ddev=osd->getD3dDev();\r
if (x>swidth || y>sheight) return; //do not draw outside the surface\r
if (screen==this) {\r
- //This should not happen!\r
- return ;\r
+ //This should not happen!\r
+ return ;\r
\r
} else {\r
- osd->BeginPainting();\r
- D3DLOCKED_RECT lockrect;\r
- RECT rect={x,y,x+1,y+1};\r
- if (d3dsurface->LockRect(&lockrect,&rect,D3DLOCK_DISCARD)!=D3D_OK) {\r
- osd->EndPainting();\r
- return ;\r
- }\r
- unsigned int*row=(unsigned int*)(((char*)lockrect.pBits));\r
- row[0]=c;\r
- if (d3dsurface->UnlockRect()!=D3D_OK) {\r
- osd->EndPainting();\r
- return ;\r
- }\r
- osd->EndPainting();\r
+ osd->BeginPainting();\r
+ D3DLOCKED_RECT lockrect;\r
+ RECT rect={x,y,x+1,y+1};\r
+ if (d3dsurface->LockRect(&lockrect,&rect,D3DLOCK_DISCARD)!=D3D_OK) {\r
+ osd->EndPainting();\r
+ return ;\r
+ }\r
+ unsigned int*row=(unsigned int*)(((char*)lockrect.pBits));\r
+ row[0]=c;\r
+ if (d3dsurface->UnlockRect()!=D3D_OK) {\r
+ osd->EndPainting();\r
+ return ;\r
+ }\r
+ osd->EndPainting();\r
}\r
\r
}\r
\r
void SurfaceWin::drawHorzLine(int x1, int x2, int y, unsigned int c)\r
{\r
- fillblt(x1, y, x2-x1, 1, c);\r
+ fillblt(x1, y, x2-x1, 1, c);\r
}\r
\r
void SurfaceWin::drawVertLine(int x, int y1, int y2, unsigned int c)\r
{\r
- fillblt(x, y1, 1, y2-y1, c);\r
+ fillblt(x, y1, 1, y2-y1, c);\r
}\r
\r
int SurfaceWin::updateToScreen(int sx, int sy, int w, int h, int dx, int dy) // FIXME new, replace others with this FIXME\r
{\r
- WaitForSingleObject(event,INFINITE); //since this might be called before surface\r
+ WaitForSingleObject(event,INFINITE); //since this might be called before surface\r
//allocation we will wait in this case, hopefully without deadlocks\r
- if (!d3dsurface) {\r
- return 0; //why does this happen\r
- }\r
- OsdWin* osd=((OsdWin*)(Osd::getInstance()));\r
- LPDIRECT3DDEVICE9 d3ddev=osd->getD3dDev();\r
+ if (!d3dsurface) {\r
+ return 0; //why does this happen\r
+ }\r
+ OsdWin* osd=((OsdWin*)(Osd::getInstance()));\r
+ LPDIRECT3DDEVICE9 d3ddev=osd->getD3dDev();\r
LPDIRECT3DSURFACE9 screensurface=((SurfaceWin*)screen)->getD3dsurface();\r
- if (!screensurface) return 0;\r
- RECT sourcerect={sx,sy,sx+w,sy+h};\r
- POINT destpoint={dx,dy};\r
- osd->BeginPainting();\r
- if (d3ddev->UpdateSurface(d3dsurface,&sourcerect,screensurface,&destpoint)!=D3D_OK) {\r
- Log::getInstance()->log("Surface", Log::DEBUG, "Could not update to Screen!");\r
- osd->EndPainting();\r
- return 0;\r
- }\r
- osd->EndPainting();\r
- return 0;\r
+ if (!screensurface) return 0;\r
+ RECT sourcerect={sx,sy,sx+w,sy+h};\r
+ POINT destpoint={dx,dy};\r
+ osd->BeginPainting();\r
+ if (d3ddev->UpdateSurface(d3dsurface,&sourcerect,screensurface,&destpoint)!=D3D_OK) {\r
+ Log::getInstance()->log("Surface", Log::DEBUG, "Could not update to Screen!");\r
+ osd->EndPainting();\r
+ return 0;\r
+ }\r
+ osd->EndPainting();\r
+ return 0;\r
}\r
\r
int SurfaceWin::blt(int fd, unsigned long shandle, int sx, int sy, int width, int height, unsigned long dhandle, int dx, int dy)\r
\r
void SurfaceWin::screenShot(char* fileName)\r
{\r
- //Isn't this for debugging only, so I won't implement it yet\r
+ //Isn't this for debugging only, so I won't implement it yet\r
}\r
\r
void SurfaceWin::readPixel(int x, int y, unsigned char* r, unsigned char* g, unsigned char* b)\r
{\r
- //Isn't this for debugging only, so I won't implement it yet\r
+ //Isn't this for debugging only, so I won't implement it yet\r
}\r
void SurfaceWin::ReleaseSurface()\r
{\r
- ResetEvent(event);\r
- LPDIRECT3DSURFACE9 temp_surf=d3dsurface;\r
- LPDIRECT3DTEXTURE9 temp_text=d3dtexture;\r
- d3dsurface=NULL;\r
- d3dtexture=NULL;\r
- sheight=swidth=0;\r
- if (temp_surf) temp_surf->Release();\r
- if (temp_text) temp_text->Release();\r
+ ResetEvent(event);\r
+ LPDIRECT3DSURFACE9 temp_surf=d3dsurface;\r
+ LPDIRECT3DTEXTURE9 temp_text=d3dtexture;\r
+ d3dsurface=NULL;\r
+ d3dtexture=NULL;\r
+ sheight=swidth=0;\r
+ if (temp_surf) temp_surf->Release();\r
+ if (temp_text) temp_text->Release();\r
}\r
\r
void SurfaceWin::drawJpeg(char *fileName,DWORD x, DWORD y,DWORD *width, DWORD *height){\r
- WaitForSingleObject(event,INFINITE); //since this might be called before surface\r
+ WaitForSingleObject(event,INFINITE); //since this might be called before surface\r
//allocation we will wait in this case, hopefully without deadlocks\r
- if (!d3dsurface) {\r
- return ; //why does this happen\r
- }\r
- OsdWin* osd=((OsdWin*)(Osd::getInstance()));\r
-\r
- \r
- D3DXIMAGE_INFO image_inf;\r
- osd->BeginPainting();\r
-// D3DXGetImageInfoFromFile(fileName,&image_inf);\r
- D3DXGetImageInfoFromResource(NULL,fileName,&image_inf);\r
- RECT dest_rec={x,y,x+image_inf.Width,\r
- y+image_inf.Height};\r
-/* if (D3DXLoadSurfaceFromFile(\r
- d3dsurface,\r
- NULL,\r
- &dest_rec,\r
- fileName,\r
- NULL,\r
- D3DX_FILTER_NONE,\r
- 0,\r
- &image_inf)!=D3D_OK) {\r
- Log::getInstance()->log("Surface", Log::DEBUG, "Could not open jpeg!");\r
- \r
- }*/\r
- if (D3DXLoadSurfaceFromResource(\r
- d3dsurface,\r
- NULL,\r
- &dest_rec,\r
- NULL,\r
- fileName,\r
- NULL,\r
- D3DX_FILTER_NONE,\r
- 0,\r
- &image_inf)!=D3D_OK) {\r
- Log::getInstance()->log("Surface", Log::DEBUG, "Could not open jpeg!");\r
- \r
- }\r
- osd->EndPainting();\r
- *width=image_inf.Width;\r
- *height=image_inf.Height;\r
- \r
+ if (!d3dsurface) {\r
+ return ; //why does this happen\r
+ }\r
+ OsdWin* osd=((OsdWin*)(Osd::getInstance()));\r
+\r
+\r
+ D3DXIMAGE_INFO image_inf;\r
+ osd->BeginPainting();\r
+// D3DXGetImageInfoFromFile(fileName,&image_inf);\r
+ D3DXGetImageInfoFromResource(NULL,fileName,&image_inf);\r
+ RECT dest_rec={x,y,x+image_inf.Width,\r
+ y+image_inf.Height};\r
+/* if (D3DXLoadSurfaceFromFile(\r
+ d3dsurface,\r
+ NULL,\r
+ &dest_rec,\r
+ fileName,\r
+ NULL,\r
+ D3DX_FILTER_NONE,\r
+ 0,\r
+ &image_inf)!=D3D_OK) {\r
+ Log::getInstance()->log("Surface", Log::DEBUG, "Could not open jpeg!");\r
+\r
+ }*/\r
+ if (D3DXLoadSurfaceFromResource(\r
+ d3dsurface,\r
+ NULL,\r
+ &dest_rec,\r
+ NULL,\r
+ fileName,\r
+ NULL,\r
+ D3DX_FILTER_NONE,\r
+ 0,\r
+ &image_inf)!=D3D_OK) {\r
+ Log::getInstance()->log("Surface", Log::DEBUG, "Could not open jpeg!");\r
+\r
+ }\r
+ osd->EndPainting();\r
+ *width=image_inf.Width;\r
+ *height=image_inf.Height;\r
+\r
}\r
\r