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
|
#include "VkvgTest.hpp"
VkvgSurface imgSurf;
void recurse_draw(VkvgContext ctx, int depth) {
depth++;
vkvg_save(ctx);
vkvg_translate(ctx, 5, 5);
vkvg_rectangle(ctx, (float)depth, (float)depth, 200, 200);
vkvg_set_source_rgb(ctx, 0, 1, 0);
vkvg_stroke(ctx);
if (depth < 20)
recurse_draw(ctx, depth);
vkvg_restore(ctx);
}
void recurse_draw_clipped(VkvgContext ctx, int depth, int maxDepth) {
static float gap = 10.f;
depth++;
float depthRatio = (float)depth / maxDepth;
vkvg_rectangle(ctx, gap * depth, gap * depth, 512.f - gap * 2.f * depth, 512.f - gap * 2.f * depth);
vkvg_clip(ctx);
vkvg_set_source_rgb(ctx, depthRatio, depthRatio, 1.f);
vkvg_paint(ctx);
vkvg_arc(ctx, 256, 256, 256.f - gap * depth, 0, 2.f*M_PI);
vkvg_clip(ctx);
vkvg_set_source_surface(ctx, imgSurf, 0, 0);
vkvg_paint(ctx);
vkvg_save(ctx);
if (depth < maxDepth)
recurse_draw_clipped(ctx, depth, maxDepth);
float a = M_PIF * 0.5f * depthRatio;
float x = cos(a) * 256;
float y = sin(a) * 256;
vkvg_set_line_width(ctx, 2.f);
vkvg_move_to(ctx, 256.f - x, 256.f - y);
vkvg_line_to(ctx, 256.f + x, 256.f + y);
vkvg_set_source_rgba(ctx, 0.f, 1.f, 0.f, 0.6f);
vkvg_stroke(ctx);
vkvg_restore(ctx);
depth--;
}
TEST(save_restrore) {
VkvgContext ctx = vkvg_create(test->surf);
recurse_draw(ctx, 0);
vkvg_destroy(ctx);
}
TEST(save_restrore_clipped3) {
VkvgContext ctx = vkvg_create(test->surf);
imgSurf = vkvg_surface_create_from_image(test->device, GET_PATH("img512.png"));
recurse_draw_clipped(ctx, 0, 3);
vkvg_surface_destroy(imgSurf);
vkvg_destroy(ctx);
}
TEST(save_restrore_clipped5) {
VkvgContext ctx = vkvg_create(test->surf);
imgSurf = vkvg_surface_create_from_image(test->device, GET_PATH("img512.png"));
recurse_draw_clipped(ctx, 0, 5);
vkvg_surface_destroy(imgSurf);
vkvg_destroy(ctx);
}
TEST(save_restrore_clipped20) {
VkvgContext ctx = vkvg_create(test->surf);
imgSurf = vkvg_surface_create_from_image(test->device, GET_PATH("img512.png"));
recurse_draw_clipped(ctx, 0, 20);
vkvg_surface_destroy(imgSurf);
vkvg_destroy(ctx);
}
|