Windows port, JPEGs
authorChris Tallon <chris@vomp.tv>
Thu, 25 May 2006 01:01:09 +0000 (01:01 +0000)
committerChris Tallon <chris@vomp.tv>
Thu, 25 May 2006 01:01:09 +0000 (01:01 +0000)
surfacewin.cc
vompwin.rc

index d17195ce4dbbd0702aed595cbd608a46bffe1c66..8cc3fbb29f593f057bbf1d3bdeb8366e24102c96 100644 (file)
-/*
-    Copyright 2004-2005 Chris Tallon
-    Portions copyright 2004 Jon Gettler
-
-    This file is part of VOMP.
-
-    VOMP is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    VOMP is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with VOMP; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-#include "surfacewin.h"
-#include "osdwin.h"
-#include <d3dx9tex.h>
-
-SurfaceWin::SurfaceWin(int id)
-: Surface(id)
-{
-  d3dtexture=NULL;
-  d3dsurface=NULL;
-  sheight=swidth=0;
-  event = CreateEvent(NULL,/*FALSE*/TRUE,FALSE,NULL);
-}
-
-SurfaceWin::~SurfaceWin()
-{
-  if (d3dsurface) d3dsurface->Release();
-  if (d3dtexture) d3dtexture->Release();
-  CloseHandle(event);
-}
-
-int SurfaceWin::create(UINT width, UINT height)
-{
-  LPDIRECT3DDEVICE9 d3ddev=((OsdWin*)(Osd::getInstance()))->getD3dDev();
-  while (true) {
-    if (screen==this) {
-      if (d3ddev->CreateTexture(1024,1024,0,0,D3DFMT_A8R8G8B8,
-        // Does every adapter with alpha blending support this?
-        D3DPOOL_DEFAULT,&d3dtexture ,NULL)!=D3D_OK) {
-          MILLISLEEP(50);//wait maybe next time it will work
-          continue;
-      }
-      if (d3dtexture->GetSurfaceLevel(0,&d3dsurface)!=D3D_OK) {
-        d3dtexture->Release();
-        d3dtexture=NULL;
-        MILLISLEEP(50);
-        continue;
-      }
-    } else {
-      HRESULT hres;
-      if (hres=d3ddev->CreateOffscreenPlainSurface(width,height,D3DFMT_A8R8G8B8,
-        D3DPOOL_SYSTEMMEM,&d3dsurface,NULL)!=D3D_OK) {
-          MILLISLEEP(50);//wait maybe next time it will work
-          continue;
-      }
-
-    }
-    sheight=height;
-    swidth=width;
-    /* If someone does high performance Animations on the OSD, we have to change the types
-     of surface in order to address these performance issues, if we have only very few updates
-     per second this would be fast enough !*/
-    break;
-  }
-  SetEvent(event);
-  return 1;
-}
-
-void SurfaceWin::display()
-{
-}
-
-int SurfaceWin::fillblt(int x, int y, int width, int height, unsigned int c)
-{
-  WaitForSingleObject(event,INFINITE); //since this might be called before surface
-  //allocation we will wait in this case, hopefully without deadlocks
-  OsdWin* osd=((OsdWin*)(Osd::getInstance()));
-
-  if (!d3dsurface) {
-    return 0; //why does this happen
-  }
-
-  LPDIRECT3DDEVICE9 d3ddev=osd->getD3dDev();
-
-  if (screen==this) {
-    //This should not happen!
-    return 0;
-
-  } else {
-    osd->BeginPainting();
-    D3DLOCKED_RECT lockrect;
-    int cx,cy,cwidth,cheight;
-    cx=min(max(x,0),swidth);
-    cy=min(max(y,0),sheight);
-    cwidth=min(width,swidth-x);
-    cheight=min(height,sheight-y);
-    RECT rect={cx,cy,cwidth,cheight};
-
-    if (d3dsurface->LockRect(&lockrect,&rect,D3DLOCK_DISCARD)!=D3D_OK) {
-      return 0;
-    }
-    unsigned int line;
-    unsigned int column;
-    for (line=0;line<cheight;line++) {
-      unsigned int*row=((unsigned int*)(((char*)lockrect.pBits)+lockrect.Pitch*line));
-      for (column=0;column<cwidth;column++) {
-        row[column]=c;
-      }
-    }
-
-    if (d3dsurface->UnlockRect()!=D3D_OK) {
-      osd->EndPainting();
-      return 0;
-    }
-    osd->EndPainting();
-  }
-
-  return 0;
-}
-
-void SurfaceWin::drawPixel(int x, int y, unsigned int c)
-{
-  //FixMe: locking for every single Pixel will be painfully slow
-  WaitForSingleObject(event,INFINITE); //since this might be called before surface
-  //allocation we will wait in this case, hopefully without deadlocks
-  if (!d3dsurface) {
-    return; //why does this happen
-  }
-  OsdWin* osd=((OsdWin*)(Osd::getInstance()));
-  LPDIRECT3DDEVICE9 d3ddev=osd->getD3dDev();
-  if (x>swidth || y>sheight) return; //do not draw outside the surface
-  if (screen==this) {
-    //This should not happen!
-    return ;
-
-  } else {
-    osd->BeginPainting();
-    D3DLOCKED_RECT lockrect;
-    RECT rect={x,y,x+1,y+1};
-    if (d3dsurface->LockRect(&lockrect,&rect,D3DLOCK_DISCARD)!=D3D_OK) {
-      osd->EndPainting();
-      return ;
-    }
-    unsigned int*row=(unsigned int*)(((char*)lockrect.pBits));
-    row[0]=c;
-    if (d3dsurface->UnlockRect()!=D3D_OK) {
-      osd->EndPainting();
-      return ;
-    }
-    osd->EndPainting();
-  }
-
-}
-
-void SurfaceWin::drawHorzLine(int x1, int x2, int y, unsigned int c)
-{
-   fillblt(x1, y, x2-x1, 1, c);
-}
-
-void SurfaceWin::drawVertLine(int x, int y1, int y2, unsigned int c)
-{
-  fillblt(x, y1, 1, y2-y1, c);
-}
-
-int SurfaceWin::updateToScreen(int sx, int sy, int w, int h, int dx, int dy) // FIXME new, replace others with this FIXME
-{
-  WaitForSingleObject(event,INFINITE); //since this might be called before surface
-  //allocation we will wait in this case, hopefully without deadlocks
-  if (!d3dsurface) {
-    return 0; //why does this happen
-  }
-  OsdWin* osd=((OsdWin*)(Osd::getInstance()));
-  LPDIRECT3DDEVICE9 d3ddev=osd->getD3dDev();
-    LPDIRECT3DSURFACE9 screensurface=((SurfaceWin*)screen)->getD3dsurface();
-  if (!screensurface) return 0;
-  RECT sourcerect={sx,sy,sx+w,sy+h};
-  POINT destpoint={dx,dy};
-  osd->BeginPainting();
-  if (d3ddev->UpdateSurface(d3dsurface,&sourcerect,screensurface,&destpoint)!=D3D_OK) {
-    Log::getInstance()->log("Surface", Log::DEBUG, "Could not update to Screen!");
-    osd->EndPainting();
-    return 0;
-  }
-  osd->EndPainting();
-  return 0;
-}
-
-int SurfaceWin::blt(int fd, unsigned long shandle, int sx, int sy, int width, int height, unsigned long dhandle, int dx, int dy)
-{
-  //I don't see code using this function, so I skip it, since it is a MVP specific interface
-  return 0;
-}
-
-void SurfaceWin::screenShot(char* fileName)
-{
-  //Isn't this for debugging only, so I won't implement it yet
-}
-
-void SurfaceWin::readPixel(int x, int y, unsigned char* r, unsigned char* g, unsigned char* b)
-{
-  //Isn't this for debugging only, so I won't implement it yet
-}
-void SurfaceWin::ReleaseSurface()
-{
-  ResetEvent(event);
-  LPDIRECT3DSURFACE9 temp_surf=d3dsurface;
-  LPDIRECT3DTEXTURE9 temp_text=d3dtexture;
-  d3dsurface=NULL;
-  d3dtexture=NULL;
-  sheight=swidth=0;
-  if (temp_surf) temp_surf->Release();
-  if (temp_text) temp_text->Release();
-}
-
-void SurfaceWin::drawJpeg(char *fileName,DWORD x, DWORD y,DWORD *width, DWORD *height){
-  WaitForSingleObject(event,INFINITE); //since this might be called before surface
-  //allocation we will wait in this case, hopefully without deadlocks
-  if (!d3dsurface) {
-    return ; //why does this happen
-  }
-  OsdWin* osd=((OsdWin*)(Osd::getInstance()));
-
-
-  D3DXIMAGE_INFO image_inf;
-  osd->BeginPainting();
-  D3DXGetImageInfoFromFile(fileName,&image_inf);
-  RECT dest_rec={x,y,x+image_inf.Width,
-    y+image_inf.Height};
-  if (D3DXLoadSurfaceFromFile(
-    d3dsurface,
-    NULL,
-    &dest_rec,
-    fileName,
-    NULL,
-    D3DX_FILTER_NONE,
-    0,
-    &image_inf)!=D3D_OK) {
-      Log::getInstance()->log("Surface", Log::DEBUG, "Could not open jpeg!");
-
-  }
-  osd->EndPainting();
-  *width=image_inf.Width;
-  *height=image_inf.Height;
-
-}
+/*\r
+    Copyright 2004-2005 Chris Tallon\r
+    Portions copyright 2004 Jon Gettler\r
+\r
+    This file is part of VOMP.\r
+\r
+    VOMP is free software; you can redistribute it and/or modify\r
+    it under the terms of the GNU General Public License as published by\r
+    the Free Software Foundation; either version 2 of the License, or\r
+    (at your option) any later version.\r
+\r
+    VOMP is distributed in the hope that it will be useful,\r
+    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+    GNU General Public License for more details.\r
+\r
+    You should have received a copy of the GNU General Public License\r
+    along with VOMP; if not, write to the Free Software\r
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+*/\r
+\r
+#include "surfacewin.h"\r
+#include "osdwin.h"\r
+#include <d3dx9tex.h>\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
+}\r
+\r
+SurfaceWin::~SurfaceWin()\r
+{\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
+}\r
+\r
+void SurfaceWin::display()\r
+{\r
+}\r
+\r
+int SurfaceWin::fillblt(int x, int y, int width, int height, unsigned int c)\r
+{\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
+  if (!d3dsurface) {\r
+               return 0; //why does this happen\r
+  }\r
+\r
+  LPDIRECT3DDEVICE9 d3ddev=osd->getD3dDev();\r
+  \r
+  if (screen==this) {\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
+  }\r
+\r
+  return 0;\r
+}\r
+\r
+void SurfaceWin::drawPixel(int x, int y, unsigned int c)\r
+{\r
+  //FixMe: locking for every single Pixel will be painfully slow\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
+  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
+\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
+  }\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
+}\r
+\r
+void SurfaceWin::drawVertLine(int x, int y1, int y2, unsigned int c)\r
+{\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
+  //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
+    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
+}\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
+  //I don't see code using this function, so I skip it, since it is a MVP specific interface\r
+  return 0;\r
+}\r
+\r
+void SurfaceWin::screenShot(char* fileName)\r
+{\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
+}\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
+}\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
+  //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
+}\r
+\r
index 7d0fbf595151498b41d7965ea2f65674795b09ac..6a58f83701cac710ced616b10e36f9445597a733 100644 (file)
@@ -40,6 +40,11 @@ BEGIN
        VK_RETURN,      VOMP_FULL_SCREEN,       VIRTKEY, ALT, NOINVERT\r
 END\r
 \r
+vdr.jpg RCDATA vdr.jpg\r
+wallpaperNTSC.jpg RCDATA wallpaperNTSC.jpg\r
+wallpaperPAL.jpg RCDATA wallpaperPAL.jpg\r
+\r
+\r
 \r
 \r
 \r