svvitch
digital signage player
D:/vs_workspace/switch_sf/src/svvitch/Renderer.h
Go to the documentation of this file.
00001 #pragma once
00002 //=============================================================
00003 // Renderer.h
00004 // レンダラークラスの定義
00005 //=============================================================
00006 
00007 #include <d3d9.h>
00008 #include <d3dx9.h>
00009 #include <string>
00010 #include <gdiplus.h>
00011 #include <vector>
00012 #include <queue>
00013 #include <Poco/HashMap.h>
00014 #include <Poco/Logger.h>
00015 #include <Poco/Mutex.h>
00016 
00017 #include "switch.h"
00018 #include "Common.h"
00019 #include "Configuration.h"
00020 #include "FPSCounter.h"
00021 #include <vfw.h>
00022 #include <dsound.h>
00023 #pragma comment(lib, "dsound.lib")
00024 #include <dxva2api.h>
00025 #pragma comment(lib, "dxva2.lib")
00026 
00027 
00028 using std::string;
00029 using std::wstring;
00030 using std::vector;
00031 using std::queue;
00032 
00033 
00034 //=============================================================
00035 // 依存するクラス
00036 //=============================================================
00037 class Scene;
00038 
00042 struct VERTEX {
00043     float x, y, z;
00044     float rhw;
00045     D3DCOLOR color;
00046     float u, v;
00047 };
00048 
00049 #define VERTEX_FVF      (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1)
00050 #define VERTEX_SIZE     (sizeof(VERTEX))
00051 #define VERTEX_COUNT    (256)
00052 
00056 struct KeyData {
00057     int keycode;
00058     bool shift;
00059     bool ctrl;
00060 //  KeyData(int keycode_, bool shift_, bool ctrl_): keycode(keycode_), shift(shift_),ctrl(ctrl_) {}
00061 };
00062 typedef KeyData* KeyDataPtr;
00063 
00064 
00069 class Renderer
00070 {
00071 private:
00072     Poco::Logger& _log;
00073     Poco::FastMutex _lock; //mutable 修飾子外した
00074     Poco::FastMutex _sceneLock;
00075     Poco::FastMutex _drawLock;
00076     Poco::FastMutex _deviceLock;
00077 
00078     HWND _hwnd;
00079     bool _postedQuit;
00080     int _exitCode;
00081 
00082     UINT _displayAdpters;
00083     UINT _maxTextureW;
00084     UINT _maxTextureH;
00085 
00086     ULONG_PTR _gdiToken;
00087     Gdiplus::GdiplusStartupInput _gdiSI;
00088 
00089     LPDIRECT3D9 _d3d;
00090     LPDIRECT3DDEVICE9 _device;
00091     D3DPRESENT_PARAMETERS* _presentParams;
00092 
00093     LPDIRECTSOUND _sound;
00094 
00095     UINT _deviceResetToken;
00096     IDirect3DDeviceManager9* _devManager;
00097 
00098     int _mem;
00099     UINT _textureMem;
00100     UINT _availableTextureMem;
00101 
00102     DWORD _current;
00103     LPDIRECT3DSURFACE9 _backBuffer;
00104     LPDIRECT3DTEXTURE9 _captureTexture;
00105 
00106     FPSCounter _fpsCounter;
00107 
00108     Gdiplus::PrivateFontCollection* _fc;
00109 //  Gdiplus::FontFamily* _multiByteFont;
00110     LPDIRECT3DTEXTURE9 _fontTexture;
00111 
00112     Poco::HashMap<string, LPDIRECT3DTEXTURE9> _cachedTextures;
00113 
00114     vector<string> _addresses;
00115 
00116     vector<Scene*> _scenes;
00117     Poco::HashMap<string, Scene*> _sceneMap;
00118 
00119 
00120     HDC _hdc;
00121     HFONT _hfontOLD;
00122     HFONT _hfont;
00123 
00124     bool _keyUpdated;
00125     int _keycode;
00126     bool _shift;
00127     bool _ctrl;
00128 
00129     vector<string> _addDrives;
00130     vector<string> _removeDrives;
00131     queue<string> _readyDrives;
00132     DWORD _lastDeviceChanged;
00133 
00134     std::map<string, string> _status;
00135 
00136 
00140     void drawText(const Gdiplus::FontFamily* ff, const int fontSize, const DWORD c1, const DWORD c2, const int w1, const DWORD c3, const int w2, const DWORD c4, const string& text, Gdiplus::Bitmap* bitmap, Gdiplus::Rect& rect) const;
00141 
00142 
00146     void createFontTexture(const Gdiplus::FontFamily* fontFamily, const int fontSize);
00147 
00149     //
00150     // この関数は以下のURLよりコピー&改変
00151     // http://support.microsoft.com/kb/163503/ja
00152     //
00153     const string firstDriveFromMask(ULONG unitmask);
00154 
00155     // ボリュームをオープンしハンドルを取得します
00156     HANDLE openVolume(const string& driveLetter);
00157 
00158     // ボリュームハンドルを解放します
00159     BOOL closeVolume(HANDLE volume);
00160 
00161     // ボリュームをロックします
00162     BOOL lockVolume(HANDLE volume);
00163 
00164     // マウント解除
00165     BOOL dismountVolume(HANDLE volume);
00166 
00167     // メディアの強制排出設定
00168     BOOL preventRemovalOfVolume(HANDLE volume, BOOL preventRemoval);
00169 
00170     // メディアの排出
00171     BOOL autoEjectVolume(HANDLE volume);
00172 
00173 
00174 public:
00175     Renderer();
00176 
00177     ‾Renderer();
00178 
00179 
00183     HRESULT initialize(HINSTANCE hInstance, HWND hWnd);
00184 
00186     const HWND getWindowHandle() const;
00187 
00188     bool peekMessage();
00189 
00190     int getExitCode();
00191 
00195     bool deliveryMessage(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
00196 
00200     const LPDIRECT3DDEVICE9 get3DDevice() const;
00201 
00205     const LPDIRECTSOUND getSoundDevice() const;
00206 
00208     const UINT getTextureMem() const;
00209 
00211     const UINT getAvailableTextureMem() const;
00212 
00216 //  const LPDIRECTINPUTDEVICE8 getKeyboardDevice() const;
00217 
00218     void notifyKeyDown(const int keycode, const bool shift, const bool ctrl);
00219 
00220     void notifyKeyUp(const int keycode, const bool shift, const bool ctrl);
00221 
00222 
00226 //  const LPDIRECTINPUTDEVICE8 getMouseDevice() const;
00227 
00228     const int getSceneCount();
00229 
00230     void insertScene(const int i, const string name, Scene* scene);
00231 
00232     void addScene(const string name, Scene* scene);
00233 
00234     Scene* getScene(const string& name);
00235 
00236     void removeScene(const string& name);
00237 
00238     bool tryDrawLock();
00239     void drawUnlock();
00240 
00244     void renderScene(const bool visibled, const LONGLONG current);
00245 
00246     const UINT getDisplayAdapters() const;
00247 
00248     const UINT getMaxTextureW() const;
00249 
00250     const UINT getMaxTextureH() const;
00251 
00255     const LPDIRECT3DTEXTURE9 createTexture(const int w, const int h, const D3DFORMAT format = D3DFMT_X8R8G8B8) const;
00256 
00260     const LPDIRECT3DTEXTURE9 createTexture(const string file) const;
00261 
00265     const LPDIRECT3DTEXTURE9 createRenderTarget(const int w, const int h, const D3DFORMAT format = D3DFMT_X8R8G8B8) const;
00266 
00267     const LPDIRECT3DSURFACE9 createLockableSurface(const int w, const int h, const D3DFORMAT format = D3DFMT_X8R8G8B8) const;
00268 
00269     const bool getRenderTargetData(LPDIRECT3DTEXTURE9 texture, LPDIRECT3DSURFACE9 surface) const;
00270 
00271     const bool updateRenderTargetData(LPDIRECT3DTEXTURE9 texture, LPDIRECT3DSURFACE9 surface) const;
00272 
00273     const bool colorFill(const LPDIRECT3DTEXTURE9 texture, const DWORD col) const;
00274 
00278     const LPDIRECT3DTEXTURE9 getCaptureTexture() const;
00279 
00280     // 線を描画
00281     void drawLine(const int x1, const int y1, const DWORD c1, const int x2, const int y2, const DWORD c2);
00282 
00286     void drawTexture(const int x, const int y, const LPDIRECT3DTEXTURE9 texture, const int flipMode, const D3DCOLOR c1 = 0xffffffff, const D3DCOLOR c2 = 0xffffffff, const D3DCOLOR c3 = 0xffffffff, const D3DCOLOR c4 = 0xffffffff) const;
00287 
00291     void drawTexture(const int x, const int y, const int w, const int h, const LPDIRECT3DTEXTURE9 texture, const int flipMode, const D3DCOLOR c1 = 0xffffffff, const D3DCOLOR c2 = 0xffffffff, const D3DCOLOR c3 = 0xffffffff, const D3DCOLOR c4 = 0xffffffff) const;
00292 
00296     void drawTextureWithAngle(const int x, const int y, const int w, const int h, const int angle, const int cx, const int cy, const LPDIRECT3DTEXTURE9 texture, const int flipMode, const D3DCOLOR c1 = 0xffffffff, const D3DCOLOR c2 = 0xffffffff, const D3DCOLOR c3 = 0xffffffff, const D3DCOLOR c4 = 0xffffffff) const;
00297 
00301     void drawTexture(const float dx, const float dy, const float dw, const float dh, const float sx, const float sy, const float sw, const float sh, const LPDIRECT3DTEXTURE9 texture, const int flipMode, const D3DCOLOR c1, const D3DCOLOR c2, const D3DCOLOR c3, const D3DCOLOR c4) const;
00302 
00306     void drawTextureWithAngle(const float dx, const float dy, const float dw, const float dh, const float sx, const float sy, const float sw, const float sh, const int angle, const int cx, const int cy, const LPDIRECT3DTEXTURE9 texture, const D3DCOLOR c1, const D3DCOLOR c2, const D3DCOLOR c3, const D3DCOLOR c4) const;
00307 
00311     LPD3DXEFFECT createEffect(const string path);
00312 
00316     void getPrivateFontFamily(string fontName, Gdiplus::FontFamily** ff);
00317 
00319     void getPrivateFontFamilies(vector<string>& fonts);
00320 
00324     bool addPrivateFontFile(string file);
00325 
00329     bool beginFont(const wstring& fontFace, const Sint32 size);
00330 
00331     void drawFont(const Sint32 x, const Sint32 y, const COLORREF fontColor, const COLORREF backColor, const string& text) const;
00332 
00333     void endFont();
00334 
00335     bool copyTexture(LPDIRECT3DTEXTURE9 src, LPDIRECT3DTEXTURE9 dst);
00336 
00337     const LPDIRECT3DTEXTURE9 createTexturedText(const wstring& fontFamily, const int fontSize, const DWORD c1, const DWORD c2, const int w1, const DWORD c3, const int w2, const DWORD c4, const string& text, int clipH = -1) const;
00338 
00339     void drawFontTextureText(const int x, const int y, const int w, const int h, const D3DCOLOR col, const string s) const;
00340 
00341     void addCachedTexture(const string& name, const LPDIRECT3DTEXTURE9 texture);
00342 
00343     void removeCachedTexture(const string& name);
00344 
00345     const LPDIRECT3DTEXTURE9 getCachedTexture(const string& name) const;
00346 
00348     void addDrive(ULONG unitmask);
00349 
00351     void removeDrive(ULONG unitmask);
00352 
00354     bool hasAddDrives();
00355 
00357     void deviceChanged();
00358 
00360     string popReadyDrive();
00361 
00362     // ボリュームのイジェクト
00363     BOOL ejectVolume(const string& driveLetter);
00364 
00366     virtual void setStatus(const string& key, const string& value);
00367 
00369     virtual const string getStatus(const string& key);
00370 
00372     virtual void removeStatus(const string& key);
00373 
00377     void finalize();
00378 };
00379 
00380 typedef Renderer* RendererPtr;
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines