|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #ifdef Q_OS_WINCE_WM |
|
43 |
|
44 #include <Ddraw.h> |
|
45 #include <QDebug> |
|
46 |
|
47 static LPDIRECTDRAW g_pDD = NULL; // DirectDraw object |
|
48 static LPDIRECTDRAWSURFACE g_pDDSSurface = NULL; // DirectDraw primary surface |
|
49 |
|
50 static DDSCAPS ddsCaps; |
|
51 static DDSURFACEDESC ddsSurfaceDesc; |
|
52 static void *buffer = NULL; |
|
53 |
|
54 static int width = 0; |
|
55 static int height = 0; |
|
56 static int pitch = 0; |
|
57 static int bitCount = 0; |
|
58 static int windowId = 0; |
|
59 |
|
60 static bool initialized = false; |
|
61 static bool locked = false; |
|
62 |
|
63 void q_lock() |
|
64 { |
|
65 if (locked) { |
|
66 qWarning("Direct Painter already locked (QDirectPainter::lock())"); |
|
67 return; |
|
68 } |
|
69 locked = true; |
|
70 |
|
71 |
|
72 memset(&ddsSurfaceDesc, 0, sizeof(ddsSurfaceDesc)); |
|
73 ddsSurfaceDesc.dwSize = sizeof(ddsSurfaceDesc); |
|
74 |
|
75 HRESULT h = g_pDDSSurface->Lock(0, &ddsSurfaceDesc, DDLOCK_WRITEONLY, 0); |
|
76 if (h != DD_OK) |
|
77 qDebug() << "GetSurfaceDesc failed!"; |
|
78 |
|
79 width = ddsSurfaceDesc.dwWidth; |
|
80 height = ddsSurfaceDesc.dwHeight; |
|
81 bitCount = ddsSurfaceDesc.ddpfPixelFormat.dwRGBBitCount; |
|
82 pitch = ddsSurfaceDesc.lPitch; |
|
83 buffer = ddsSurfaceDesc.lpSurface; |
|
84 } |
|
85 |
|
86 void q_unlock() |
|
87 { |
|
88 if( !locked) { |
|
89 qWarning("Direct Painter not locked (QDirectPainter::unlock()"); |
|
90 return; |
|
91 } |
|
92 g_pDDSSurface->Unlock(0); |
|
93 locked = false; |
|
94 } |
|
95 |
|
96 void q_initDD() |
|
97 { |
|
98 if (initialized) |
|
99 return; |
|
100 |
|
101 DirectDrawCreate(NULL, &g_pDD, NULL); |
|
102 |
|
103 HRESULT h; |
|
104 h = g_pDD->SetCooperativeLevel(0, DDSCL_NORMAL); |
|
105 |
|
106 if (h != DD_OK) |
|
107 qDebug() << "cooperation level failed"; |
|
108 |
|
109 h = g_pDD->TestCooperativeLevel(); |
|
110 if (h != DD_OK) |
|
111 qDebug() << "cooperation level failed test"; |
|
112 |
|
113 DDSURFACEDESC ddsd; |
|
114 memset(&ddsd, 0, sizeof(ddsd)); |
|
115 ddsd.dwSize = sizeof(ddsd); |
|
116 |
|
117 ddsd.dwFlags = DDSD_CAPS; |
|
118 |
|
119 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; |
|
120 |
|
121 h = g_pDD->CreateSurface(&ddsd, &g_pDDSSurface, NULL); |
|
122 |
|
123 if (h != DD_OK) |
|
124 qDebug() << "CreateSurface failed!"; |
|
125 |
|
126 if (g_pDDSSurface->GetCaps(&ddsCaps) != DD_OK) |
|
127 qDebug() << "GetCaps failed"; |
|
128 |
|
129 q_lock(); |
|
130 q_unlock(); |
|
131 initialized = true; |
|
132 } |
|
133 |
|
134 uchar* q_frameBuffer() |
|
135 { |
|
136 return (uchar*) buffer; |
|
137 } |
|
138 |
|
139 int q_screenDepth() |
|
140 { |
|
141 return bitCount; |
|
142 } |
|
143 |
|
144 int q_screenWidth() |
|
145 { |
|
146 return width; |
|
147 } |
|
148 |
|
149 int q_screenHeight() |
|
150 { |
|
151 return height; |
|
152 } |
|
153 |
|
154 int q_linestep() |
|
155 { |
|
156 return pitch; |
|
157 } |
|
158 |
|
159 #endif //Q_OS_WINCE_WM |
|
160 |
|
161 |