This repository has been archived by the owner on Mar 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 172
/
render_soft.c
112 lines (92 loc) · 3.51 KB
/
render_soft.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
/*
* Copyright (c) 2011 Toni Spets <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <windows.h>
#include <stdio.h>
#include "main.h"
#include "surface.h"
DWORD WINAPI render_soft_main(void)
{
PBITMAPINFO bmi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256);
bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi->bmiHeader.biWidth = ddraw->width;
bmi->bmiHeader.biHeight = -ddraw->height;
bmi->bmiHeader.biPlanes = 1;
bmi->bmiHeader.biBitCount = ddraw->bpp;
bmi->bmiHeader.biCompression = BI_RGB;
DWORD dst_top = 0;
DWORD dst_left = 0;
DWORD dst_width = ddraw->render.width;
DWORD dst_height = ddraw->render.height;
DWORD tick_start = 0;
DWORD tick_end = 0;
DWORD frame_len = 0;
if (ddraw->boxing)
{
dst_width = ddraw->width;
dst_height = ddraw->height;
/* test if we can double scale the window */
if (ddraw->width * 2 <= ddraw->render.width && ddraw->height * 2 <= ddraw->render.height)
{
dst_width *= 2;
dst_height *= 2;
}
dst_top = ddraw->render.height / 2 - dst_height / 2;
dst_left = ddraw->render.width / 2 - dst_width / 2;
}
if(ddraw->render.maxfps < 0)
{
ddraw->render.maxfps = ddraw->mode.dmDisplayFrequency;
}
if(ddraw->render.maxfps > 0)
{
frame_len = 1000.0f / ddraw->render.maxfps;
}
while (ddraw->render.run && WaitForSingleObject(ddraw->render.sem, INFINITE) != WAIT_FAILED)
{
if(ddraw->render.maxfps > 0)
{
tick_start = GetTickCount();
}
EnterCriticalSection(&ddraw->cs);
if (ddraw->primary && (ddraw->primary->palette || ddraw->bpp == 16))
{
if (ddraw->primary->palette && ddraw->primary->palette->data_rgb == NULL)
{
ddraw->primary->palette->data_rgb = &bmi->bmiColors[0];
}
if (ddraw->render.width != ddraw->width || ddraw->render.height != ddraw->height)
{
StretchDIBits(ddraw->render.hDC, dst_left, dst_top, dst_width, dst_height, 0, 0, ddraw->width, ddraw->height, ddraw->primary->surface, bmi, DIB_RGB_COLORS, SRCCOPY);
}
else
{
SetDIBitsToDevice(ddraw->render.hDC, 0, 0, ddraw->width, ddraw->height, 0, 0, 0, ddraw->height, ddraw->primary->surface, bmi, DIB_RGB_COLORS);
}
}
LeaveCriticalSection(&ddraw->cs);
if(ddraw->render.maxfps > 0)
{
tick_end = GetTickCount();
if(tick_end - tick_start < frame_len)
{
Sleep( frame_len - (tick_end - tick_start) );
}
}
SetEvent(ddraw->render.ev);
}
HeapFree(GetProcessHeap(), 0, bmi);
return TRUE;
}