summaryrefslogtreecommitdiffstats
path: root/rdtk/librdtk/test/TestRdTkNinePatch.c
blob: 2c7405f526616b07cb6ddc4ca00654c6a3350020 (plain)
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
#include <stdio.h>
#include <stdint.h>
#include <rdtk/rdtk.h>
#include <winpr/error.h>

int TestRdTkNinePatch(int argc, char* argv[])
{
	rdtkEngine* engine = NULL;
	rdtkSurface* surface = NULL;
	uint32_t scanline = 0;
	uint32_t width = 0;
	uint32_t height = 0;
	uint8_t* data = NULL;
	int ret = -1;

	WINPR_UNUSED(argc);
	WINPR_UNUSED(argv);

	if (!(engine = rdtk_engine_new()))
	{
		printf("%s: error creating rdtk engine (%" PRIu32 ")\n", __func__, GetLastError());
		goto out;
	}

	width = 1024;
	height = 768;
	scanline = width * 4;

	/* let rdtk allocate the surface buffer */
	if (!(surface = rdtk_surface_new(engine, NULL, width, height, scanline)))
	{
		printf("%s: error creating auto-allocated surface (%" PRIu32 ")\n", __func__,
		       GetLastError());
		goto out;
	}
	rdtk_surface_free(surface);
	surface = NULL;

	/* test self-allocated buffer */
	if (!(data = calloc(height, scanline)))
	{
		printf("%s: error allocating surface buffer (%" PRIu32 ")\n", __func__, GetLastError());
		goto out;
	}

	if (!(surface = rdtk_surface_new(engine, data, width, height, scanline)))
	{
		printf("%s: error creating self-allocated surface (%" PRIu32 ")\n", __func__,
		       GetLastError());
		goto out;
	}

	ret = 0;

out:
	rdtk_surface_free(surface);
	rdtk_engine_free(engine);
	free(data);

	return ret;
}