-
Notifications
You must be signed in to change notification settings - Fork 2
/
kva_wo.c
438 lines (339 loc) · 12.3 KB
/
kva_wo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
/*
WarpOverlay interface for K Video Accelerator
Copyright (C) 2007-2012 by KO Myung-Hun <komh@chollian.net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#define INCL_DOS
#define INCL_WIN
#define INCL_GPI
#include <os2.h>
#include <mmioos2.h>
#include <fourcc.h>
#include <stdlib.h>
#include <string.h>
#include "hwvideo.h"
#include "kva.h"
#include "kva_internal.h"
#include "kva_wo.h"
static HWND m_hwndKVA = NULLHANDLE;
static HMODULE m_HWVideoHandle = NULLHANDLE;
static HWVIDEOCAPS m_hwvc = { 0 };
static HWVIDEOSETUP m_hwvs = { 0 };
static PFNWP m_pfnwpOld = NULL;
static ULONG m_aulAttr[ KVAA_LAST ] = { -1, -1, -1, -1 };
// WarpOverlay! functions pointers
static DECLARE_PFN( ULONG, APIENTRY, m_pfnHWVIDEOInit, ( VOID ));
static DECLARE_PFN( ULONG, APIENTRY, m_pfnHWVIDEOCaps, ( PHWVIDEOCAPS ));
static DECLARE_PFN( ULONG, APIENTRY, m_pfnHWVIDEOSetup, ( PHWVIDEOSETUP ));
static DECLARE_PFN( ULONG, APIENTRY, m_pfnHWVIDEOBeginUpdate, ( PVOID, PULONG ));
static DECLARE_PFN( ULONG, APIENTRY, m_pfnHWVIDEOEndUpdate, ( VOID ));
static DECLARE_PFN( ULONG, APIENTRY, m_pfnHWVIDEOGetAttrib, ( ULONG, PHWATTRIBUTE ));
static DECLARE_PFN( ULONG, APIENTRY, m_pfnHWVIDEOSetAttrib, ( ULONG, PHWATTRIBUTE ));
static DECLARE_PFN( ULONG, APIENTRY, m_pfnHWVIDEOClose, ( VOID ));
static APIRET APIENTRY woDone( VOID );
static APIRET APIENTRY woLockBuffer( PPVOID ppBuffer, PULONG pulBPL );
static APIRET APIENTRY woUnlockBuffer( VOID );
static APIRET APIENTRY woSetup( PKVASETUP pkvas );
static APIRET APIENTRY woCaps( PKVACAPS pkvac );
static APIRET APIENTRY woQueryAttr( ULONG ulAttr, PULONG pulValue );
static APIRET APIENTRY woSetAttr( ULONG ulAttr, PULONG pulValue );
// Just put DLL loading into separate function
static BOOL LoadOverlay(void)
{
char szTempStr[ 255 ];
// Load WarpOverlay! API DLL
if( DosLoadModule( szTempStr, sizeof( szTempStr ), "hwvideo", &m_HWVideoHandle ))
return FALSE;
// Get all functions entry points
if( DosQueryProcAddr( m_HWVideoHandle, 0, "HWVIDEOInit", ( PFN * )&m_pfnHWVIDEOInit ))
return FALSE;
if( DosQueryProcAddr( m_HWVideoHandle, 0, "HWVIDEOCaps", ( PFN * )&m_pfnHWVIDEOCaps ))
return FALSE;
if( DosQueryProcAddr( m_HWVideoHandle, 0, "HWVIDEOSetup", ( PFN * )&m_pfnHWVIDEOSetup ))
return FALSE;
if( DosQueryProcAddr( m_HWVideoHandle, 0, "HWVIDEOBeginUpdate", ( PFN * )&m_pfnHWVIDEOBeginUpdate ))
return FALSE;
if( DosQueryProcAddr( m_HWVideoHandle, 0, "HWVIDEOEndUpdate", ( PFN * )&m_pfnHWVIDEOEndUpdate ))
return FALSE;
if( DosQueryProcAddr( m_HWVideoHandle, 0, "HWVIDEOGetAttrib", ( PFN * )&m_pfnHWVIDEOGetAttrib ))
return FALSE;
if( DosQueryProcAddr( m_HWVideoHandle, 0, "HWVIDEOSetAttrib", ( PFN * )&m_pfnHWVIDEOSetAttrib ))
return FALSE;
if( DosQueryProcAddr( m_HWVideoHandle, 0, "HWVIDEOClose", ( PFN * )&m_pfnHWVIDEOClose ))
return FALSE;
return TRUE;
}
static MRESULT EXPENTRY woNewWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
{
switch( msg )
{
case WM_ERASEBACKGROUND :
{
HPS hpsFrame = ( HPS )mp1;
PRECTL prcl = ( PRECTL )mp2;
GpiCreateLogColorTable( hpsFrame, 0, LCOLF_RGB, 0, 0, NULL );
WinFillRect( hpsFrame, prcl, m_hwvs.ulKeyColor);
return FALSE;
}
case WM_SIZE :
case WM_MOVE :
// WinMapWindowPoints() sometimes does a wrong conversion on WM_MOVE.
// For examples, minimizing and restoring a window of Qt4.
// So we need to setup on WM_PAINT as well in order to work around
// this problem.
case WM_PAINT :
{
RECTL rcl;
kvaAdjustDstRect( &m_hwvs.rctlSrcRect, &rcl );
WinMapWindowPoints( hwnd, HWND_DESKTOP, ( PPOINTL )&rcl, 2 );
if( !WinEqualRect( WinQueryAnchorBlock( hwnd ),
&rcl, &m_hwvs.rctlDstRect ))
{
m_hwvs.rctlDstRect = rcl;
m_pfnHWVIDEOSetup( &m_hwvs );
}
break; // fall through to old window proc
}
}
return m_pfnwpOld( hwnd, msg, mp1, mp2 );
}
APIRET APIENTRY kvaWoInit( HWND hwnd, ULONG ulKeyColor, PKVAAPIS pkva )
{
BOOL fWOInited = FALSE;
HWATTRIBUTE attr;
int i;
CHAR szClassName[ 80 ];
CLASSINFO ci;
ULONG rc;
m_HWVideoHandle = NULLHANDLE;
memset( &m_hwvc, 0, sizeof( HWVIDEOCAPS ));
memset( &m_hwvs, 0, sizeof( HWVIDEOSETUP ));
m_pfnwpOld = NULL;
rc = KVAE_NO_ERROR;
if( !LoadOverlay())
{
rc = KVAE_CANNOT_LOAD_WO;
goto exit_error;
}
rc = m_pfnHWVIDEOInit();
if( rc )
goto exit_error;
fWOInited = TRUE;
// Query overlay capabilities
m_hwvc.ulLength = sizeof( m_hwvc );
// First time we need to call with zero value
m_hwvc.ulNumColors = 0;
m_hwvc.fccColorType = NULL;
m_pfnHWVIDEOCaps( &m_hwvc );
// this time hwvc.ulNumColors filled with actual count of supported FOURCCs
// but need to check this
if( m_hwvc.ulNumColors )
{
m_hwvc.fccColorType = malloc( m_hwvc.ulNumColors * sizeof( FOURCC ));
m_pfnHWVIDEOCaps( &m_hwvc );
}
else
{
rc = KVAE_NO_SUPPORTED_FOURCC;
goto exit_error;
}
if( m_hwvc.fccDstColor == FOURCC_LUT8 )
{
// WO doesn't supports palettized mode.
rc = KVAE_WO_PALETTIZED_MODE;
goto exit_error;
}
attr.ulLength = sizeof( HWATTRIBUTE );
for( i = 0; i < m_hwvc.ulAttrCount; i++ )
{
m_pfnHWVIDEOGetAttrib( i, &attr );
if( !strcmp( attr.szAttrDesc, ATTRIBUTE_BRIGHTNESS ))
m_aulAttr[ KVAA_BRIGHTNESS ] = i;
else if ( !strcmp( attr.szAttrDesc, ATTRIBUTE_CONTRAST ))
m_aulAttr[ KVAA_CONTRAST ] = i;
else if( !strcmp( attr.szAttrDesc, ATTRIBUTE_SATURATION ))
m_aulAttr[ KVAA_SATURATION ] = i;
else if( !strcmp( attr.szAttrDesc, ATTRIBUTE_HUE ))
m_aulAttr[ KVAA_HUE ] = i;
}
m_hwndKVA = hwnd;
m_hwvs.ulKeyColor = ulKeyColor;
WinQueryClassName( m_hwndKVA, sizeof( szClassName ), szClassName );
WinQueryClassInfo( WinQueryAnchorBlock( m_hwndKVA ), szClassName, &ci );
if( !( ci.flClassStyle & CS_MOVENOTIFY ))
{
ci.flClassStyle |= CS_MOVENOTIFY;
WinRegisterClass( WinQueryAnchorBlock( m_hwndKVA ),
szClassName,
ci.pfnWindowProc,
ci.flClassStyle,
ci.cbWindowData );
}
m_pfnwpOld = WinSubclassWindow( m_hwndKVA, woNewWindowProc );
if( m_pfnwpOld )
{
pkva->pfnDone = woDone;
pkva->pfnLockBuffer = woLockBuffer;
pkva->pfnUnlockBuffer = woUnlockBuffer;
pkva->pfnSetup = woSetup;
pkva->pfnCaps = woCaps;
pkva->pfnQueryAttr = woQueryAttr;
pkva->pfnSetAttr = woSetAttr;
}
else
{
rc = KVAE_CANNOT_SUBCLASS;
goto exit_error;
}
return KVAE_NO_ERROR;
exit_error :
if( m_HWVideoHandle )
{
if( m_hwvc.fccColorType )
free( m_hwvc.fccColorType );
if( fWOInited )
m_pfnHWVIDEOClose();
DosFreeModule( m_HWVideoHandle );
}
return rc;
}
static APIRET APIENTRY woDone( VOID )
{
ULONG rc;
free( m_hwvc.fccColorType );
WinSubclassWindow( m_hwndKVA, m_pfnwpOld );
rc = m_pfnHWVIDEOClose();
DosFreeModule( m_HWVideoHandle );
return rc;
}
static APIRET APIENTRY woLockBuffer( PPVOID ppBuffer, PULONG pulBPL )
{
ULONG ulPhysBuffer;
*pulBPL = m_hwvs.ulSrcPitch;
return m_pfnHWVIDEOBeginUpdate( ppBuffer, &ulPhysBuffer );
}
static APIRET APIENTRY woUnlockBuffer( VOID )
{
return m_pfnHWVIDEOEndUpdate();
}
static APIRET APIENTRY woSetup( PKVASETUP pkvas )
{
m_hwvs.ulLength = sizeof( HWVIDEOSETUP );
m_hwvs.rctlSrcRect = pkvas->rclSrcRect;
m_hwvs.szlSrcSize = pkvas->szlSrcSize;
m_hwvs.fccColor = pkvas->fccSrcColor;
m_hwvs.ulSrcPitch = ( m_hwvs.szlSrcSize.cx * 2 + m_hwvc.ulScanAlign ) & ~m_hwvc.ulScanAlign;
kvaAdjustDstRect( &m_hwvs.rctlSrcRect, &m_hwvs.rctlDstRect );
WinMapWindowPoints( m_hwndKVA, HWND_DESKTOP, ( PPOINTL )&m_hwvs.rctlDstRect, 2 );
if( m_hwvs.rctlDstRect.xLeft == m_hwvs.rctlDstRect.xRight ||
m_hwvs.rctlDstRect.yTop == m_hwvs.rctlDstRect.yBottom )
return m_pfnHWVIDEOSetup( NULL );
return m_pfnHWVIDEOSetup( &m_hwvs );
}
#ifndef SHOW_CAPS
static APIRET APIENTRY woCaps( PKVACAPS pkvac )
{
int i;
switch( m_hwvc.fccDstColor )
{
case FOURCC_BGR4 :
pkvac->ulDepth = 32;
break;
case FOURCC_BGR3 :
pkvac->ulDepth = 24;
break;
case FOURCC_R565 :
case FOURCC_R555 : // AS DIVE do with SNAP
pkvac->ulDepth = 16;
break;
default : // WO doesn't support palettized mode.
return KVAE_WO_PALETTIZED_MODE;
}
pkvac->ulMode = KVAM_WO;
pkvac->cxScreen = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN );
pkvac->cyScreen = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN );
pkvac->fccScreen = m_hwvc.fccDstColor;
pkvac->ulInputFormatFlags = 0;
for( i = 0; i < m_hwvc.ulNumColors; i++ )
{
switch( m_hwvc.fccColorType[ i ])
{
case FOURCC_Y422 :
pkvac->ulInputFormatFlags |= KVAF_YUY2;
break;
case FOURCC_R565 :
pkvac->ulInputFormatFlags |= KVAF_BGR16;
pkvac->ulRMask = (( 1 << 5 ) - 1 ) << 11;
pkvac->ulGMask = (( 1 << 6 ) - 1 ) << 5;
pkvac->ulBMask = (( 1 << 5 ) - 1 ) << 0;
break;
}
}
return KVAE_NO_ERROR;
}
#else
#include <stdio.h>
static APIRET APIENTRY woCaps( PKVACAPS pkvac )
{
int i;
printf("--- WarpOverlay Caps ---\n");
printf("ulCapsFlag = %lx\n", m_hwvc.ulCapsFlags );
printf("SrcMax.cx = %ld, SrcMax.cy = %d\n", m_hwvc.szlSrcMax.cx, m_hwvc.szlSrcMax.cy );
printf("Dest Margin xLeft = %ld, yBottom = %ld, xRight = %ld, yTop = %ld\n",
m_hwvc.rctlDstMargin.xLeft, m_hwvc.rctlDstMargin.yBottom,
m_hwvc.rctlDstMargin.xRight, m_hwvc.rctlDstMargin.yTop );
printf("screen FOURCC = %.4s\n", &m_hwvc.fccDstColor );
printf("ulScanAlign = %ld\n", m_hwvc.ulScanAlign );
printf("ulNumColors = %ld\n", m_hwvc.ulNumColors );
for( i = 0; i < m_hwvc.ulNumColors; i++ )
printf("%dth FOURCC = %.4s\n", i, m_hwvc.fccColorType + i );
printf("ulAttrCount = %ld\n", m_hwvc.ulAttrCount );
return KVAE_NO_ERROR;
}
#endif
APIRET APIENTRY woQueryAttr( ULONG ulAttr, PULONG pulValue )
{
HWATTRIBUTE attr;
ULONG rc;
if( ulAttr > KVAA_HUE )
return KVAE_NO_ATTRIBUTE;
ulAttr = m_aulAttr[ ulAttr ];
if( ulAttr == ( ULONG )-1 )
return KVAE_NO_ATTRIBUTE;
attr.ulLength = sizeof( HWATTRIBUTE );
rc = m_pfnHWVIDEOGetAttrib( ulAttr, &attr );
*pulValue = attr.ulCurrentValue;
return rc;
}
APIRET APIENTRY woSetAttr( ULONG ulAttr, PULONG pulValue )
{
HWATTRIBUTE attr;
ULONG rc;
if( ulAttr > KVAA_HUE )
return KVAE_NO_ATTRIBUTE;
ulAttr = m_aulAttr[ ulAttr ];
if( ulAttr == ( ULONG )-1 )
return KVAE_NO_ATTRIBUTE;
attr.ulLength = sizeof( HWATTRIBUTE );
rc = m_pfnHWVIDEOGetAttrib( ulAttr, &attr );
if( rc )
return rc;
if( *pulValue == ( ULONG )-1 )
*pulValue = attr.ulDefaultValue;
if(( LONG )*pulValue < 0 )
*pulValue = 0;
if( *pulValue > 255 )
*pulValue = 255;
attr.ulCurrentValue = *pulValue;
return m_pfnHWVIDEOSetAttrib( ulAttr, &attr );
}