Add very primitive AlphaBlend test.
[reactos.git] / reactos / apps / utils / rosperf / alphablend.c
1 /*
2 * ReactOS RosPerf - ReactOS GUI performance test program
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #include <windows.h>
20 #include <wingdi.h>
21 #include "rosperf.h"
22
23 typedef struct _ALPHABLEND_CONTEXT {
24 HDC BitmapDc;
25 HBITMAP Bitmap;
26 } ALPHABLEND_CONTEXT, *PALPHABLEND_CONTEXT;
27
28 unsigned
29 AlphaBlendInit(void **Context, PPERF_INFO PerfInfo, unsigned Reps)
30 {
31 PALPHABLEND_CONTEXT ctx = HeapAlloc(GetProcessHeap(), 0, sizeof (ALPHABLEND_CONTEXT));
32 INT x, y;
33
34 ctx->BitmapDc = CreateCompatibleDC(PerfInfo->BackgroundDc);
35 ctx->Bitmap = CreateCompatibleBitmap(PerfInfo->BackgroundDc, PerfInfo->WndWidth, PerfInfo->WndHeight);
36 SelectObject(ctx->BitmapDc, ctx->Bitmap);
37
38 for (y = 0; y < PerfInfo->WndHeight; y++)
39 {
40 for (x = 0; x < PerfInfo->WndWidth; x++)
41 {
42 SetPixel(ctx->BitmapDc, x, y, RGB(0xff, 0x00, 0x00));
43 }
44 }
45
46 *Context = ctx;
47
48 return Reps;
49 }
50
51 void
52 AlphaBlendCleanup(void *Context, PPERF_INFO PerfInfo)
53 {
54 PALPHABLEND_CONTEXT ctx = Context;
55 DeleteDC(ctx->BitmapDc);
56 DeleteObject(ctx->Bitmap);
57 HeapFree(GetProcessHeap(), 0, ctx);
58 }
59
60
61 ULONG
62 DbgPrint(
63 IN PCH Format,
64 IN ...);
65
66 void
67 AlphaBlendProc(void *Context, PPERF_INFO PerfInfo, unsigned Reps)
68 {
69 PALPHABLEND_CONTEXT ctx = Context;
70 unsigned Rep;
71 BLENDFUNCTION BlendFunc = { AC_SRC_OVER, 0, 0, 0 };
72
73 for (Rep = 0; Rep < Reps; Rep++)
74 {
75 BlendFunc.SourceConstantAlpha = 255 * Rep / Reps;
76 #if 0
77 PatBlt(PerfInfo->BackgroundDc, 0, 0, PerfInfo->WndWidth, PerfInfo->WndHeight, PATCOPY);
78 #endif
79 if (!AlphaBlend(PerfInfo->BackgroundDc, 0, 0, PerfInfo->WndWidth, PerfInfo->WndHeight,
80 ctx->BitmapDc, 0, 0, PerfInfo->WndWidth, PerfInfo->WndHeight,
81 BlendFunc))
82 {
83 DbgPrint("AlphaBlend failed (0x%lx)\n", GetLastError());
84 }
85 }
86 }
87
88 /* EOF */