Subversion Repositories AndroidProjects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
244 chris 1
#ifndef __D3DTESTER_H__
2
#define __D3DTESTER_H__
3
#include <d3d.h>
4
#include <exception>
5
#include <string>
6
 
7
namespace Sexy
8
{
9
 
10
///////////////////////////////////////////////////////////////////////////////
11
///////////////////////////////////////////////////////////////////////////////
12
class D3DTestImage
13
{
14
protected:
15
        DWORD *mBits;
16
        int mWidth;
17
        int mHeight;
18
 
19
        void FreeImage();
20
 
21
public:
22
        D3DTestImage();
23
        D3DTestImage(int theWidth, int theHeight);
24
        virtual ~D3DTestImage();
25
 
26
        void Create(int theWidth, int theHeight);
27
 
28
        const D3DTestImage& operator=(const D3DTestImage &theImage);
29
 
30
        void MakeVerticalBands();
31
        void FillRect(int x, int y, int theWidth, int theHeight, DWORD theColor);
32
        void CopyToTexture8888(LPDIRECTDRAWSURFACE7 theTexture, int offx, int offy, int texWidth, int texHeight);
33
        void CopyToTexture4444(LPDIRECTDRAWSURFACE7 theTexture, int offx, int offy, int texWidth, int texHeight);
34
        void DrawPieceToDevice(LPDIRECT3DDEVICE7 theDevice, LPDIRECTDRAWSURFACE7 theTexture, float x, float y, int offx, int offy, int texWidth, int texHeight, DWORD theColor);
35
        void DrawToDevice(LPDIRECT3DDEVICE7 theDevice, LPDIRECTDRAWSURFACE7 theTexture, int x, int y, DWORD theColor = 0xffffffff);
36
        bool CompareEqual(const D3DTestImage &theImage) const;
37
 
38
        DWORD* GetBits() { return mBits; }
39
        const DWORD* GetBits() const { return mBits; }
40
 
41
        int GetWidth() const { return mWidth; }
42
        int GetHeight() const { return mHeight; }
43
 
44
        enum { COLOR_TOLERANCE = 16*16*3 };
45
        static int ColorDistance(DWORD c1, DWORD c2);
46
        bool IsUniformColor(DWORD theColor, int &theNumMistakes, int testWidth, int testHeight) const;
47
        int CheckUniformBands(int testWidth, int testHeight, int xoff = 0, int yoff = 0);
48
};
49
 
50
///////////////////////////////////////////////////////////////////////////////
51
///////////////////////////////////////////////////////////////////////////////
52
class D3DTester
53
{
54
protected:
55
        LPDIRECTDRAW7                   mDD7;
56
        LPDIRECTDRAWSURFACE7    mPrimarySurface;
57
        LPDIRECTDRAWSURFACE7    mTextureSurface;
58
        LPDIRECTDRAWSURFACE7    mTextureSurface2;
59
        LPDIRECT3D7                             mD3D7;
60
        LPDIRECT3DDEVICE7               mD3DDevice7;
61
        HKEY                                    mRegKey;
62
        GUID                                    mDisplayGUID;
63
        std::string                             mDisplayDriver;
64
        std::string                             mDisplayDescription;
65
 
66
        enum { TEST_VERSION = 2 };
67
 
68
        D3DTestImage mTestImage;
69
 
70
        struct TestException : public std::exception
71
        {
72
                std::string mMsg;
73
                TestException(const std::string &theMsg) : mMsg(theMsg) { }
74
        };
75
 
76
        static HRESULT CALLBACK PixelFormatsCallback(LPDDPIXELFORMAT theFormat, LPVOID lpContext);
77
 
78
        void CopyPrimaryToTestImage();
79
        bool TestAlphaBlend();
80
        bool TestAdditiveBlend();
81
        bool TestAlphaAddBlend();
82
        bool TestAlphaModulate();
83
        bool TestClipProblem();
84
 
85
        std::string mFailureReason;
86
        std::string mWarning;
87
 
88
        DWORD mMinVidMemory;
89
        DWORD mRecommendedVidMemory;
90
        bool mCheckRegistry;
91
        bool mShouldWriteToRegistry;
92
        bool mResultsChanged;
93
        int mDriverYear;
94
 
95
        bool Fail(const std::string &theStr);
96
        bool Warn(const std::string &theStr);
97
 
98
        bool Init(HWND theHWND, LPDIRECTDRAW7 theDDraw);
99
        bool FileContains(FILE* theFile, const char* theString);
100
        bool IsSupportedCard(const char *theDisplayDesc);
101
        void Cleanup();
102
        bool DoTest();
103
 
104
        bool CheckRegistry();
105
        void WriteToRegistry();
106
 
107
public:
108
        D3DTester();
109
        virtual ~D3DTester();
110
 
111
        static void CheckDXError(HRESULT theResult, const char *theMsg = "");
112
 
113
        bool HadWarning() { return !mWarning.empty(); }
114
        bool HadError() { return !mFailureReason.empty(); }
115
        bool Is3DSupported() { return !HadError(); }
116
        bool Is3DRecommended() { return !HadError() && !HadWarning(); }
117
        std::string GetWarning() { return mWarning; }
118
        std::string GetError() { return mFailureReason; }
119
        bool ResultsChanged() { return mResultsChanged; }
120
 
121
        void SetVidMemoryConstraints(DWORD theMin, DWORD theRecommended);
122
 
123
        void TestD3D(HWND theHWND, LPDIRECTDRAW7 theDDraw);
124
};
125
 
126
} // namespace Sexy
127
 
128
 
129
#endif