FUNCTION (buildtest TEST_FILE)
GET_FILENAME_COMPONENT(TEST_NAME ${TEST_FILE} NAME_WE)
ADD_EXECUTABLE(${TEST_NAME} ${TEST_FILE})
- TARGET_INCLUDE_DIRECTORIES(${TEST_NAME} PRIVATE
- ${Vulkan_INCLUDE_DIRS}
- ${GLFW3_INCLUDE_DIR}
- ${CMAKE_CURRENT_SOURCE_DIR}/../include
- ${CMAKE_CURRENT_SOURCE_DIR}/../src
- ${CMAKE_CURRENT_SOURCE_DIR}/common
- ${CMAKE_CURRENT_SOURCE_DIR}/../vkh/include
- ${CMAKE_CURRENT_SOURCE_DIR}/../vkh/src
- )
TARGET_LINK_LIBRARIES(${TEST_NAME}
tests_common
)
ENDFUNCTION (buildtest)
ADD_LIBRARY("tests_common" STATIC common/vkengine.c common/test.c common/rnd.c)
-TARGET_INCLUDE_DIRECTORIES(tests_common PRIVATE
- ${Vulkan_INCLUDE_DIRS}
- ${GLFW3_INCLUDE_DIR}
- "${CMAKE_CURRENT_SOURCE_DIR}/../include"
- "${CMAKE_CURRENT_SOURCE_DIR}/../src"
- "${CMAKE_CURRENT_SOURCE_DIR}/../common"
- "${CMAKE_CURRENT_SOURCE_DIR}/../vkh/include"
- "${CMAKE_CURRENT_SOURCE_DIR}/../vkh/src"
- )
+
+TARGET_INCLUDE_DIRECTORIES(tests_common
+ PUBLIC
+ ${Vulkan_INCLUDE_DIRS}
+ ${GLFW3_INCLUDE_DIR}
+ "${CMAKE_CURRENT_SOURCE_DIR}/../include"
+ "${CMAKE_CURRENT_SOURCE_DIR}/../src"
+ "${CMAKE_CURRENT_SOURCE_DIR}/common"
+ "${CMAKE_CURRENT_SOURCE_DIR}/../vkh/include"
+ "${CMAKE_CURRENT_SOURCE_DIR}/../vkh/src"
+)
TARGET_LINK_LIBRARIES(tests_common
- ${Vulkan_LIBRARIES}
- ${GLFW3_LIBRARY}
- vkvg_static
+ PUBLIC
+ ${Vulkan_LIBRARIES}
+ ${GLFW3_LIBRARY}
+ vkvg
)
file(GLOB_RECURSE DATAS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "data/*")
vkvg_paint(ctx);
vkvg_destroy(ctx);
}
+void clip_transformed_ec () {
+ VkvgContext ctx = vkvg_create(surf);
+ vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_NON_ZERO);
+ vkvg_set_source_rgb(ctx,1,0,0);
+ vkvg_paint(ctx);
+ vkvg_rotate(ctx,0.1f);
+ vkvg_set_source_rgb(ctx,0,1,0);
+ vkvg_rectangle(ctx, 100,100,300,200);
+ vkvg_clip(ctx);
+ vkvg_paint(ctx);
+ vkvg_translate (ctx,200,100);
+ vkvg_set_source_rgb(ctx,0,0,1);
+ vkvg_paint(ctx);
+
+ vkvg_destroy(ctx);
+}
void clipped_transformed_eo () {
VkvgContext ctx = vkvg_create(surf);
vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD);
vkvg_clip(ctx);
vkvg_save(ctx);
-
vkvg_set_source_rgb(ctx,1,1,0);
vkvg_paint(ctx);
-
vkvg_rectangle(ctx, 200,200,200,200);
vkvg_clip(ctx);
vkvg_restore(ctx);
-
vkvg_rectangle(ctx, 350,350,420,420);
vkvg_set_source_rgb(ctx,0,0,1);
vkvg_fill(ctx);
}
int main(int argc, char *argv[]) {
no_test_size = true;
+ PERFORM_TEST (clip_transformed_ec, argc, argv);
PERFORM_TEST (clipped_paint_ec, argc, argv);
PERFORM_TEST (clipped_paint_eo, argc, argv);
PERFORM_TEST (clipped_transformed_ec, argc, argv);
printf("\t\t\t - b: Butt (default)\n");
printf("\t\t\t - r: Rount\n");
printf("\t\t\t - s: Square\n");
+ printf("\t-f fill_rule:\tset current fill rule:\n");
+ printf("\t\t\t - 0: Even Odd\n");
+ printf("\t\t\t - 1: Non Zero\n");
printf("\t-d:\t\tenable dashes.\n");
printf("\t-n index:\tRun only a single test, zero based index.\n");
printf("\t-q:\t\tQuiet, don't print measures table head row, usefull for batch tests.\n");
line_width = atoi (argv[i]);
}else if (strcmp (argv[i], "-d\0") == 0) {
dashes_count = 2;
+ }else if (strcmp (argv[i], "-f\0") == 0) {
+ if (argc -1 < ++i)
+ _print_usage_and_exit();
+ fill_rule = atoi (argv[i]);
} else if (strcmp (argv[i], "-o\0") == 0) {
offscreen = true;
}else if (strcmp (argv[i], "-j\0") == 0) {
vkvg_destroy(ctx);
}
+void opacity(){
+ VkvgContext ctx = vkvg_create(surf);
+ vkvg_clear(ctx);
+
+ vkvg_set_source_rgba(ctx, 1,0,0,1.0f);
+ vkvg_rectangle(ctx,100,100,200,200);
+ vkvg_fill(ctx);
+
+ vkvg_set_opacity(ctx,0.5f);
+
+ vkvg_set_source_rgba(ctx, 0,0,1,1.0f);
+ vkvg_rectangle(ctx,200,200,200,200);
+ vkvg_fill(ctx);
+
+ vkvg_destroy(ctx);
+}
+
int main(int argc, char *argv[]) {
no_test_size = true;
PERFORM_TEST (compositing, argc, argv);
+ PERFORM_TEST (opacity, argc, argv);
return 0;
}
void test(){
VkvgContext ctx = vkvg_create(surf);
- vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_NON_ZERO);
vkvg_set_line_width(ctx, 20);
vkvg_scale(ctx,2,2);
float h = (float)test_height;
VkvgContext ctx = _initCtx();
- vkvg_set_fill_rule(ctx, fill_rule);
randomize_color(ctx);
float x1 = rndf() * w;
vkvg_move_to (ctx, 100, 100);
vkvg_rel_line_to (ctx, 50, -80);
vkvg_rel_line_to (ctx, 50, 80);
- //vkvg_close_path (ctx);
+ vkvg_close_path (ctx);
vkvg_move_to (ctx, 300, 100);
vkvg_rel_line_to (ctx, 50, -80);
}
int main(int argc, char *argv[]) {
+ //vkvg_log_level = VKVG_LOG_FULL;
no_test_size = true;
PERFORM_TEST (test, argc, argv);
return 0;
float x = 100;
pat = create_grad(ctx,x);
//vkvg_pattern_set_extend(pat,VKVG_EXTEND_NONE);
- vkvg_rectangle(ctx, x,200,20,20);
+ vkvg_rectangle(ctx, x,200,50,50);
vkvg_set_source (ctx, pat);
vkvg_pattern_destroy (pat);
vkvg_fill(ctx);
x+=100;
- pat = create_grad(ctx,x);
+ pat = vkvg_pattern_create_linear(10,0,300,0);
+ vkvg_pattern_add_color_stop(pat, 0, 0, 0, 1, 0);
+ vkvg_pattern_add_color_stop(pat, 1, 1, 0, 0, 1);
//vkvg_pattern_set_extend(pat,VKVG_EXTEND_NONE);
- vkvg_rectangle(ctx, x,200,20,20);
+ vkvg_rectangle(ctx, 10,10,300,50);
vkvg_set_source (ctx, pat);
vkvg_pattern_destroy (pat);
vkvg_fill(ctx);
- x+=100;
+ x+=200;
pat = create_grad(ctx,x);
//vkvg_pattern_set_extend(pat,VKVG_EXTEND_NONE);
- vkvg_rectangle(ctx, x,200,20,20);
+ vkvg_rectangle(ctx, x,200,50,50);
vkvg_set_source (ctx, pat);
vkvg_pattern_destroy (pat);
vkvg_fill(ctx);
pat = create_grad(ctx,x);
//vkvg_pattern_set_extend(pat,VKVG_EXTEND_NONE);
- vkvg_rectangle(ctx, x,200,20,20);
+ vkvg_rectangle(ctx, x,200,50,50);
vkvg_set_source (ctx, pat);
vkvg_pattern_destroy (pat);
vkvg_fill(ctx);
int main(int argc, char *argv[]) {
no_test_size = true;
PERFORM_TEST(paint, argc, argv);
- /*PERFORM_TEST(paint_repeat, argc, argv);
- PERFORM_TEST(gradient_transform, argc, argv);*/
+ PERFORM_TEST(paint_repeat, argc, argv);
+ PERFORM_TEST(gradient_transform, argc, argv);
return 0;
}
vkvg_surface_destroy(imgSurf);
vkvg_destroy(ctx);
}
+void translate(){
+ VkvgContext ctx = vkvg_create(surf);
+ vkvg_translate (ctx, 150,50);
+ VkvgSurface imgSurf = vkvg_surface_create_from_image(device, imgPath);
+ vkvg_set_source_surface(ctx, imgSurf, 0, 0);
+
+ vkvg_paint(ctx);
+
+ vkvg_surface_destroy(imgSurf);
+ vkvg_destroy(ctx);
+}
+void offset_and_scale(){
+ VkvgContext ctx = vkvg_create(surf);
+ vkvg_scale (ctx, 0.2f,0.2f);
+ VkvgSurface imgSurf = vkvg_surface_create_from_image(device, imgPath);
+ vkvg_set_source_surface(ctx, imgSurf, 100, 100);
+
+ vkvg_paint(ctx);
+
+ vkvg_surface_destroy(imgSurf);
+ vkvg_destroy(ctx);
+}
+
+static float angle = 0;
+void paint_with_rot(){
+ angle += 0.005;
+ VkvgContext ctx = vkvg_create(surf);
+ vkvg_clear(ctx);
+
+ vkvg_rotate (ctx, angle);
+ VkvgSurface imgSurf = vkvg_surface_create_from_image(device, imgPath);
+ vkvg_set_source_surface(ctx, imgSurf, 0, 0);
+
+ vkvg_paint(ctx);
+
+ vkvg_surface_destroy(imgSurf);
+ vkvg_destroy(ctx);
+}
+void offset_and_rot(){
+ angle += 0.005;
+ VkvgContext ctx = vkvg_create(surf);
+ vkvg_clear(ctx);
+
+ vkvg_rotate (ctx, angle);
+ VkvgSurface imgSurf = vkvg_surface_create_from_image(device, imgPath);
+ vkvg_set_source_surface(ctx, imgSurf, 100, 100);
+
+ vkvg_paint(ctx);
+
+ vkvg_surface_destroy(imgSurf);
+ vkvg_destroy(ctx);
+}
void paint_pattern () {
VkvgContext ctx = vkvg_create(surf);
PERFORM_TEST (paint, argc, argv);
PERFORM_TEST (paint_offset, argc, argv);
PERFORM_TEST (paint_with_scale, argc, argv);
+ PERFORM_TEST (offset_and_scale, argc, argv);
+ PERFORM_TEST (translate, argc, argv);
+ PERFORM_TEST (paint_with_rot, argc, argv);
+ PERFORM_TEST (offset_and_rot, argc, argv);
PERFORM_TEST (paint_pattern, argc, argv);
PERFORM_TEST (paint_patt_repeat, argc, argv);
PERFORM_TEST (paint_patt_repeat_scalled, argc, argv);
vkvg_set_line_cap (ctx, lineCap);
if (startWithArc)
- vkvg_arc(ctx,pts[0].x,pts[0].y,200, 0.3f, M_PIF);
+ vkvg_arc_negative(ctx,pts[0].x,pts[0].y,200, M_PIF*1.5f, M_PIF);
else
vkvg_move_to(ctx,pts[0].x,pts[0].y);
for (int i=1; i<ptsCount-1; i++)
vkvg_line_to(ctx,pts[i].x,pts[i].y);
if (endWithArc)
- vkvg_arc(ctx,pts[ptsCount-1].x,pts[ptsCount-1].y,200, 0.3f, M_PIF);
+ vkvg_arc_negative(ctx,pts[ptsCount-1].x,pts[ptsCount-1].y,200, M_PIF*1.5f, M_PIF);
else
vkvg_line_to(ctx,pts[ptsCount-1].x,pts[ptsCount-1].y);
vkvg_set_source_rgba(ctx,0,0,0,1);
vkvg_stroke(ctx);
vkvg_set_source_rgba(ctx,0.5f,0.5f,1.0f,0.7f);
- vkvg_arc(ctx, pts[hoverPt].x, pts[hoverPt].y, pointSize, 0, M_PIF*2);
+ vkvg_arc (ctx, pts[hoverPt].x, pts[hoverPt].y, pointSize, 0, M_PIF*2);
vkvg_fill_preserve(ctx);
vkvg_stroke(ctx);
} else
#include "test.h"
-vkvg_fill_rule_t fillrule = VKVG_FILL_RULE_NON_ZERO;
float lineWidth = 10.f;
VkvgSurface createSurf (uint32_t width, uint32_t height) {
VkvgSurface s = vkvg_surface_create(device, width, height);
- VkvgContext ctx = vkvg_create(s);
- vkvg_set_fill_rule(ctx,fillrule);
+ VkvgContext ctx = _initCtx(surf);
vkvg_set_line_width(ctx,lineWidth);
float hlw = lineWidth/2.f;
/*
void paint(){
VkvgSurface src = createSurf(256,256);
- VkvgContext ctx = vkvg_create(surf);
- vkvg_set_fill_rule(ctx,fillrule);
+ VkvgContext ctx = _initCtx(surf);
vkvg_set_source_surface(ctx, src, 0, 0);
vkvg_paint(ctx);
vkvg_destroy(ctx);
}
void paint_with_offset(){
VkvgSurface src = createSurf(256,256);
- VkvgContext ctx = vkvg_create(surf);
+ VkvgContext ctx = _initCtx(surf);
vkvg_set_source_rgba(ctx,0,1,0,0.5);
vkvg_paint(ctx);
- vkvg_set_fill_rule(ctx,fillrule);
vkvg_set_source_surface(ctx, src, 100, 100);
vkvg_paint(ctx);
vkvg_destroy(ctx);
}
void paint_multiple(){
VkvgSurface src = createSurf(256,256);
- VkvgContext ctx = vkvg_create(surf);
- vkvg_set_fill_rule(ctx,fillrule);
+ VkvgContext ctx = _initCtx(surf);
for(int i=0;i<10;i++) {
vkvg_set_source_surface(ctx, src, i * 20, i * 20);
vkvg_paint(ctx);
}
void paint_with_rotation(){
VkvgSurface src = createSurf(256,256);
- VkvgContext ctx = vkvg_create(surf);
- vkvg_set_fill_rule(ctx,fillrule);
+ VkvgContext ctx = _initCtx(surf);
vkvg_set_source_surface(ctx, src, 0, 0);
vkvg_rotate(ctx, 45);
vkvg_paint(ctx);
}
void paint_with_scale(){
VkvgSurface src = createSurf(256,256);
- VkvgContext ctx = vkvg_create(surf);
- vkvg_set_fill_rule(ctx,fillrule);
+ VkvgContext ctx = _initCtx(surf);
vkvg_set_source_surface(ctx, src, 0, 0);
vkvg_scale (ctx, 0.2f,0.2f);
vkvg_paint(ctx);
}
void paint_rect(){
VkvgSurface src = createSurf(256,256);
- VkvgContext ctx = vkvg_create(surf);
- vkvg_set_fill_rule(ctx,fillrule);
+ VkvgContext ctx = _initCtx(surf);
vkvg_set_source_surface(ctx, src, 0, 0);
vkvg_rectangle(ctx,100,100,300,200);
vkvg_paint(ctx);
}
//TODO:test failed: full screen paint instead of rotated rect
void paint_rect_with_rotation(){
- VkvgContext ctx = vkvg_create(surf);
- vkvg_set_fill_rule(ctx,fillrule);
+ VkvgContext ctx = _initCtx(surf);
vkvg_rotate(ctx, 45);
vkvg_set_source_rgba(ctx,1,0,0,1);
vkvg_rectangle(ctx,100,100,300,200);
vkvg_destroy(ctx);
}
void paint_rect_with_scale(){
- VkvgContext ctx = vkvg_create(surf);
- vkvg_set_fill_rule(ctx,fillrule);
+ VkvgContext ctx = _initCtx(surf);
vkvg_scale (ctx, 0.2f,0.2f);
vkvg_set_source_rgba(ctx,1,0,0,1);
vkvg_rectangle(ctx,100,100,300,200);
PERFORM_TEST (paint_with_rotation, argc, argv);
PERFORM_TEST (paint_with_scale, argc, argv);
PERFORM_TEST (paint_rect, argc, argv);
- /*PERFORM_TEST (paint_rect_with_rotation, argc, argv);
- PERFORM_TEST (paint_rect_with_scale, argc, argv);*/
+ PERFORM_TEST (paint_rect_with_rotation, argc, argv);
+ PERFORM_TEST (paint_rect_with_scale, argc, argv);
return 0;
}
--- /dev/null
+#include "test.h"
+#include "vectors.h"
+
+vkvg_fill_rule_t fillrule = VKVG_FILL_RULE_NON_ZERO;
+static VkSampleCountFlags samples = VK_SAMPLE_COUNT_8_BIT;
+float lineWidth = 4.0f;
+vkvg_line_join_t lineJoin = VKVG_LINE_JOIN_MITER;
+vkvg_line_cap_t lineCap = VKVG_LINE_CAP_BUTT;
+bool isClosed = false, refresh = true;
+bool startWithArc = false, endWithArc = false;
+
+int ptsCount = 0;
+vec2 pts[1024];
+int hoverPt = -1;
+double pointSize = 7;
+float _dashes[] = {5.0f,3.0f};
+int _ndashes = 2;
+
+void emit_path (VkvgContext ctx) {
+ vkvg_move_to(ctx,pts[0].x,pts[0].y);
+ for (int i=1; i<ptsCount; i++)
+ vkvg_line_to(ctx,pts[i].x,pts[i].y);
+ if (isClosed)
+ vkvg_close_path(ctx);
+}
+
+void draw (){
+ refresh = false;
+
+ VkvgContext ctx = vkvg_create(surf);
+ vkvg_clear(ctx);
+ vkvg_set_source_rgba(ctx,1,0,0,1);
+ vkvg_set_line_width (ctx,lineWidth);
+ vkvg_set_line_join (ctx, lineJoin);
+ vkvg_set_line_cap (ctx, lineCap);
+
+ emit_path(ctx);
+ float x1, y1, x2, y2;
+ vkvg_path_extents(ctx, &x1, &y1, &x2, &y2);
+ vkvg_set_source_rgba(ctx,0.2,0.2,1,0.5);
+ if (hoverPt>=0) {
+ if (isClosed)
+ vkvg_fill_preserve(ctx);
+ vkvg_set_source_rgba(ctx,1,0.2,0.2,0.5);
+ vkvg_stroke_preserve(ctx);
+ vkvg_set_dash(ctx, NULL, 0, 0);
+ vkvg_set_line_width(ctx,1);
+ vkvg_set_source_rgba(ctx,0,0,0,1);
+ vkvg_stroke(ctx);
+ vkvg_set_source_rgba(ctx,0.5f,0.5f,1.0f,0.7f);
+ vkvg_arc (ctx, pts[hoverPt].x, pts[hoverPt].y, pointSize, 0, M_PIF*2);
+ vkvg_fill_preserve(ctx);
+ vkvg_stroke(ctx);
+ } else {
+ if (isClosed)
+ vkvg_fill_preserve(ctx);
+ vkvg_set_source_rgba(ctx,1,0.2,0.2,0.5);
+ vkvg_stroke(ctx);
+ }
+
+ vkvg_rectangle(ctx, x1, y1, x2 - x1, y2 - y1);
+ vkvg_set_dash(ctx, _dashes, _ndashes, 0);
+ vkvg_set_line_width(ctx,1);
+ vkvg_set_source_rgba(ctx,0,1,0,1);
+ vkvg_stroke(ctx);
+
+ vkvg_destroy(ctx);
+}
+static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
+ if (action != GLFW_PRESS)
+ return;
+ switch (key) {
+ case GLFW_KEY_ESCAPE :
+ glfwSetWindowShouldClose(window, GLFW_TRUE);
+ break;
+ case GLFW_KEY_W :
+ isClosed ^= true;
+ break;
+ case GLFW_KEY_DELETE :
+ ptsCount = 0;
+ break;
+ case GLFW_KEY_J :
+ lineJoin++;
+ if (lineJoin > 2)
+ lineJoin = 0;
+ break;
+ case GLFW_KEY_C :
+ lineCap++;
+ if (lineCap > 2)
+ lineCap = 0;
+ break;
+ case GLFW_KEY_KP_SUBTRACT :
+ if (ptsCount > 1)
+ ptsCount--;
+ break;
+ }
+ refresh = true;
+}
+static vec2 mousePos;
+static void mouse_move_callback(GLFWwindow* window, double x, double y){
+ mousePos = (vec2) {x, y};
+ if (mouseDown) {
+ if (hoverPt < 0)
+ return;
+ pts[hoverPt] = mousePos;
+ refresh = true;
+ } else {
+ for (int i=0; i<ptsCount; i++) {
+ if (x > pts[i].x - pointSize &&
+ x < pts[i].x + pointSize &&
+ y > pts[i].y - pointSize &&
+ y < pts[i].y + pointSize) {
+ hoverPt = i;
+ refresh = true;
+ return;
+ }
+ }
+ refresh = true;
+ hoverPt = -1;
+ }
+}
+static void scroll_callback(GLFWwindow* window, double x, double y){
+ if (y<0.f)
+ zoom *= 0.5f;
+ else
+ zoom *= 2.0f;
+}
+static void mouse_button_callback(GLFWwindow* window, int but, int state, int modif){
+ if (but != GLFW_MOUSE_BUTTON_1)
+ return;
+ if (state == GLFW_TRUE)
+ mouseDown = true;
+ else
+ mouseDown = false;
+ if (state == GLFW_TRUE && hoverPt < 0)
+ pts[ptsCount++] = mousePos;
+ refresh = true;
+}
+
+
+
+int main(int argc, char* argv[]) {
+
+ _parse_args (argc, argv);
+ VkEngine e;
+ e = vkengine_create (VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU, VK_PRESENT_MODE_FIFO_KHR, test_width, test_height);
+
+ VkhPresenter r = e->renderer;
+ vkengine_set_key_callback (e, key_callback);
+ vkengine_set_mouse_but_callback(e, mouse_button_callback);
+ vkengine_set_cursor_pos_callback(e, mouse_move_callback);
+ vkengine_set_scroll_callback(e, scroll_callback);
+
+ bool deferredResolve = false;
+
+ device = vkvg_device_create_from_vk_multisample(vkh_app_get_inst(e->app), r->dev->phy, r->dev->dev, r->qFam, 0, samples, deferredResolve);
+ surf = vkvg_surface_create(device, test_width, test_height);
+
+ vkh_presenter_build_blit_cmd (r, vkvg_surface_get_vk_image(surf), test_width, test_height);
+
+ while (!vkengine_should_close (e)) {
+ glfwPollEvents();
+
+ if (refresh)
+ draw ();
+
+ if (!vkh_presenter_draw (r)){
+ vkh_presenter_get_size (r, &test_width, &test_height);
+ vkvg_surface_destroy (surf);
+ surf = vkvg_surface_create(device, test_width, test_height);
+ vkh_presenter_build_blit_cmd (r, vkvg_surface_get_vk_image(surf), test_width, test_height);
+ vkDeviceWaitIdle(r->dev->dev);
+ continue;
+ }
+ }
+ vkDeviceWaitIdle(e->dev->dev);
+
+ vkvg_surface_destroy (surf);
+
+ vkvg_device_destroy (device);
+
+ vkengine_destroy (e);
+
+ return 0;
+}
--- /dev/null
+#include "test.h"
+
+float lineWidth = 10.f;
+const char* imgPath = "data/miroir.jpg";
+
+VkvgPattern create_grad (VkvgContext ctx) {
+ VkvgPattern pat = vkvg_pattern_create_linear(0,0,200,0);
+ vkvg_pattern_add_color_stop(pat, 0, 1, 0, 0, 1);
+ vkvg_pattern_add_color_stop(pat, 0.5, 0, 1, 0, 1);
+ vkvg_pattern_add_color_stop(pat, 1.0, 0, 0, 1, 1);
+ return pat;
+}
+
+VkvgSurface createSurf (uint32_t width, uint32_t height) {
+ VkvgSurface s = vkvg_surface_create(device, width, height);
+ VkvgContext ctx = _initCtx(surf);
+ vkvg_set_line_width(ctx,lineWidth);
+ float hlw = lineWidth/2.f;
+ /*
+ vkvg_set_source_rgba(ctx,0,1,0,0.5);
+ vkvg_fill_preserve(ctx);*/
+ vkvg_set_source_rgba(ctx,1,0,0,0.5);
+ vkvg_paint(ctx);
+ vkvg_set_source_rgba(ctx,0,0,1,0.5);
+ vkvg_rectangle(ctx,hlw,hlw,(float)width-lineWidth,(float)height-lineWidth);
+ vkvg_stroke(ctx);
+ vkvg_destroy(ctx);
+ return s;
+}
+
+void img_scale() {
+ VkvgSurface imgSurf = vkvg_surface_create_from_image(device, imgPath);
+ VkvgPattern pat = vkvg_pattern_create_for_surface(imgSurf);
+ VkvgContext ctx = _initCtx(surf);
+
+ vkvg_translate(ctx, 100,100);
+
+ vkvg_matrix_t mat;
+ vkvg_matrix_init_scale(&mat, 2.0, 2.0);
+ vkvg_pattern_set_matrix (pat, &mat);
+
+ vkvg_set_source (ctx, pat);
+ vkvg_rectangle(ctx, 0 , 0, 200, 140);
+ vkvg_fill(ctx);
+ vkvg_destroy(ctx);
+ vkvg_pattern_destroy(pat);
+ vkvg_surface_destroy(imgSurf);
+}
+
+void pat_scale(){
+
+ VkvgContext ctx = _initCtx(surf);
+ VkvgPattern pat = create_grad(ctx);
+
+ vkvg_translate(ctx, 100,100);
+
+ vkvg_matrix_t mat;
+ vkvg_matrix_init_scale(&mat, 0.5, 0.5);
+ vkvg_pattern_set_matrix (pat, &mat);
+
+ vkvg_set_source (ctx, pat);
+ vkvg_rectangle(ctx, 0 , 0, 200, 140);
+ vkvg_fill(ctx);
+ vkvg_destroy(ctx);
+ vkvg_pattern_destroy(pat);
+}
+static float angle = 0;
+void pat_rotate(){
+ angle += 0.001f;
+
+ VkvgContext ctx = _initCtx(surf);
+ VkvgPattern pat = create_grad(ctx);
+
+ //vkvg_translate(ctx, 100,100);
+
+ vkvg_matrix_t mat;
+ vkvg_matrix_init_translate(&mat, 100, 70);
+ vkvg_matrix_rotate(&mat, angle);
+ vkvg_pattern_set_matrix (pat, &mat);
+
+ vkvg_set_source (ctx, pat);
+ vkvg_rectangle(ctx, 0 , 0, 200, 140);
+ vkvg_fill(ctx);
+ vkvg_destroy(ctx);
+ vkvg_pattern_destroy(pat);
+}
+int main(int argc, char *argv[]) {
+ no_test_size = true;
+ PERFORM_TEST (pat_scale, argc, argv);
+ PERFORM_TEST (pat_rotate, argc, argv);
+ PERFORM_TEST (img_scale, argc, argv);
+ return 0;
+}
vkvg_translate (ctx, 5,5);
vkvg_rectangle(ctx, (float)depth,(float)depth,200,200);
- vkvg_clip_preserve(ctx);
+ /*vkvg_clip_preserve(ctx);
vkvg_set_source_rgb(ctx, 1.f/depth, 1.f / depth, 1.f / depth);
- vkvg_fill_preserve(ctx);
- vkvg_set_source_rgb(ctx, 0,0,0);
+ vkvg_fill_preserve(ctx);*/
+ vkvg_set_source_rgb(ctx, 0,1,0);
vkvg_stroke(ctx);
if (depth < 20)
#include "test.h"
-vkvg_fill_rule_t fillrule = VKVG_FILL_RULE_NON_ZERO;
-
void paint(){
- VkvgContext ctx = vkvg_create(surf);
- vkvg_set_fill_rule(ctx,fillrule);
+ VkvgContext ctx = _initCtx(surf);
vkvg_set_source_rgba(ctx,1,0,0,1);
vkvg_paint(ctx);
vkvg_destroy(ctx);
}
void paint_with_rotation(){
- VkvgContext ctx = vkvg_create(surf);
- vkvg_set_fill_rule(ctx,fillrule);
+ VkvgContext ctx = _initCtx(surf);
vkvg_rotate(ctx, 45);
vkvg_set_source_rgba(ctx,1,0,0,1);
vkvg_paint(ctx);
vkvg_destroy(ctx);
}
void paint_with_scale(){
- VkvgContext ctx = vkvg_create(surf);
- vkvg_set_fill_rule(ctx,fillrule);
+ VkvgContext ctx = _initCtx(surf);
vkvg_scale (ctx, 0.2f,0.2f);
vkvg_set_source_rgba(ctx,1,0,0,1);
vkvg_paint(ctx);
vkvg_destroy(ctx);
}
void paint_rect(){
- VkvgContext ctx = vkvg_create(surf);
- vkvg_set_fill_rule(ctx,fillrule);
+ VkvgContext ctx = _initCtx(surf);
vkvg_set_source_rgba(ctx,1,0,0,1);
vkvg_rectangle(ctx,100,100,300,200);
vkvg_paint(ctx);
}
//TODO:test failed: full screen paint instead of rotated rect
void paint_rect_with_rotation(){
- VkvgContext ctx = vkvg_create(surf);
- vkvg_set_fill_rule(ctx,fillrule);
+ VkvgContext ctx = _initCtx(surf);
vkvg_rotate(ctx, 45);
vkvg_set_source_rgba(ctx,1,0,0,1);
vkvg_rectangle(ctx,100,100,300,200);
vkvg_destroy(ctx);
}
void paint_rect_with_scale(){
- VkvgContext ctx = vkvg_create(surf);
- vkvg_set_fill_rule(ctx,fillrule);
+ VkvgContext ctx = _initCtx(surf);
vkvg_scale (ctx, 0.2f,0.2f);
vkvg_set_source_rgba(ctx,1,0,0,1);
vkvg_rectangle(ctx,100,100,300,200);
rotation+=0.002f;
vkvg_matrix_t mat;
- vkvg_matrix_init_translate (&mat, 512,400);
- vkvg_matrix_rotate(&mat,rotation);
+ vkvg_matrix_init_translate (&mat, panX,panY);
vkvg_matrix_scale(&mat,zoom,zoom);
- vkvg_matrix_translate(&mat,-512.f + panX,-400.f +panY);
+ vkvg_matrix_translate (&mat, 400,400);
+ vkvg_matrix_rotate(&mat,rotation);
+ vkvg_matrix_translate(&mat,-400.f,-400.f);
VkvgContext ctx = vkvg_create(surf);
vkvg_paint(ctx);
//vkvg_set_matrix(ctx,&mat);
+ vkvg_translate (ctx, panX,panY);
+ vkvg_scale(ctx,zoom,zoom);
+ vkvg_translate (ctx, 400,400);
+ vkvg_rotate(ctx,rotation);
+ vkvg_translate(ctx,-400.f,-400.f);
cairo_print_arc(ctx);
--- /dev/null
+/*
+ * Copyright (c) 2018-2022 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
+ * Software, and to permit persons to whom the Software is furnished to do so, subject
+ * to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "test.h"
+
+
+void _test_rounded_rect (VkvgContext cr) {
+ /* a custom shape that could be wrapped in a function */
+ float x0 = -100, /* parameters like vkvg_rectangle */
+ y0 = -100,
+ rect_width = 200,
+ rect_height = 200,
+ radius = 102.4f; /* and an approximate curvature radius */
+
+ float x1,y1;
+
+ x1=x0+rect_width;
+ y1=y0+rect_height;
+ if (!rect_width || !rect_height)
+ return;
+ if (rect_width/2<radius) {
+ if (rect_height/2<radius) {
+ vkvg_move_to (cr, x0, (y0 + y1)/2);
+ vkvg_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0);
+ vkvg_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2);
+ vkvg_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1);
+ vkvg_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2);
+ } else {
+ vkvg_move_to (cr, x0, y0 + radius);
+ vkvg_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0);
+ vkvg_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
+ vkvg_line_to (cr, x1 , y1 - radius);
+ vkvg_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1);
+ vkvg_curve_to (cr, x0, y1, x0, y1, x0, y1- radius);
+ }
+ } else {
+ if (rect_height/2<radius) {
+ vkvg_move_to (cr, x0, (y0 + y1)/2);
+ vkvg_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
+ vkvg_line_to (cr, x1 - radius, y0);
+ vkvg_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2);
+ vkvg_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
+ vkvg_line_to (cr, x0 + radius, y1);
+ vkvg_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2);
+ } else {
+ vkvg_move_to (cr, x0, y0 + radius);
+ vkvg_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
+ vkvg_line_to (cr, x1 - radius, y0);
+ vkvg_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
+ vkvg_line_to (cr, x1 , y1 - radius);
+ vkvg_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
+ vkvg_line_to (cr, x0 + radius, y1);
+ vkvg_curve_to (cr, x0, y1, x0, y1, x0, y1- radius);
+ }
+ }
+ vkvg_close_path (cr);
+
+ vkvg_set_source_rgb (cr, 0.5f, 0.5f, 1);
+ vkvg_fill_preserve (cr);
+ vkvg_set_source_rgba (cr, 0.5f, 0, 0, 0.5f);
+ vkvg_set_line_width (cr, 10.0f);
+ vkvg_stroke (cr);
+}
+
+
+static float rotation = 0.f;
+
+void cairo_tests () {
+ rotation+=0.002f;
+
+ VkvgContext ctx = vkvg_create(surf);
+ vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD);
+ vkvg_set_source_rgba(ctx,1.0f,1.0f,1.0f,1);
+ vkvg_paint(ctx);
+
+ vkvg_set_line_width(ctx,10);
+
+ vkvg_set_source_rgb(ctx,0,0,1);
+
+ vkvg_translate (ctx, test_width/2,test_height/2);
+ vkvg_rotate(ctx, rotation);
+ //vkvg_scale(ctx, 200,200);
+
+ vkvg_arc (ctx, 0, 0, 150, 0, M_PI*1.5);
+ vkvg_stroke(ctx);
+
+ _test_rounded_rect(ctx);
+
+ vkvg_destroy(ctx);
+}
+
+
+int main(int argc, char *argv[]) {
+ no_test_size = true;
+ PERFORM_TEST (cairo_tests, argc, argv);
+ return 0;
+}