diff options
Diffstat (limited to 'tests')
36 files changed, 2032 insertions, 1860 deletions
diff --git a/tests/arcs.c b/tests/arcs.c index 3d10c35..daeb48c 100644 --- a/tests/arcs.c +++ b/tests/arcs.c @@ -1,25 +1,91 @@ #include "test.h" -void test(){ - VkvgContext ctx = vkvg_create(surf); +void draw_growing_circles (VkvgContext ctx, float y, int count) { + float x = 2; + for (int i=1; i<count; i++) { + x += 0.5f*i; + //vkvg_set_source_rgb (ctx, 1,0,1); + vkvg_arc(ctx, x + 2, y, 0.5f * i, 0, M_PIF*1.5f); + //vkvg_set_source_rgb (ctx, 0,1,1); + //vkvg_arc_negative(ctx, x + 2, y, 0.5 * i, M_PI/2,0); + x += 0.5f*i + 5; + } +} + +void scaled_up() { + VkvgContext ctx = vkvg_create(surf); - vkvg_set_line_width(ctx, 0.5); - vkvg_set_source_rgb (ctx, 1,1,1); - vkvg_paint(ctx); - vkvg_set_source_rgb (ctx, 0,0,0); + vkvg_set_source_rgb (ctx, 1,1,1); + vkvg_paint(ctx); + vkvg_set_source_rgb (ctx, 0,0,0); - vkvg_scale(ctx,3,3); - vkvg_arc(ctx, 150, 100, 3.5, 0, M_PI*2); - vkvg_stroke(ctx); - vkvg_arc(ctx, 200, 200, 10, 0, M_PI*2); - vkvg_fill(ctx); + vkvg_scale(ctx,100,100); + vkvg_arc(ctx, 2, 2, 0.5f, 0, M_PIF/2.f); + vkvg_stroke(ctx); - vkvg_destroy(ctx); + vkvg_destroy(ctx); } +void sizes() { + VkvgContext ctx = vkvg_create(surf); -int main(int argc, char *argv[]) { + vkvg_set_source_rgb (ctx, 1,1,1); + vkvg_paint(ctx); + vkvg_set_source_rgb (ctx, 0,0,0); + + draw_growing_circles (ctx, 100, 40); + vkvg_stroke(ctx); + + vkvg_destroy(ctx); +} +void test(){ + VkvgContext ctx = vkvg_create(surf); + + vkvg_set_source_rgb (ctx, 1,1,1); + vkvg_paint(ctx); + vkvg_set_source_rgb (ctx, 0,0,0); - perform_test (test, 1024, 768); + vkvg_set_source_rgb (ctx, 1,0,1); + vkvg_set_line_width(ctx, 5.0); + vkvg_arc(ctx, 100, 100, 20, 0, M_PIF/2); + vkvg_stroke(ctx); - return 0; + vkvg_set_source_rgb (ctx, 0,1,1); + vkvg_arc_negative(ctx, 100, 100, 20, 0, M_PIF/2); + vkvg_stroke(ctx); + + vkvg_set_source_rgb (ctx, 1,0,1); + vkvg_arc(ctx, 100, 200, 20, M_PIF/2, 0); + vkvg_stroke(ctx); + + vkvg_set_source_rgb (ctx, 0,1,1); + vkvg_arc_negative(ctx, 100, 200, 20, M_PIF/2, 0); + vkvg_stroke(ctx); + + vkvg_set_source_rgb (ctx, 0,0,1); + vkvg_set_line_width(ctx, 10.0); + vkvg_arc(ctx, 350, 100, 40, 0, M_PIF*2); + vkvg_stroke(ctx); + + vkvg_set_source_rgb (ctx, 0,1,0); + vkvg_set_line_width(ctx, 1.0); + vkvg_arc(ctx, 150, 100, 3.5, 0, M_PIF*2); + vkvg_stroke(ctx); + vkvg_arc(ctx, 200, 200, 10, 0, M_PIF*2); + vkvg_fill(ctx); + + vkvg_set_source_rgb (ctx, 1,0,0); + vkvg_scale(ctx,3,3); + vkvg_arc(ctx, 150, 100, 3.5, 0, M_PIF*2); + vkvg_stroke(ctx); + vkvg_arc(ctx, 200, 200, 10, 0, M_PIF*2); + vkvg_fill(ctx); + + vkvg_destroy(ctx); +} + +int main(int argc, char *argv[]) { + PERFORM_TEST (sizes, argc, argv); + PERFORM_TEST (scaled_up, argc, argv); + PERFORM_TEST (test, argc, argv); + return 0; } diff --git a/tests/circles.c b/tests/circles.c new file mode 100644 index 0000000..906652f --- /dev/null +++ b/tests/circles.c @@ -0,0 +1,64 @@ +#include "test.h" + +void draw_growing_circles (VkvgContext ctx, float y, int count) { + float x = 2; + for (int i=1; i<count; i++) { + x += 0.5f*i; + vkvg_arc(ctx, x + 2, y, 0.5f * i, 0, M_PIF*2.f); + x += 0.5f*i + 5; + } +} + +void scaled_up() { + VkvgContext ctx = vkvg_create(surf); + + vkvg_set_source_rgb (ctx, 1,1,1); + vkvg_paint(ctx); + vkvg_set_source_rgb (ctx, 0,0,0); + + vkvg_scale(ctx,100,100); + vkvg_arc(ctx, 2, 2, 0.5f, 0, M_PIF*2); + vkvg_stroke(ctx); + + vkvg_destroy(ctx); +} +void fill_and_stroke () { + vkvg_surface_clear(surf); + VkvgContext ctx = vkvg_create(surf); + vkvg_set_source_rgba (ctx, 0,0.1f,0.8f, 0.5f); + vkvg_set_line_width(ctx,10); + + vkvg_arc(ctx, 300, 300, 150.f, 0, M_PIF*2); + vkvg_fill_preserve(ctx); + vkvg_stroke(ctx); + + vkvg_destroy(ctx); +} +void sizes() { + VkvgContext ctx = vkvg_create(surf); + + vkvg_set_source_rgb (ctx, 1,1,1); + vkvg_paint(ctx); + vkvg_set_source_rgb (ctx, 0,0,0); + + draw_growing_circles (ctx, 100, 40); + vkvg_fill (ctx); + + draw_growing_circles (ctx, 200, 40); + vkvg_stroke(ctx); + + vkvg_set_source_rgba (ctx, 0,0,1,0.4F); + draw_growing_circles (ctx, 300, 40); + vkvg_fill_preserve (ctx); + vkvg_set_line_width(ctx,5); + vkvg_stroke(ctx); + + vkvg_destroy(ctx); +} + +int main(int argc, char *argv[]) { + PERFORM_TEST (fill_and_stroke, argc, argv); + //PERFORM_TEST (sizes, argc, argv); + //PERFORM_TEST (scaled_up, argc, argv); + return 0; +} diff --git a/tests/clip.c b/tests/clip.c index e618974..ac24af2 100644 --- a/tests/clip.c +++ b/tests/clip.c @@ -1,82 +1,81 @@ #include "test.h" void test_clip(){ - vkvg_surface_clear(surf); - VkvgContext ctx = vkvg_create(surf); + vkvg_surface_clear(surf); + VkvgContext ctx = vkvg_create(surf); - vkvg_move_to(ctx,10,10); - vkvg_line_to(ctx,400,150); - vkvg_line_to(ctx,900,10); - vkvg_line_to(ctx,700,450); - vkvg_line_to(ctx,900,750); - vkvg_line_to(ctx,500,650); - vkvg_line_to(ctx,100,800); - vkvg_line_to(ctx,150,400); - vkvg_clip_preserve(ctx); - vkvg_set_operator(ctx, VKVG_OPERATOR_CLEAR); - vkvg_fill_preserve(ctx); - vkvg_clip(ctx); - vkvg_set_operator(ctx, VKVG_OPERATOR_OVER); + vkvg_move_to(ctx,10,10); + vkvg_line_to(ctx,400,150); + vkvg_line_to(ctx,900,10); + vkvg_line_to(ctx,700,450); + vkvg_line_to(ctx,900,750); + vkvg_line_to(ctx,500,650); + vkvg_line_to(ctx,100,800); + vkvg_line_to(ctx,150,400); + vkvg_clip_preserve(ctx); + vkvg_set_operator(ctx, VKVG_OPERATOR_CLEAR); + vkvg_fill_preserve(ctx); + vkvg_clip(ctx); + vkvg_set_operator(ctx, VKVG_OPERATOR_OVER); - vkvg_set_source_rgb(ctx,1,0,0); - vkvg_paint(ctx); + vkvg_set_source_rgb(ctx,1,0,0); + vkvg_paint(ctx); - vkvg_destroy(ctx); + vkvg_destroy(ctx); } void test_clip2(){ - vkvg_surface_clear(surf); - VkvgContext ctx = vkvg_create(surf); - vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_NON_ZERO); - vkvg_rectangle(ctx, 50,50,500,500); - vkvg_clip(ctx); + vkvg_surface_clear(surf); + VkvgContext ctx = vkvg_create(surf); + vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_NON_ZERO); + vkvg_rectangle(ctx, 50,50,500,500); + vkvg_clip(ctx); - vkvg_set_source_rgb(ctx,1,0,0); - vkvg_paint(ctx); + vkvg_set_source_rgb(ctx,1,0,0); + vkvg_paint(ctx); - vkvg_save(ctx); - vkvg_rectangle(ctx, 100,100,350,350); - vkvg_clip(ctx); - vkvg_save(ctx); + vkvg_save(ctx); + vkvg_rectangle(ctx, 100,100,350,350); + vkvg_clip(ctx); + vkvg_save(ctx); - vkvg_set_source_rgb(ctx,1,1,0); - vkvg_paint(ctx); + vkvg_set_source_rgb(ctx,1,1,0); + vkvg_paint(ctx); - vkvg_rectangle(ctx, 200,200,200,200); - vkvg_clip(ctx); + vkvg_rectangle(ctx, 200,200,200,200); + vkvg_clip(ctx); - vkvg_set_source_rgb(ctx,0,1,0); - vkvg_paint(ctx); + vkvg_set_source_rgb(ctx,0,1,0); + vkvg_paint(ctx); - vkvg_restore(ctx); + vkvg_restore(ctx); - vkvg_rectangle(ctx, 350,350,420,420); - vkvg_set_source_rgb(ctx,0,0,1); - vkvg_fill(ctx); + vkvg_rectangle(ctx, 350,350,420,420); + vkvg_set_source_rgb(ctx,0,0,1); + vkvg_fill(ctx); - vkvg_restore(ctx); + vkvg_restore(ctx); - //vkvg_clip(ctx); - // - /*vkvg_clip_preserve(ctx); - vkvg_set_operator(ctx, VKVG_OPERATOR_CLEAR); - vkvg_fill_preserve(ctx);*/ - //vkvg_clip(ctx); - //vkvg_set_operator(ctx, VKVG_OPERATOR_OVER); - /*vkvg_rectangle(ctx, 200,200,220,220); - vkvg_set_source_rgb(ctx,1,0,0); - vkvg_paint(ctx);*/ + //vkvg_clip(ctx); + // + /*vkvg_clip_preserve(ctx); + vkvg_set_operator(ctx, VKVG_OPERATOR_CLEAR); + vkvg_fill_preserve(ctx);*/ + //vkvg_clip(ctx); + //vkvg_set_operator(ctx, VKVG_OPERATOR_OVER); + /*vkvg_rectangle(ctx, 200,200,220,220); + vkvg_set_source_rgb(ctx,1,0,0); + vkvg_paint(ctx);*/ - vkvg_destroy(ctx); + vkvg_destroy(ctx); } int main(int argc, char *argv[]) { - - perform_test (test_clip2, 1024, 768); - - return 0; + PERFORM_TEST (test_clip, argc, argv); + PERFORM_TEST (test_clip2, argc, argv); + return 0; } diff --git a/tests/colinear.c b/tests/colinear.c index 7f426ad..68bf3ad 100644 --- a/tests/colinear.c +++ b/tests/colinear.c @@ -1,25 +1,25 @@ #include "test.h" void test(){ - VkvgContext ctx = vkvg_create(surf); + VkvgContext ctx = vkvg_create(surf); - vkvg_set_source_rgba(ctx,0.7,0.7,0.7,1); - vkvg_paint(ctx); + vkvg_set_source_rgba(ctx,0.7f,0.7f,0.7f,1); + vkvg_paint(ctx); - vkvg_set_source_rgba(ctx,0,1,0,1); - vkvg_set_line_width(ctx,10); + vkvg_set_source_rgba(ctx,0,1,0,1); + vkvg_set_line_width(ctx,10); - vkvg_move_to(ctx,100,100); - vkvg_line_to(ctx,100,200); - vkvg_line_to(ctx,100,100); - vkvg_stroke(ctx); + vkvg_move_to(ctx,100,100); + vkvg_line_to(ctx,100,200); + vkvg_line_to(ctx,100,100); + vkvg_stroke(ctx); - vkvg_destroy(ctx); + vkvg_destroy(ctx); } int main(int argc, char *argv[]) { - perform_test (test, 1024, 768); + PERFORM_TEST (test, argc, argv); - return 0; + return 0; } diff --git a/tests/common/test.c b/tests/common/test.c index b8de624..e210a2b 100644 --- a/tests/common/test.c +++ b/tests/common/test.c @@ -1,299 +1,427 @@ #include "test.h" +#include "string.h" -float panX = 0.f; -float panY = 0.f; +#if defined(_WIN32) || defined(_WIN64) +int gettimeofday(struct timeval * tp, void * tzp) +{ + // FILETIME Jan 1 1970 00:00:00 + // Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's + static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL); + + SYSTEMTIME nSystemTime; + FILETIME nFileTime; + uint64_t nTime; + + GetSystemTime( &nSystemTime ); + SystemTimeToFileTime( &nSystemTime, &nFileTime ); + nTime = ((uint64_t)nFileTime.dwLowDateTime ) ; + nTime += ((uint64_t)nFileTime.dwHighDateTime) << 32; + + tp->tv_sec = (long) ((nTime - EPOCH) / 10000000L); + tp->tv_usec = (long) (nSystemTime.wMilliseconds * 1000); + return 0; +} +#endif + +float panX = 0.f; +float panY = 0.f; float lastX = 0.f; float lastY = 0.f; -float zoom = 1.0f; +float zoom = 1.0f; bool mouseDown = false; -VkvgDevice device = NULL; -VkvgSurface surf = NULL; +VkvgDevice device = NULL; +VkvgSurface surf = NULL; + +uint32_t test_size = 100; // items drawn in one run, or complexity +uint32_t iterations = 1000;// repeat test n times +uint32_t test_width = 1024; +uint32_t test_height= 768; +bool test_vsync = false; -uint test_size = 100; // items drawn in one run, or complexity -int iterations = 40000; // repeat test n times static bool paused = false; -static VkSampleCountFlags samples = VK_SAMPLE_COUNT_4_BIT; +static VkSampleCountFlags samples = VK_SAMPLE_COUNT_8_BIT; static vk_engine_t* e; static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { - if (action != GLFW_PRESS) - return; - switch (key) { - case GLFW_KEY_SPACE: - paused = !paused; - break; - case GLFW_KEY_ESCAPE : - glfwSetWindowShouldClose(window, GLFW_TRUE); - break; - } + if (action != GLFW_PRESS) + return; + switch (key) { + case GLFW_KEY_SPACE: + paused = !paused; + break; + case GLFW_KEY_ESCAPE : + glfwSetWindowShouldClose(window, GLFW_TRUE); + break; + } } static void char_callback (GLFWwindow* window, uint32_t c){} static void mouse_move_callback(GLFWwindow* window, double x, double y){ - if (mouseDown) { - panX += ((float)x-lastX); - panY += ((float)y-lastY); - } - lastX = (float)x; - lastY = (float)y; + if (mouseDown) { + panX += ((float)x-lastX); + panY += ((float)y-lastY); + } + lastX = (float)x; + lastY = (float)y; } static void scroll_callback(GLFWwindow* window, double x, double y){ - if (y<0.f) - zoom *= 0.5f; - else - zoom *= 2.0f; + 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 (but != GLFW_MOUSE_BUTTON_1) + return; + if (state == GLFW_TRUE) + mouseDown = true; + else + mouseDown = false; } double time_diff(struct timeval x , struct timeval y) { - double x_ms , y_ms , diff; + double x_ms , y_ms , diff; - x_ms = (double)x.tv_sec*1000000 + (double)x.tv_usec; - y_ms = (double)y.tv_sec*1000000 + (double)y.tv_usec; + x_ms = (double)x.tv_sec*1000000 + (double)x.tv_usec; + y_ms = (double)y.tv_sec*1000000 + (double)y.tv_usec; - diff = (double)y_ms - (double)x_ms; + diff = (double)y_ms - (double)x_ms; - return diff; + return diff; } void randomize_color (VkvgContext ctx) { - vkvg_set_source_rgba(ctx, - (float)rand()/RAND_MAX, - (float)rand()/RAND_MAX, - (float)rand()/RAND_MAX, - (float)rand()/RAND_MAX - ); - //vkvg_set_source_color(ctx,(uint32_t) rand()); + vkvg_set_source_rgba(ctx, + (float)rand()/RAND_MAX, + (float)rand()/RAND_MAX, + (float)rand()/RAND_MAX, + (float)rand()/RAND_MAX + ); } /* from caskbench */ double get_tick (void) { - struct timeval now; - gettimeofday (&now, NULL); - return (double)now.tv_sec + (double)now.tv_usec / 1000000.0; + struct timeval now; + gettimeofday (&now, NULL); + return (double)now.tv_sec + (double)now.tv_usec / 1000000.0; } double median_run_time (double data[], int n) { - double temp; - int i, j; - for (i = 0; i < n; i++) - for (j = i+1; j < n; j++) - { - if (data[i] > data[j]) - { - temp = data[j]; - data[j] = data[i]; - data[i] = temp; - } - } - if (n % 2 == 0) - return (data[n/2] + data[n/2-1])/2; - else - return data[n/2]; + double temp; + int i, j; + for (i = 0; i < n; i++) + for (j = i+1; j < n; j++) + { + if (data[i] > data[j]) + { + temp = data[j]; + data[j] = data[i]; + data[i] = temp; + } + } + if (n % 2 == 0) + return (data[n/2] + data[n/2-1])/2; + else + return data[n/2]; } double standard_deviation (const double data[], int n, double mean) { - double sum_deviation = 0.0; - for (int i = 0; i < n; ++i) - sum_deviation += (data[i]-mean) * (data[i]-mean); - return sqrt (sum_deviation / n); + double sum_deviation = 0.0; + int i; + for (i = 0; i < n; ++i) + sum_deviation += (data[i]-mean) * (data[i]-mean); + return sqrt (sum_deviation / n); } /***************/ -void init_test (uint width, uint height){ - e = vkengine_create (VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU, VK_PRESENT_MODE_MAILBOX_KHR, width, 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; +void init_test (uint32_t width, uint32_t height){ + if (test_vsync) + e = vkengine_create (VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU, VK_PRESENT_MODE_FIFO_KHR, width, height); + else + e = vkengine_create (VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU, VK_PRESENT_MODE_MAILBOX_KHR, width, height); - device = vkvg_device_create_multisample(vkh_app_get_inst(e->app), r->dev->phy, r->dev->dev, r->qFam, 0, samples, deferredResolve); + 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); - vkvg_device_set_dpy(device, 96, 96); + bool deferredResolve = false; - surf = vkvg_surface_create(device, width, height); - - vkh_presenter_build_blit_cmd (r, vkvg_surface_get_vk_image(surf), width, height); -} -void run_test_func (void(*testfunc)(void),uint width, uint height) { - bool deferredResolve = false; - VkhPresenter r = e->renderer; + device = vkvg_device_create_multisample(vkh_app_get_inst(e->app), r->dev->phy, r->dev->dev, r->qFam, 0, samples, deferredResolve); - double start_time, stop_time, run_time, run_total, min_run_time = -1, max_run_time; - double run_time_values[iterations]; + vkvg_device_set_dpy(device, 96, 96); - int i = 0; + surf = vkvg_surface_create(device, width, height); - while (!vkengine_should_close (e) && i < iterations) { - glfwPollEvents(); - - start_time = get_tick(); - - if (!paused) - testfunc(); - - if (deferredResolve) - vkvg_multisample_surface_resolve(surf); - if (!vkh_presenter_draw (r)) - vkh_presenter_build_blit_cmd (r, vkvg_surface_get_vk_image(surf), width, height); - - vkDeviceWaitIdle(e->dev->dev); - - stop_time = get_tick(); - run_time = stop_time - start_time; - run_time_values[i] = run_time; - - if (min_run_time < 0) - min_run_time = run_time; - else - min_run_time = MIN(run_time, min_run_time); - max_run_time = MAX(run_time, max_run_time); - run_total += run_time; - i++; - } - - double avg_run_time = run_total / (double)i; - double med_run_time = median_run_time (run_time_values, i); - double standard_dev = standard_deviation (run_time_values, i, avg_run_time); - double avg_frames_per_second = (1.0 / avg_run_time); - avg_frames_per_second = (avg_frames_per_second<9999) ? avg_frames_per_second:9999; + vkh_presenter_build_blit_cmd (r, vkvg_surface_get_vk_image(surf), width, height); +} - printf ("size:%d iter:%d avgFps: %f avg: %4.2f%% med: %4.2f%% sd: %4.2f%% \n", test_size, i, avg_frames_per_second, avg_run_time, med_run_time, standard_dev); +// printf ("size:%d iter:%d avgFps: %f avg: %4.2f%% med: %4.2f%% sd: %4.2f%% \n", test_size, i, avg_frames_per_second, avg_run_time, med_run_time, standard_dev); -} void clear_test () { - vkDeviceWaitIdle(e->dev->dev); + vkDeviceWaitIdle(e->dev->dev); - vkvg_surface_destroy (surf); - vkvg_device_destroy (device); + vkvg_surface_destroy (surf); + vkvg_device_destroy (device); - vkengine_destroy (e); + vkengine_destroy (e); } #ifdef VKVG_TEST_DIRECT_DRAW VkvgSurface* surfaces; #endif -void perform_test (void(*testfunc)(void),uint width, uint height) { - e = vkengine_create (VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU, VK_PRESENT_MODE_MAILBOX_KHR, width, 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); +void perform_test (void(*testfunc)(void), const char *testName, int argc, char* argv[]) { + //init random gen + struct timeval currentTime; + gettimeofday(¤tTime, NULL); + srand((unsigned) currentTime.tv_usec); + + //dumpLayerExts(); + if (argc > 1) + iterations = atoi (argv[1]); + if (argc > 2) + test_size = atoi (argv[2]); + if (iterations == 0 || test_size == 0) { + printf("usage: test [iterations] [size]\n"); + return; + } - bool deferredResolve = false; + char* whoami; + (whoami = strrchr(argv[0], '/')) ? ++whoami : (whoami = argv[0]); - device = vkvg_device_create_multisample(vkh_app_get_inst(e->app), r->dev->phy, r->dev->dev, r->qFam, 0, samples, deferredResolve); + if (test_vsync) + e = vkengine_create (VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU, VK_PRESENT_MODE_FIFO_KHR, test_width, test_height); + else + e = vkengine_create (VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU, VK_PRESENT_MODE_MAILBOX_KHR, test_width, test_height); - vkvg_device_set_dpy(device, 96, 96); + 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_multisample(vkh_app_get_inst(e->app), r->dev->phy, r->dev->dev, r->qFam, 0, samples, deferredResolve); + + vkvg_device_set_dpy(device, 96, 96); #ifdef VKVG_TEST_DIRECT_DRAW - surfaces = (VkvgSurface*)malloc(r->imgCount * sizeof (VkvgSurface)); - for (uint i=0; i < r->imgCount;i++) - surfaces[i] = vkvg_surface_create_for_VkhImage (device, r->ScBuffers[i]); + surfaces = (VkvgSurface*)malloc(r->imgCount * sizeof (VkvgSurface)); + for (uint32_t i=0; i < r->imgCount;i++) + surfaces[i] = vkvg_surface_create_for_VkhImage (device, r->ScBuffers[i]); #else - surf = vkvg_surface_create(device, width, height); - vkh_presenter_build_blit_cmd (r, vkvg_surface_get_vk_image(surf), width, height); + 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); #endif - double start_time = 0, stop_time = 0, run_time = 0, run_total = 0, min_run_time = -1, max_run_time = 0; - double run_time_values[iterations]; + double start_time = 0.0, stop_time = 0.0, run_time = 0.0, run_total = 0.0, min_run_time = -1, max_run_time = 0.0; + double* run_time_values = (double*)malloc(iterations*sizeof(double)); - int i = 0; + uint32_t i = 0; - while (!vkengine_should_close (e) && i < iterations) { - glfwPollEvents(); + vkengine_set_title(e, testName); - start_time = get_tick(); + while (!vkengine_should_close (e) && i < iterations) { + glfwPollEvents(); + + start_time = get_tick(); #ifdef VKVG_TEST_DIRECT_DRAW - if (!vkh_presenter_acquireNextImage(r, NULL, NULL)) { - for (uint i=0; i < r->imgCount;i++) - vkvg_surface_destroy (surfaces[i]); + if (!vkh_presenter_acquireNextImage(r, NULL, NULL)) { + for (uint32_t i=0; i < r->imgCount;i++) + vkvg_surface_destroy (surfaces[i]); - vkh_presenter_create_swapchain (r); + vkh_presenter_create_swapchain (r); - for (uint i=0; i < r->imgCount;i++) - surfaces[i] = vkvg_surface_create_for_VkhImage (device, r->ScBuffers[i]); - }else{ - surf = surfaces[r->currentScBufferIndex]; + for (uint32_t i=0; i < r->imgCount;i++) + surfaces[i] = vkvg_surface_create_for_VkhImage (device, r->ScBuffers[i]); + }else{ + surf = surfaces[r->currentScBufferIndex]; - testfunc(); + testfunc(); - if (deferredResolve) - vkvg_multisample_surface_resolve(surf); + if (deferredResolve) + vkvg_multisample_surface_resolve(surf); - VkPresentInfoKHR present = { .sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, - .swapchainCount = 1, - .pSwapchains = &r->swapChain, - .pImageIndices = &r->currentScBufferIndex }; + VkPresentInfoKHR present = { .sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, + .swapchainCount = 1, + .pSwapchains = &r->swapChain, + .pImageIndices = &r->currentScBufferIndex }; - vkQueuePresentKHR(r->queue, &present); - } + vkQueuePresentKHR(r->queue, &present); + } #else - if (!paused) - testfunc(); + if (!paused) + testfunc(); - if (deferredResolve) - vkvg_multisample_surface_resolve(surf); - if (!vkh_presenter_draw (r)) - vkh_presenter_build_blit_cmd (r, vkvg_surface_get_vk_image(surf), width, height); + if (deferredResolve) + vkvg_multisample_surface_resolve(surf); + 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; + } #endif - vkDeviceWaitIdle(e->dev->dev); + if (paused) + continue; + + stop_time = get_tick(); + run_time = stop_time - start_time; + run_time_values[i] = run_time; - if (paused) - continue; + if (min_run_time < 0) + min_run_time = run_time; + else + min_run_time = MIN(run_time, min_run_time); + max_run_time = MAX(run_time, max_run_time); + run_total += run_time; + i++; + } - stop_time = get_tick(); - run_time = stop_time - start_time; - run_time_values[i] = run_time; + double avg_run_time = run_total / (double)i; + double med_run_time = median_run_time (run_time_values, i); + double standard_dev = standard_deviation (run_time_values, i, avg_run_time); + double avg_frames_per_second = (1.0 / avg_run_time); + avg_frames_per_second = (avg_frames_per_second<9999) ? avg_frames_per_second:9999; - if (min_run_time < 0) - min_run_time = run_time; - else - min_run_time = MIN(run_time, min_run_time); - max_run_time = MAX(run_time, max_run_time); - run_total += run_time; - i++; - } + free (run_time_values); - double avg_run_time = run_total / (double)i; - double med_run_time = median_run_time (run_time_values, i); - double standard_dev = standard_deviation (run_time_values, i, avg_run_time); - double avg_frames_per_second = (1.0 / avg_run_time); - avg_frames_per_second = (avg_frames_per_second<9999) ? avg_frames_per_second:9999; - printf ("size:%d iter:%d avgFps: %f avg: %4.2f%% med: %4.2f%% sd: %4.2f%% \n", test_size, i, avg_frames_per_second, avg_run_time, med_run_time, standard_dev); + //printf ("size:%d iter:%d avgFps: %f avg: %4.2f%% med: %4.2f%% sd: %4.2f%% \n", test_size, i, avg_frames_per_second, avg_run_time, med_run_time, standard_dev); + printf ("| %-15s | %-25s | ",whoami + 5, testName); + printf ("%4d | %4d | %7.2f | %6.5f | %6.5f | %6.5f |\n", + test_size, i, avg_frames_per_second, avg_run_time, med_run_time, standard_dev); - vkDeviceWaitIdle(e->dev->dev); + //printf ("%s size:%d iter:%d avgFps: %f avg: %4.2f%% med: %4.2f%% sd: %4.2f%% \n", whoami+5, test_size, i, avg_frames_per_second, avg_run_time, med_run_time, standard_dev); + + vkDeviceWaitIdle(e->dev->dev); #ifdef VKVG_TEST_DIRECT_DRAW - for (uint i=0; i<r->imgCount;i++) - vkvg_surface_destroy (surfaces[i]); + for (uint32_t i=0; i<r->imgCount;i++) + vkvg_surface_destroy (surfaces[i]); - free (surfaces); + free (surfaces); #else - vkvg_surface_destroy (surf); + vkvg_surface_destroy (surf); #endif - vkvg_device_destroy (device); + vkvg_device_destroy (device); + + vkengine_destroy (e); +} +const int star_points[11][2] = { + { 0, 85 }, + { 75, 75 }, + { 100, 10 }, + { 125, 75 }, + { 200, 85 }, + { 150, 125 }, + { 160, 190 }, + { 100, 150 }, + { 40, 190 }, + { 50, 125 }, + { 0, 85 } +}; + +void draw_random_shape (VkvgContext ctx, shape_t shape, float sizeFact) { + float w = (float)test_width; + float h = (float)test_height; + + float x, y, z, v, r; - vkengine_destroy (e); + randomize_color (ctx); + + switch (shape) { + case SHAPE_LINE: + x = (float)rand()/RAND_MAX * w; + y = (float)rand()/RAND_MAX * h; + z = (float)rand()/RAND_MAX * w; + v = (float)rand()/RAND_MAX * h; + + vkvg_move_to(ctx, x, y); + vkvg_line_to(ctx, z, v); + vkvg_stroke(ctx); + break; + case SHAPE_RECTANGLE: + z = truncf((sizeFact*w*rand()/RAND_MAX)+1.f); + v = truncf((sizeFact*h*rand()/RAND_MAX)+1.f); + x = truncf((w-z)*rand()/RAND_MAX); + y = truncf((h-v)*rand()/RAND_MAX); + + vkvg_rectangle(ctx, x+1, y+1, z, v); + break; + case SHAPE_ROUNDED_RECTANGLE: + z = truncf((sizeFact*w*rand()/RAND_MAX)+1.f); + v = truncf((sizeFact*h*rand()/RAND_MAX)+1.f); + x = truncf((w-z)*rand()/RAND_MAX); + y = truncf((h-v)*rand()/RAND_MAX); + r = truncf((0.2f*z*rand()/RAND_MAX)+1.f); + + if ((r > v / 2) || (r > z / 2)) + r = MIN(v / 2, z / 2); + + vkvg_move_to(ctx, x, y + r); + vkvg_arc(ctx, x + r, y + r, r, (float)M_PI, (float)-M_PI_2); + vkvg_line_to(ctx, x + z - r, y); + vkvg_arc(ctx, x + z - r, y + r, r, (float)-M_PI_2, 0); + vkvg_line_to(ctx, x + z, y + v - r); + vkvg_arc(ctx, x + z - r, y + v - r, r, 0, (float)M_PI_2); + vkvg_line_to(ctx, x + r, y + v); + vkvg_arc(ctx, x + r, y + v - r, r, (float)M_PI_2, (float)M_PI); + vkvg_line_to(ctx, x, y + r); + vkvg_close_path(ctx); + break; + case SHAPE_CIRCLE: + /*x = truncf((float)w * rnd()/RAND_MAX); + y = truncf((float)h * rnd()/RAND_MAX); + v = truncf((float)w * rnd()/RAND_MAX * 0.2f);*/ + x = (float)rand()/RAND_MAX * w; + y = (float)rand()/RAND_MAX * h; + + r = truncf((sizeFact*MIN(w,h)*rand()/RAND_MAX)+1.f); + + /*float r = 0.5f*w*rand()/RAND_MAX; + float x = truncf(0.5f * w*rand()/RAND_MAX + r); + float y = truncf(0.5f * w*rand()/RAND_MAX + r);*/ + + vkvg_arc(ctx, x, y, r, 0, (float)M_PI * 2.0f); + break; + case SHAPE_TRIANGLE: + case SHAPE_STAR: + x = (float)rand()/RAND_MAX * w; + y = (float)rand()/RAND_MAX * h; + z = (float)rand()/RAND_MAX * sizeFact + 0.15f; //scale + + vkvg_move_to (ctx, x+star_points[0][0]*z, y+star_points[0][1]*z); + for (int s=1; s<11; s++) + vkvg_line_to (ctx, x+star_points[s][0]*z, y+star_points[s][1]*z); + vkvg_close_path (ctx); + break; + case SHAPE_RANDOM: + draw_random_shape(ctx, 1 + rand()%4, sizeFact); + break; + } } + +/*void draw_random_shape (VkvgContext ctx, shape_t shape) { + float w = (float)test_width; + float h = (float)test_height; + randomize_color(ctx); + float z = truncf((0.5f*w*rand()/RAND_MAX)+1.f); + float v = truncf((0.5f*w*rand()/RAND_MAX)+1.f); + float x = truncf((w-z)*rand()/RAND_MAX); + float y = truncf((h-v)*rand()/RAND_MAX); + vkvg_rectangle(ctx, x, y, z, v); +}*/ diff --git a/tests/common/test.h b/tests/common/test.h index f916c45..91b6393 100644 --- a/tests/common/test.h +++ b/tests/common/test.h @@ -1,7 +1,10 @@ #include "vkengine.h" -#include "stdio.h" -#include "stdlib.h" -#include "time.h" +#include <stdio.h> +#include <stdlib.h> +#define _USE_MATH_DEFINES +#include <math.h> +#include <time.h> + #include "vkvg.h" #include "vkh_device.h" @@ -18,64 +21,59 @@ # define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif -#ifdef _WIN32 // MSC_VER - #define WIN32_LEAN_AND_MEAN - #define NOMINMAX - #include <Windows.h> // Windows.h -> WinDef.h defines min() max() - - /* - typedef uint16_t WORD ; - typedef uint32_t DWORD; - - typedef struct _FILETIME { - DWORD dwLowDateTime; - DWORD dwHighDateTime; - } FILETIME; - - typedef struct _SYSTEMTIME { - WORD wYear; - WORD wMonth; - WORD wDayOfWeek; - WORD wDay; - WORD wHour; - WORD wMinute; - WORD wSecond; - WORD wMilliseconds; - } SYSTEMTIME, *PSYSTEMTIME; - */ +#define PERFORM_TEST(testName, argc, argv) perform_test(testName, #testName, argc, argv); +#if defined(_WIN32) || defined(_WIN64) + #define WIN32_LEAN_AND_MEAN + #define NOMINMAX + #include <Windows.h> // Windows.h -> WinDef.h defines min() max() - // *sigh* Microsoft has this in winsock2.h because they are too lazy to put it in the standard location ... !?!? - typedef struct timeval { - long tv_sec; - long tv_usec; - } timeval; + /* + typedef uint16_t WORD ; + typedef uint32_t DWORD; - // *sigh* no gettimeofday on Win32/Win64 - int gettimeofday(struct timeval * tp, struct timezone * tzp) - { - // FILETIME Jan 1 1970 00:00:00 - // Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's - static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL); + typedef struct _FILETIME { + DWORD dwLowDateTime; + DWORD dwHighDateTime; + } FILETIME; - SYSTEMTIME nSystemTime; - FILETIME nFileTime; - uint64_t nTime; + typedef struct _SYSTEMTIME { + WORD wYear; + WORD wMonth; + WORD wDayOfWeek; + WORD wDay; + WORD wHour; + WORD wMinute; + WORD wSecond; + WORD wMilliseconds; + } SYSTEMTIME, *PSYSTEMTIME; + */ - GetSystemTime( &nSystemTime ); - SystemTimeToFileTime( &nSystemTime, &nFileTime ); - nTime = ((uint64_t)nFileTime.dwLowDateTime ) ; - nTime += ((uint64_t)nFileTime.dwHighDateTime) << 32; + // *sigh* Microsoft has this in winsock2.h because they are too lazy to put it in the standard location ... !?!? + typedef struct timeval { + long tv_sec; + long tv_usec; + } timeval; - tp->tv_sec = (long) ((nTime - EPOCH) / 10000000L); - tp->tv_usec = (long) (nSystemTime.wMilliseconds * 1000); - return 0; - } + // *sigh* no gettimeofday on Win32/Win64 + int gettimeofday(struct timeval * tp, void * tzp); #else - #include <sys/time.h> -#endif // _WIN32 + #include <sys/time.h> +#endif + +typedef enum _shape_t { + SHAPE_LINE, + SHAPE_RECTANGLE, + SHAPE_ROUNDED_RECTANGLE, + SHAPE_CIRCLE, + SHAPE_TRIANGLE, + SHAPE_STAR, + SHAPE_RANDOM, +} shape_t; -extern uint test_size; -extern int iterations; +extern uint32_t test_size; +extern uint32_t iterations; +extern uint32_t test_width; +extern uint32_t test_height; extern float panX; extern float panY; @@ -88,10 +86,11 @@ extern VkvgDevice device; extern VkvgSurface surf; //run test in one step -void perform_test (void(*testfunc)(void),uint width, uint height); -void randomize_color (VkvgContext ctx); +void perform_test (void(*testfunc)(), const char* testName, int argc, char *argv[]); + +void randomize_color (VkvgContext ctx); +void draw_random_shape (VkvgContext ctx, shape_t shape, float sizeFact); //run test in 3 step: init, run, clear. -void init_test (uint width, uint height); -void run_test_func (void(*testfunc)(void),uint width, uint height); +void init_test (uint32_t width, uint32_t height); void clear_test (); diff --git a/tests/common/vkengine.c b/tests/common/vkengine.c index 6e8157e..9aac16b 100644 --- a/tests/common/vkengine.c +++ b/tests/common/vkengine.c @@ -29,261 +29,234 @@ #include "vkh_device.h" bool vkeCheckPhyPropBlitSource (VkEngine e) { - VkFormatProperties formatProps; - vkGetPhysicalDeviceFormatProperties(e->dev->phy, e->renderer->format, &formatProps); - + VkFormatProperties formatProps; + vkGetPhysicalDeviceFormatProperties(e->dev->phy, e->renderer->format, &formatProps); #ifdef VKVG_TILING_OPTIMAL - assert((formatProps.optimalTilingFeatures & VK_FORMAT_FEATURE_BLIT_SRC_BIT) && "Format cannot be used as transfer source"); + return formatProps.optimalTilingFeatures & VK_FORMAT_FEATURE_BLIT_SRC_BIT; #else - assert((formatProps.linearTilingFeatures & VK_FORMAT_FEATURE_BLIT_SRC_BIT) && "Format cannot be used as transfer source"); + return formatProps.linearTilingFeatures & VK_FORMAT_FEATURE_BLIT_SRC_BIT; #endif } VkSampleCountFlagBits getMaxUsableSampleCount(VkSampleCountFlags counts) { - if (counts & VK_SAMPLE_COUNT_64_BIT) { return VK_SAMPLE_COUNT_64_BIT; } - if (counts & VK_SAMPLE_COUNT_32_BIT) { return VK_SAMPLE_COUNT_32_BIT; } - if (counts & VK_SAMPLE_COUNT_16_BIT) { return VK_SAMPLE_COUNT_16_BIT; } - if (counts & VK_SAMPLE_COUNT_8_BIT) { return VK_SAMPLE_COUNT_8_BIT; } - if (counts & VK_SAMPLE_COUNT_4_BIT) { return VK_SAMPLE_COUNT_4_BIT; } - if (counts & VK_SAMPLE_COUNT_2_BIT) { return VK_SAMPLE_COUNT_2_BIT; } - return VK_SAMPLE_COUNT_1_BIT; + if (counts & VK_SAMPLE_COUNT_64_BIT) { return VK_SAMPLE_COUNT_64_BIT; } + if (counts & VK_SAMPLE_COUNT_32_BIT) { return VK_SAMPLE_COUNT_32_BIT; } + if (counts & VK_SAMPLE_COUNT_16_BIT) { return VK_SAMPLE_COUNT_16_BIT; } + if (counts & VK_SAMPLE_COUNT_8_BIT) { return VK_SAMPLE_COUNT_8_BIT; } + if (counts & VK_SAMPLE_COUNT_4_BIT) { return VK_SAMPLE_COUNT_4_BIT; } + if (counts & VK_SAMPLE_COUNT_2_BIT) { return VK_SAMPLE_COUNT_2_BIT; } + return VK_SAMPLE_COUNT_1_BIT; } void vkengine_dump_Infos (VkEngine e){ - printf("max samples = %d\n", getMaxUsableSampleCount(e->gpu_props.limits.framebufferColorSampleCounts)); - printf("max tex2d size = %d\n", e->gpu_props.limits.maxImageDimension2D); - printf("max tex array layers = %d\n", e->gpu_props.limits.maxImageArrayLayers); - printf("max mem alloc count = %d\n", e->gpu_props.limits.maxMemoryAllocationCount); + printf("max samples = %d\n", getMaxUsableSampleCount(e->gpu_props.limits.framebufferColorSampleCounts)); + printf("max tex2d size = %d\n", e->gpu_props.limits.maxImageDimension2D); + printf("max tex array layers = %d\n", e->gpu_props.limits.maxImageArrayLayers); + printf("max mem alloc count = %d\n", e->gpu_props.limits.maxMemoryAllocationCount); - for (uint32_t i = 0; i < e->memory_properties.memoryHeapCount; i++) { - printf("Mem Heap %d\n", i); - printf("\tflags= %d\n", e->memory_properties.memoryHeaps[i].flags); - printf("\tsize = %lu Mo\n", e->memory_properties.memoryHeaps[i].size/ (uint32_t)(1024*1024)); - } - for (uint32_t i = 0; i < e->memory_properties.memoryTypeCount; i++) { - printf("Mem type %d\n", i); - printf("\theap %d: ", e->memory_properties.memoryTypes[i].heapIndex); - if (e->memory_properties.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) - printf("VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT|"); - if (e->memory_properties.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) - printf("VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT|"); - if (e->memory_properties.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) - printf("VK_MEMORY_PROPERTY_HOST_COHERENT_BIT|"); - if (e->memory_properties.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) - printf("VK_MEMORY_PROPERTY_HOST_CACHED_BIT|"); - if (e->memory_properties.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) - printf("VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT|"); - printf("\n"); - } + for (uint32_t i = 0; i < e->memory_properties.memoryHeapCount; i++) { + printf("Mem Heap %d\n", i); + printf("\tflags= %d\n", e->memory_properties.memoryHeaps[i].flags); + printf("\tsize = %lu Mo\n", (unsigned long)e->memory_properties.memoryHeaps[i].size/ (uint32_t)(1024*1024)); + } + for (uint32_t i = 0; i < e->memory_properties.memoryTypeCount; i++) { + printf("Mem type %d\n", i); + printf("\theap %d: ", e->memory_properties.memoryTypes[i].heapIndex); + if (e->memory_properties.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) + printf("VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT|"); + if (e->memory_properties.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) + printf("VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT|"); + if (e->memory_properties.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) + printf("VK_MEMORY_PROPERTY_HOST_COHERENT_BIT|"); + if (e->memory_properties.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) + printf("VK_MEMORY_PROPERTY_HOST_CACHED_BIT|"); + if (e->memory_properties.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) + printf("VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT|"); + printf("\n"); + } } void vkengine_dump_available_layers () { - uint32_t layerCount; - vkEnumerateInstanceLayerProperties(&layerCount, NULL); + uint32_t layerCount; + vkEnumerateInstanceLayerProperties(&layerCount, NULL); - VkLayerProperties availableLayers [layerCount]; - vkEnumerateInstanceLayerProperties(&layerCount, availableLayers); + VkLayerProperties* availableLayers = (VkLayerProperties*)malloc(layerCount*sizeof(VkLayerProperties)); + vkEnumerateInstanceLayerProperties(&layerCount, availableLayers); - printf("Available Layers:\n"); - printf("-----------------\n"); - for (uint i=0; i<layerCount; i++) { - printf ("\t - %s\n", availableLayers[i].layerName); - } - printf("-----------------\n\n"); + printf("Available Layers:\n"); + printf("-----------------\n"); + for (uint32_t i=0; i<layerCount; i++) { + printf ("\t - %s\n", availableLayers[i].layerName); + } + printf("-----------------\n\n"); + free (availableLayers); } vk_engine_t* vkengine_create (VkPhysicalDeviceType preferedGPU, VkPresentModeKHR presentMode, uint32_t width, uint32_t height) { - vk_engine_t* e = (vk_engine_t*)calloc(1,sizeof(vk_engine_t)); + vk_engine_t* e = (vk_engine_t*)calloc(1,sizeof(vk_engine_t)); - glfwInit(); - assert (glfwVulkanSupported()==GLFW_TRUE); + glfwInit(); + assert (glfwVulkanSupported()==GLFW_TRUE); - uint32_t enabledExtsCount = 0, phyCount = 0; - const char** gflwExts = glfwGetRequiredInstanceExtensions (&enabledExtsCount); + uint32_t enabledExtsCount = 0, phyCount = 0; + const char** gflwExts = glfwGetRequiredInstanceExtensions (&enabledExtsCount); - const char* enabledExts [enabledExtsCount+1]; + const char* enabledExts [10]; - for (uint i=0;i<enabledExtsCount;i++) - enabledExts[i] = gflwExts[i]; + for (uint32_t i=0;i<enabledExtsCount;i++) + enabledExts[i] = gflwExts[i]; #ifdef VKVG_USE_RENDERDOC - const uint32_t enabledLayersCount = 2; - const char* enabledLayers[] = {"VK_LAYER_KHRONOS_validation", "VK_LAYER_RENDERDOC_Capture"}; + const uint32_t enabledLayersCount = 2; + const char* enabledLayers[] = {"VK_LAYER_KHRONOS_validation", "VK_LAYER_RENDERDOC_Capture"}; #elif defined (VKVG_USE_VALIDATION) - const uint32_t enabledLayersCount = 1; - const char* enabledLayers[] = {"VK_LAYER_KHRONOS_validation"}; + const uint32_t enabledLayersCount = 1; + const char* enabledLayers[] = {"VK_LAYER_KHRONOS_validation"}; #else - const uint32_t enabledLayersCount = 0; - const char* enabledLayers[] = {NULL}; + const uint32_t enabledLayersCount = 0; + const char* enabledLayers[] = {NULL}; #endif #ifdef DEBUG - enabledExts[enabledExtsCount] = "VK_EXT_debug_utils"; - enabledExtsCount++; + enabledExts[enabledExtsCount] = "VK_EXT_debug_utils"; + enabledExtsCount++; #endif - e->app = vkh_app_create("vkvgTest", enabledLayersCount, enabledLayers, enabledExtsCount, enabledExts); + e->app = vkh_app_create("vkvgTest", enabledLayersCount, enabledLayers, enabledExtsCount, enabledExts); #ifdef DEBUG - vkh_app_enable_debug_messenger(e->app - , VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT - | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT - | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT - , VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT - | VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT - //| VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT - //| VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT - , NULL); + vkh_app_enable_debug_messenger(e->app + , VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT + | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT + | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT + , VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT + | VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT + //| VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT + //| VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT + , NULL); #endif - glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); - glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); - glfwWindowHint(GLFW_FLOATING, GLFW_FALSE); - glfwWindowHint(GLFW_DECORATED, GLFW_TRUE); - - e->window = glfwCreateWindow ((int)width, (int)height, "Window Title", NULL, NULL); + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); + glfwWindowHint(GLFW_FLOATING, GLFW_FALSE); + glfwWindowHint(GLFW_DECORATED, GLFW_TRUE); - VkSurfaceKHR surf; - VkResult res = glfwCreateWindowSurface(e->app->inst, e->window, NULL, &surf); + e->window = glfwCreateWindow ((int)width, (int)height, "Window Title", NULL, NULL); - VkhPhyInfo* phys = vkh_app_get_phyinfos (e->app, &phyCount, surf); + VkSurfaceKHR surf; + VK_CHECK_RESULT (glfwCreateWindowSurface(e->app->inst, e->window, NULL, &surf)) - VkhPhyInfo pi = NULL; - for (int i=0; i<phyCount; i++){ - pi = phys[i]; - if (pi->properties.deviceType == preferedGPU) - break; - } + VkhPhyInfo* phys = vkh_app_get_phyinfos (e->app, &phyCount, surf); - e->memory_properties = pi->memProps; - e->gpu_props = pi->properties; + VkhPhyInfo pi = 0; + for (uint32_t i=0; i<phyCount; i++){ + pi = phys[i]; + if (pi->properties.deviceType == preferedGPU) + break; + } - uint32_t qCount = 0; - VkDeviceQueueCreateInfo pQueueInfos[3]; - float queue_priorities[] = {0.0}; + e->memory_properties = pi->memProps; + e->gpu_props = pi->properties; - VkDeviceQueueCreateInfo qiG = { .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, - .queueCount = 1, - .queueFamilyIndex = pi->gQueue, - .pQueuePriorities = queue_priorities }; - VkDeviceQueueCreateInfo qiC = { .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, - .queueCount = 1, - .queueFamilyIndex = pi->cQueue, - .pQueuePriorities = queue_priorities }; - VkDeviceQueueCreateInfo qiT = { .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, - .queueCount = 1, - .queueFamilyIndex = pi->tQueue, - .pQueuePriorities = queue_priorities }; + uint32_t qCount = 0; + float qPriorities[] = {0.0}; - if (pi->gQueue == pi->cQueue){ - if(pi->gQueue == pi->tQueue){ - qCount=1; - pQueueInfos[0] = qiG; - }else{ - qCount=2; - pQueueInfos[0] = qiG; - pQueueInfos[1] = qiT; - } - }else{ - if((pi->gQueue == pi->tQueue) || (pi->cQueue==pi->tQueue)){ - qCount=2; - pQueueInfos[0] = qiG; - pQueueInfos[1] = qiC; - }else{ - qCount=3; - pQueueInfos[0] = qiG; - pQueueInfos[1] = qiC; - pQueueInfos[2] = qiT; - } - } + VkDeviceQueueCreateInfo pQueueInfos[] = { {0},{0},{0} }; + if (vkh_phyinfo_create_presentable_queues (pi, 1, qPriorities, &pQueueInfos[qCount])) + qCount++; + /*if (vkh_phyinfo_create_compute_queues (pi, 1, qPriorities, &pQueueInfos[qCount])) + qCount++; + if (vkh_phyinfo_create_transfer_queues (pi, 1, qPriorities, &pQueueInfos[qCount])) + qCount++;*/ - char const * dex [] = {"VK_KHR_swapchain", "VK_KHR_push_descriptor"}; - enabledExtsCount = 2; + char const * dex [] = {"VK_KHR_swapchain", "VK_KHR_push_descriptor"}; + enabledExtsCount = 2; - VkPhysicalDeviceFeatures enabledFeatures = { - .fillModeNonSolid = true, - //.sampleRateShading = true - }; + VkPhysicalDeviceFeatures enabledFeatures = { + .fillModeNonSolid = true, + //.sampleRateShading = true + }; - VkDeviceCreateInfo device_info = { .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, - .queueCreateInfoCount = qCount, - .pQueueCreateInfos = (VkDeviceQueueCreateInfo*)&pQueueInfos, - .enabledExtensionCount = enabledExtsCount, - .ppEnabledExtensionNames = dex, - .pEnabledFeatures = &enabledFeatures - }; + VkDeviceCreateInfo device_info = { .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, + .queueCreateInfoCount = qCount, + .pQueueCreateInfos = (VkDeviceQueueCreateInfo*)&pQueueInfos, + .enabledExtensionCount = enabledExtsCount, + .ppEnabledExtensionNames = dex, + .pEnabledFeatures = &enabledFeatures}; - e->dev = vkh_device_create(e->app, pi, &device_info); + e->dev = vkh_device_create(e->app, pi, &device_info); - e->renderer = vkh_presenter_create - (e->dev, (uint32_t) pi->pQueue, surf, width, height, VK_FORMAT_B8G8R8A8_UNORM, presentMode); + e->renderer = vkh_presenter_create + (e->dev, (uint32_t) pi->pQueue, surf, width, height, VK_FORMAT_B8G8R8A8_UNORM, presentMode); - vkh_app_free_phyinfos (phyCount, phys); + vkh_app_free_phyinfos (phyCount, phys); - vkeCheckPhyPropBlitSource (e); + vkeCheckPhyPropBlitSource (e); - return e; + return e; } void vkengine_destroy (VkEngine e) { - vkDeviceWaitIdle(e->dev->dev); + vkDeviceWaitIdle(e->dev->dev); - VkSurfaceKHR surf = e->renderer->surface; + VkSurfaceKHR surf = e->renderer->surface; - vkh_presenter_destroy (e->renderer); - vkDestroySurfaceKHR (e->app->inst, surf, NULL); + vkh_presenter_destroy (e->renderer); + vkDestroySurfaceKHR (e->app->inst, surf, NULL); - vkh_device_destroy (e->dev); + vkh_device_destroy (e->dev); - glfwDestroyWindow (e->window); - glfwTerminate (); + glfwDestroyWindow (e->window); + glfwTerminate (); - vkh_app_destroy (e->app); + vkh_app_destroy (e->app); - free(e); + free(e); } void vkengine_close (VkEngine e) { - glfwSetWindowShouldClose(e->window, GLFW_TRUE); + glfwSetWindowShouldClose(e->window, GLFW_TRUE); } void vkengine_blitter_run (VkEngine e, VkImage img, uint32_t width, uint32_t height) { - VkhPresenter p = e->renderer; - vkh_presenter_build_blit_cmd (p, img, width, height); + VkhPresenter p = e->renderer; + vkh_presenter_build_blit_cmd (p, img, width, height); - while (!vkengine_should_close (e)) { - glfwPollEvents(); - if (!vkh_presenter_draw (p)) - vkh_presenter_build_blit_cmd (p, img, width, height); - } + while (!vkengine_should_close (e)) { + glfwPollEvents(); + if (!vkh_presenter_draw (p)) + vkh_presenter_build_blit_cmd (p, img, width, height); + } } -inline bool vkengine_should_close (VkEngine e) { - return glfwWindowShouldClose (e->window); +bool vkengine_should_close (VkEngine e) { + return glfwWindowShouldClose (e->window); +} +void vkengine_set_title (VkEngine e, const char* title) { + glfwSetWindowTitle(e->window, title); } - VkDevice vkengine_get_device (VkEngine e){ - return e->dev->dev; + return e->dev->dev; } VkPhysicalDevice vkengine_get_physical_device (VkEngine e){ - return e->dev->phy; + return e->dev->phy; } VkQueue vkengine_get_queue (VkEngine e){ - return e->renderer->queue; + return e->renderer->queue; } uint32_t vkengine_get_queue_fam_idx (VkEngine e){ - return e->renderer->qFam; + return e->renderer->qFam; } void vkengine_set_key_callback (VkEngine e, GLFWkeyfun key_callback){ - glfwSetKeyCallback (e->window, key_callback); + glfwSetKeyCallback (e->window, key_callback); } void vkengine_set_mouse_but_callback (VkEngine e, GLFWmousebuttonfun onMouseBut){ - glfwSetMouseButtonCallback(e->window, onMouseBut); + glfwSetMouseButtonCallback(e->window, onMouseBut); } void vkengine_set_cursor_pos_callback (VkEngine e, GLFWcursorposfun onMouseMove){ - glfwSetCursorPosCallback(e->window, onMouseMove); + glfwSetCursorPosCallback(e->window, onMouseMove); } void vkengine_set_scroll_callback (VkEngine e, GLFWscrollfun onScroll){ - glfwSetScrollCallback(e->window, onScroll); + glfwSetScrollCallback(e->window, onScroll); } void vkengine_set_char_callback (VkEngine e, GLFWcharfun onChar){ - glfwSetCharCallback(e->window, onChar); + glfwSetCharCallback(e->window, onChar); } diff --git a/tests/common/vkengine.h b/tests/common/vkengine.h index 056be08..7c4e229 100644 --- a/tests/common/vkengine.h +++ b/tests/common/vkengine.h @@ -28,10 +28,13 @@ #include <stdbool.h> #include <GLFW/glfw3.h> +#undef APIENTRY + #include <vulkan/vulkan.h> #include "vkh.h" + #define FENCE_TIMEOUT 100000000 typedef struct _vk_engine_t* VkEngine; @@ -51,6 +54,7 @@ void vkengine_destroy (VkEngine e); bool vkengine_should_close (VkEngine e); void vkengine_close (VkEngine e); void vkengine_dump_Infos (VkEngine e); +void vkengine_set_title (VkEngine e, const char* title); VkDevice vkengine_get_device (VkEngine e); VkPhysicalDevice vkengine_get_physical_device(VkEngine e); VkQueue vkengine_get_queue (VkEngine e); diff --git a/tests/compositing.c b/tests/compositing.c index 56e3d45..df193a7 100644 --- a/tests/compositing.c +++ b/tests/compositing.c @@ -1,24 +1,22 @@ #include "test.h" -void test(){ - vkvg_surface_clear(surf); +void compositing(){ + vkvg_surface_clear(surf); - VkvgContext ctx = vkvg_create(surf); + VkvgContext ctx = vkvg_create(surf); - vkvg_set_source_rgba(ctx, 1,0,0,0.5); - vkvg_rectangle(ctx,100,100,200,200); - vkvg_fill(ctx); + vkvg_set_source_rgba(ctx, 1,0,0,0.5f); + vkvg_rectangle(ctx,100,100,200,200); + vkvg_fill(ctx); - vkvg_set_source_rgba(ctx, 0,0,1,0.5); - vkvg_rectangle(ctx,200,200,200,200); - vkvg_fill(ctx); + vkvg_set_source_rgba(ctx, 0,0,1,0.5f); + vkvg_rectangle(ctx,200,200,200,200); + vkvg_fill(ctx); - vkvg_destroy(ctx); + vkvg_destroy(ctx); } int main(int argc, char *argv[]) { - - perform_test (test, 600, 800); - - return 0; + PERFORM_TEST (compositing, argc, argv); + return 0; } diff --git a/tests/curve.c b/tests/curve.c index dd3d4b5..8ff7cad 100644 --- a/tests/curve.c +++ b/tests/curve.c @@ -1,62 +1,114 @@ #include "test.h" void test(){ - VkvgContext ctx = vkvg_create(surf); + VkvgContext ctx = vkvg_create(surf); - vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_NON_ZERO); - vkvg_set_line_width(ctx, 20); + vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_NON_ZERO); + vkvg_set_line_width(ctx, 20); - vkvg_scale(ctx,2,2); - vkvg_set_line_join(ctx, VKVG_LINE_JOIN_BEVEL); + //vkvg_scale(ctx,2,2); + vkvg_set_line_join(ctx, VKVG_LINE_JOIN_BEVEL); - //vkvg_arc (ctx, 200, 500, 100, 0, M_PI); + //vkvg_arc (ctx, 200, 500, 100, 0, M_PI); - vkvg_set_source_rgb (ctx, 0.5,0,0); + vkvg_set_source_rgb (ctx, 0.5f,0,0); - /*vkvg_move_to(ctx,100,100); - vkvg_line_to(ctx,300,100); - vkvg_line_to(ctx,500,300); - vkvg_line_to(ctx,300,500); - //vkvg_arc (ctx, 200, 500, 100, 0, M_PI); - vkvg_line_to(ctx,300,700); - vkvg_line_to(ctx,100,500);*/ + /*vkvg_move_to(ctx,100,100); + vkvg_line_to(ctx,300,100); + vkvg_line_to(ctx,500,300); + vkvg_line_to(ctx,300,500); + //vkvg_arc (ctx, 200, 500, 100, 0, M_PI); + vkvg_line_to(ctx,300,700); + vkvg_line_to(ctx,100,500);*/ - /*vkvg_arc(ctx, 300, 300, 100, 0, M_PI); - vkvg_line_to(ctx,100,200); - vkvg_line_to(ctx,200,100); - vkvg_arc(ctx, 250, 100, 50, M_PI, M_PI * 1.5f); - vkvg_line_to(ctx,350,50); - vkvg_arc(ctx, 350, 100, 50, M_PI*1.5f, M_PI * 2.0f); + /*vkvg_arc(ctx, 300, 300, 100, 0, M_PI); + vkvg_line_to(ctx,100,200); + vkvg_line_to(ctx,200,100); + vkvg_arc(ctx, 250, 100, 50, M_PI, M_PI * 1.5f); + vkvg_line_to(ctx,350,50); + vkvg_arc(ctx, 350, 100, 50, M_PI*1.5f, M_PI * 2.0f); - vkvg_stroke(ctx); - vkvg_translate(ctx,400,30); + vkvg_stroke(ctx); + vkvg_translate(ctx,400,30); - */ - vkvg_translate(ctx,200,30); - vkvg_arc(ctx, 200, 200, 20, 0, M_PI*2); - //vkvg_stroke(ctx); + */ + vkvg_translate(ctx,200,30); + vkvg_arc(ctx, 200, 200, 20, 0, M_PIF*2); + vkvg_stroke(ctx); - vkvg_set_source_rgba (ctx, 0.5,0.0,1.0,0.5); - vkvg_move_to(ctx,200,100); - vkvg_curve_to(ctx,250,100,300,150,300,200); - vkvg_line_to(ctx,300,300); - vkvg_curve_to(ctx,300,350,250,400,200,400); - vkvg_line_to(ctx,100,400); - vkvg_curve_to(ctx,50,400,10,350,10,300); - vkvg_line_to(ctx,10,200); - vkvg_curve_to(ctx,10,150,50,100,100,100); - vkvg_fill_preserve(ctx); - vkvg_set_source_rgba (ctx, 0.1f,0.3,0.7,0.5); - vkvg_stroke(ctx); + vkvg_set_source_rgba (ctx, 0.5f,0.0f,1.0f,0.5f); + vkvg_move_to(ctx,100,100); + vkvg_line_to(ctx,200,100); + vkvg_curve_to(ctx,250,100,300,150,300,200); + vkvg_line_to(ctx,300,300); + vkvg_curve_to(ctx,300,350,250,400,200,400); + vkvg_line_to(ctx,100,400); + vkvg_curve_to(ctx,50,400,10,350,10,300); + vkvg_line_to(ctx,10,200); + vkvg_curve_to(ctx,10,150,50,100,100,100); + //vkvg_close_path(ctx); + vkvg_fill_preserve(ctx); + vkvg_set_source_rgba (ctx, 0.1f,0.3f,0.7f,0.5f); + vkvg_stroke(ctx); - vkvg_destroy(ctx); + vkvg_destroy(ctx); } -int main(int argc, char *argv[]) { +void curved_rect() { + VkvgContext ctx = vkvg_create(surf); + + float x = 50, y = 50, width = 150, height = 140, radius = 30; + + vkvg_scale(ctx, 2, 2); + //vkvg_rotate(ctx,0.5f); + + vkvg_set_line_width(ctx, 15); + vkvg_set_source_rgba(ctx, 0, 0.5f, 0.4f, 1); + + + if ((radius > height / 2) || (radius > width / 2)) + radius = MIN(height / 2, width / 2); + + vkvg_move_to(ctx, x, y + radius); + vkvg_arc(ctx, x + radius, y + radius, radius, M_PIF, (float)-M_PI_2); + vkvg_line_to(ctx, x + width - radius, y); + vkvg_arc(ctx, x + width - radius, y + radius, radius, (float)-M_PI_2, 0); + vkvg_line_to(ctx, x + width, y + height - radius); + vkvg_arc(ctx, x + width - radius, y + height - radius, radius, 0, (float)M_PI_2); + vkvg_line_to(ctx, x + radius, y + height); + vkvg_arc(ctx, x + radius, y + height - radius, radius, (float)M_PI_2, M_PIF); + vkvg_line_to(ctx, x, y + radius); + vkvg_close_path(ctx); + vkvg_fill_preserve(ctx); + vkvg_set_source_rgba(ctx, 0.5f, 0, 0, 0.5f); + vkvg_stroke(ctx); - perform_test (test, 1024, 768); + vkvg_destroy(ctx); +} + +void test2() { + VkvgContext ctx = vkvg_create(surf); + + vkvg_move_to(ctx, 100, 400); + vkvg_curve_to(ctx, 100, 100, 600, 700, 600, 400); + vkvg_curve_to(ctx, 1000, 100, 100, 800, 1000, 800); + vkvg_curve_to(ctx, 1000, 500, 700, 500, 700, 100); + vkvg_close_path(ctx); + + //vkvg_set_source_rgba (ctx, 0.5,0.0,1.0,0.5); + //vkvg_fill_preserve(ctx); - return 0; + vkvg_set_source_rgba(ctx, 1, 0, 0, 1); + vkvg_set_line_width(ctx, 40); + vkvg_stroke(ctx); + + vkvg_destroy(ctx); +} +int main(int argc, char *argv[]) { + PERFORM_TEST(test, argc, argv); + PERFORM_TEST(test2, argc, argv); + PERFORM_TEST(curved_rect, argc, argv); + return 0; } diff --git a/tests/curve2.c b/tests/curve2.c deleted file mode 100644 index 76a115d..0000000 --- a/tests/curve2.c +++ /dev/null @@ -1,29 +0,0 @@ -#include "test.h" - -void test(){ - VkvgContext ctx = vkvg_create(surf); - - vkvg_move_to (ctx, 100, 400); - vkvg_curve_to (ctx, 100, 100, 600,700,600,400); - vkvg_curve_to (ctx, 1000, 100, 100, 800, 1000, 800); - vkvg_curve_to (ctx, 1000, 500, 700, 500, 700, 100); - vkvg_close_path(ctx); - - //vkvg_set_source_rgba (ctx, 0.5,0.0,1.0,0.5); - //vkvg_fill_preserve(ctx); - - vkvg_set_source_rgba (ctx, 1,0,0,1); - vkvg_set_line_width(ctx, 40); - vkvg_stroke_preserve(ctx); - vkvg_set_source_rgba (ctx, 1,1,0,1); - vkvg_fill(ctx); - - vkvg_destroy(ctx); -} - -int main(int argc, char *argv[]) { - - perform_test (test, 1024, 768); - - return 0; -} diff --git a/tests/curved_rect.c b/tests/curved_rect.c deleted file mode 100644 index 34e739f..0000000 --- a/tests/curved_rect.c +++ /dev/null @@ -1,40 +0,0 @@ -#include "test.h" - -void test(){ - VkvgContext ctx = vkvg_create(surf); - - float x = 50, y = 50, width = 150, height = 140, radius = 30; - - vkvg_scale(ctx,2,2); - //vkvg_rotate(ctx,0.5f); - - vkvg_set_line_width(ctx,15); - vkvg_set_source_rgba(ctx, 0, 0.5f, 0.4f, 1); - - - if ((radius > height / 2) || (radius > width / 2)) - radius = MIN(height / 2, width / 2); - - vkvg_move_to(ctx, x, y + radius); - vkvg_arc(ctx, x + radius, y + radius, radius, M_PIF, (float)-M_PI_2); - vkvg_line_to(ctx, x + width - radius, y); - vkvg_arc(ctx, x + width - radius, y + radius, radius, (float)-M_PI_2, 0); - vkvg_line_to(ctx, x + width, y + height - radius); - vkvg_arc(ctx, x + width - radius, y + height - radius, radius, 0, (float)M_PI_2); - vkvg_line_to(ctx, x + radius, y + height); - vkvg_arc(ctx, x + radius, y + height - radius, radius, (float)M_PI_2, M_PIF); - vkvg_line_to(ctx, x, y + radius); - vkvg_close_path(ctx); - vkvg_fill_preserve(ctx); - vkvg_set_source_rgba(ctx,0.5,0,0,0.5); - vkvg_stroke(ctx); - - vkvg_destroy(ctx); -} - -int main(int argc, char *argv[]) { - - perform_test (test, 1024, 768); - - return 0; -} diff --git a/tests/fill.c b/tests/fill.c index 612afc5..5d49946 100644 --- a/tests/fill.c +++ b/tests/fill.c @@ -1,25 +1,26 @@ #include "test.h" void test(){ - VkvgContext ctx = vkvg_create(surf); + VkvgContext ctx = vkvg_create(surf); + vkvg_set_line_width(ctx,30); + vkvg_set_line_join(ctx,VKVG_LINE_JOIN_ROUND); - vkvg_set_source_rgba(ctx,0.1,0.9,0.1,1.0); - vkvg_move_to(ctx,100,100); - vkvg_rel_line_to(ctx,100,100); - vkvg_rel_line_to(ctx,100,-100); - vkvg_rel_line_to(ctx,100,200); - vkvg_rel_line_to(ctx,-100,100); - vkvg_rel_line_to(ctx,-100,-100); - vkvg_rel_line_to(ctx,-100,-50); - //vkvg_close_path(ctx); - vkvg_fill(ctx); + vkvg_set_source_rgba(ctx,0.1f,0.9f,0.1f,1.0f); + vkvg_move_to(ctx,100,100); + vkvg_rel_line_to(ctx,50,200); + vkvg_rel_line_to(ctx,150,-100); + vkvg_rel_line_to(ctx,100,200); + vkvg_rel_line_to(ctx,-100,100); + vkvg_rel_line_to(ctx,-10,-100); + vkvg_rel_line_to(ctx,-190,-50); + vkvg_close_path(ctx); - vkvg_destroy(ctx); + vkvg_stroke(ctx); + + vkvg_destroy(ctx); } int main(int argc, char *argv[]) { - - perform_test (test, 1024, 768); - - return 0; + PERFORM_TEST (test, argc, argv); + return 0; } diff --git a/tests/fill_and_stroke.c b/tests/fill_and_stroke.c index b431c8e..1e2931f 100644 --- a/tests/fill_and_stroke.c +++ b/tests/fill_and_stroke.c @@ -1,33 +1,29 @@ #include "test.h" void test(){ - VkvgContext ctx = vkvg_create(surf); + VkvgContext ctx = vkvg_create(surf); - vkvg_translate(ctx,250,150); + 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_move_to (ctx, 100, 100); - vkvg_rel_line_to (ctx, 50, -80); - vkvg_rel_line_to (ctx, 50, 80); - //vkvg_close_path (ctx); + vkvg_move_to (ctx, 300, 100); + vkvg_rel_line_to (ctx, 50, -80); + vkvg_rel_line_to (ctx, 50, 80); + vkvg_close_path (ctx); - vkvg_move_to (ctx, 300, 100); - vkvg_rel_line_to (ctx, 50, -80); - vkvg_rel_line_to (ctx, 50, 80); - vkvg_close_path (ctx); + vkvg_set_line_width (ctx, 10.0); + vkvg_set_source_rgb (ctx, 0, 0, 1); + vkvg_fill_preserve (ctx); + //vkvg_fill(ctx); + vkvg_set_source_rgb (ctx, 1, 0, 0); + vkvg_stroke (ctx); - vkvg_set_line_width (ctx, 10.0); - vkvg_set_source_rgb (ctx, 0, 0, 1); - vkvg_fill_preserve (ctx); - //vkvg_fill(ctx); - vkvg_set_source_rgb (ctx, 1, 0, 0); - vkvg_stroke (ctx); - - vkvg_destroy(ctx); + vkvg_destroy(ctx); } int main(int argc, char *argv[]) { - - perform_test (test, 1024, 768); - - return 0; + PERFORM_TEST (test, argc, argv); + return 0; } diff --git a/tests/fillnstroke.c b/tests/fillnstroke.c deleted file mode 100644 index 7d35b29..0000000 --- a/tests/fillnstroke.c +++ /dev/null @@ -1,40 +0,0 @@ -#include "test.h" - -void test(){ - VkvgContext ctx = vkvg_create(surf); - - float x = 50, y = 150, dx = 150, dy = 140; - - vkvg_scale(ctx,2,2); - - vkvg_set_line_width(ctx,40); - vkvg_set_source_rgba(ctx,0,1,0,1); - - - vkvg_set_line_join(ctx,VKVG_LINE_JOIN_ROUND); - //vkvg_rectangle(ctx,x,y,dx,dy); - - - vkvg_move_to(ctx,x,y); - vkvg_rel_line_to(ctx,50,-30); - vkvg_rel_line_to(ctx,50,0); - vkvg_rel_line_to(ctx,50,30); - vkvg_rel_line_to(ctx,0,60); - vkvg_rel_line_to(ctx,-50,70); - vkvg_rel_line_to(ctx,-50,0); - vkvg_rel_line_to(ctx,-50,-70); - vkvg_line_to(ctx,x,y); - //vkvg_close_path(ctx); - vkvg_fill_preserve(ctx); - vkvg_set_source_rgba(ctx,0.5,0,0,0.5); - vkvg_stroke(ctx); - - vkvg_destroy(ctx); -} - -int main(int argc, char *argv[]) { - - perform_test (test, 1024, 768); - - return 0; -} diff --git a/tests/gradient.c b/tests/gradient.c index c11a6dc..151a9a4 100644 --- a/tests/gradient.c +++ b/tests/gradient.c @@ -1,43 +1,94 @@ #include "test.h" -void test(){ - VkvgContext ctx = vkvg_create(surf); +VkvgPattern create_grad (VkvgContext ctx) { + VkvgPattern pat = vkvg_pattern_create_linear(0,0,300,0); + vkvg_pattern_add_color_stop(pat, 0, 1, 0, 0, 1); + vkvg_pattern_add_color_stop(pat, 0.5f, 0, 1, 0, 1); + vkvg_pattern_add_color_stop(pat, 1, 0, 0, 1, 1); + return pat; +} + +void paint(){ + VkvgContext ctx = vkvg_create(surf); + VkvgPattern pat = create_grad(ctx); + vkvg_pattern_set_extend(pat,VKVG_EXTEND_NONE); + vkvg_set_source (ctx, pat); + vkvg_paint(ctx); + + vkvg_pattern_destroy (pat); + vkvg_destroy(ctx); +} +void paint_repeat(){ + VkvgContext ctx = vkvg_create(surf); + VkvgPattern pat = create_grad(ctx); + vkvg_pattern_set_extend(pat,VKVG_EXTEND_REPEAT); + vkvg_set_source (ctx, pat); + vkvg_paint(ctx); + + vkvg_pattern_destroy (pat); + vkvg_destroy(ctx); +} - VkvgPattern pat = vkvg_pattern_create_linear(0,0,300,300); - vkvg_set_line_width(ctx, 20); - 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, 1, 1); - vkvg_set_source (ctx, pat); - vkvg_rectangle(ctx,100,100,200,200); - //vkvg_fill (ctx); - //vkvg_paint(ctx); - vkvg_stroke (ctx); - vkvg_pattern_destroy (pat); +void test(){ + VkvgContext ctx = vkvg_create(surf); + VkvgPattern pat = create_grad(ctx); + vkvg_set_source (ctx, pat); + vkvg_rectangle(ctx,100,100,200,200); + vkvg_set_line_width(ctx, 20); + //vkvg_fill (ctx); + //vkvg_paint(ctx); + vkvg_stroke (ctx); + vkvg_pattern_destroy (pat); - vkvg_destroy(ctx); + vkvg_destroy(ctx); } void test2(){ - VkvgContext ctx = vkvg_create(surf); + VkvgContext ctx = vkvg_create(surf); - vkvg_set_source_rgb(ctx,1,0,0); - vkvg_paint(ctx); + vkvg_set_source_rgb(ctx,1,0,0); + vkvg_paint(ctx); - VkvgPattern pat = vkvg_pattern_create_linear(100,0,300,0); - vkvg_set_line_width(ctx, 20); - vkvg_pattern_add_color_stop(pat, 0, 1, 1, 1, 1); - vkvg_pattern_add_color_stop(pat, 1, 1, 1, 0, 0); - vkvg_set_source (ctx, pat); - vkvg_rectangle(ctx,100,100,200,200); - vkvg_fill (ctx); - //vkvg_stroke (ctx); - vkvg_pattern_destroy (pat); + VkvgPattern pat = vkvg_pattern_create_linear(100,0,300,0); + vkvg_set_line_width(ctx, 20); + vkvg_pattern_add_color_stop(pat, 0, 1, 1, 1, 1); + vkvg_pattern_add_color_stop(pat, 1, 1, 1, 0, 0); + vkvg_set_source (ctx, pat); + vkvg_rectangle(ctx,100,100,200,200); + vkvg_fill (ctx); + //vkvg_stroke (ctx); + vkvg_pattern_destroy (pat); - vkvg_destroy(ctx); + vkvg_destroy(ctx); } -int main(int argc, char *argv[]) { - perform_test (test, 1024, 768); +void gradient_transform() { + VkvgContext ctx = vkvg_create(surf); + + //vkvg_translate(ctx,-100,-100); + + vkvg_translate(ctx, 200, 100); + vkvg_rotate(ctx, 0.5f); + + //vkvg_scale(ctx,2,2); + VkvgPattern pat = vkvg_pattern_create_linear(0, 0, 400, 0); + vkvg_pattern_set_extend(pat, VKVG_EXTEND_NONE); + vkvg_set_line_width(ctx, 20); + vkvg_pattern_add_color_stop(pat, 0, 1, 0, 0, 1); + vkvg_pattern_add_color_stop(pat, 0.5f, 0, 1, 0, 1); + vkvg_pattern_add_color_stop(pat, 1, 0, 0, 1, 1); + vkvg_set_source(ctx, pat); + vkvg_rectangle(ctx, 0, 0, 400, 200); + //vkvg_fill (ctx); + vkvg_stroke(ctx); + //vkvg_paint(ctx); + vkvg_pattern_destroy(pat); - return 0; + vkvg_destroy(ctx); +} + +int main(int argc, char *argv[]) { + PERFORM_TEST(paint, argc, argv); + PERFORM_TEST(paint_repeat, argc, argv); + PERFORM_TEST(gradient_transform, argc, argv); + return 0; } diff --git a/tests/gradient_transform.c b/tests/gradient_transform.c deleted file mode 100644 index a9d51b8..0000000 --- a/tests/gradient_transform.c +++ /dev/null @@ -1,33 +0,0 @@ -#include "test.h" - -void test(){ - VkvgContext ctx = vkvg_create(surf); - - //vkvg_translate(ctx,-100,-100); - - vkvg_translate(ctx,100,100); - vkvg_rotate(ctx,0.5); - - //vkvg_scale(ctx,2,2); - VkvgPattern pat = vkvg_pattern_create_linear(0,0,200,0); - //vkvg_pattern_set_extend(pat, VKVG_EXTEND_REPEAT); - vkvg_set_line_width(ctx, 20); - 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, 1, 1); - vkvg_set_source (ctx, pat); - vkvg_rectangle(ctx,0,0,200,200); - vkvg_fill (ctx); - //vkvg_stroke (ctx); - //vkvg_paint(ctx); - vkvg_pattern_destroy (pat); - - vkvg_destroy(ctx); -} - -int main(int argc, char *argv[]) { - - perform_test (test, 1024, 768); - - return 0; -} diff --git a/tests/hlines.c b/tests/hlines.c index 90d0451..25322f5 100644 --- a/tests/hlines.c +++ b/tests/hlines.c @@ -1,35 +1,35 @@ #include "test.h" void test(){ - vkvg_surface_clear(surf); - struct timeval currentTime; - gettimeofday(¤tTime, NULL); + vkvg_surface_clear(surf); + struct timeval currentTime; + gettimeofday(¤tTime, NULL); - srand((unsigned) currentTime.tv_usec); - const float w = 1024.f; - const float h = 800.f; + srand((unsigned) currentTime.tv_usec); + const float w = 1024.f; + const float h = 800.f; - VkvgContext ctx = vkvg_create(surf); - //vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD); - vkvg_set_line_width(ctx,1); - //vkvg_set_line_join(ctx,VKVG_LINE_JOIN_BEVEL); + VkvgContext ctx = vkvg_create(surf); + //vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD); + vkvg_set_line_width(ctx,1); + //vkvg_set_line_join(ctx,VKVG_LINE_JOIN_BEVEL); - for (uint i=0; i<test_size; i++) { - randomize_color(ctx); - float x1 = w*rand()/RAND_MAX; - float y1 = h*rand()/RAND_MAX; - float v = 500.f*rand()/RAND_MAX; + for (uint32_t i=0; i<test_size; i++) { + randomize_color(ctx); + float x1 = w*rand()/RAND_MAX; + float y1 = h*rand()/RAND_MAX; + float v = 500.f*rand()/RAND_MAX; - vkvg_move_to (ctx, x1, y1); - vkvg_line_to (ctx, x1 + v, y1); - vkvg_stroke (ctx); - } - vkvg_destroy(ctx); + vkvg_move_to (ctx, x1, y1); + vkvg_line_to (ctx, x1 + v, y1); + vkvg_stroke (ctx); + } + vkvg_destroy(ctx); } int main(int argc, char *argv[]) { - perform_test (test, 1024, 768); + PERFORM_TEST (test, argc, argv); - return 0; + return 0; } diff --git a/tests/img_surf.c b/tests/img_surf.c index 319acfb..ad0abc4 100644 --- a/tests/img_surf.c +++ b/tests/img_surf.c @@ -1,75 +1,115 @@ #include "test.h" +void paint () { + VkvgContext ctx = vkvg_create(surf); + VkvgSurface imgSurf = vkvg_surface_create_from_image(device, "data/miroir.jpg"); -void test(){ - VkvgContext ctx = vkvg_create(surf); - vkvg_set_fill_rule(ctx,VKVG_FILL_RULE_NON_ZERO); - VkvgSurface imgSurf = vkvg_surface_create_from_image(device, "data/miroir.jpg"); - - //vkvg_translate(ctx,20,20); - //vkvg_rotate(ctx,0.5); - - vkvg_set_source_rgba(ctx,1,0,0,1); - //vkvg_rectangle(ctx,100,100,200,200); - /*vkvg_rectangle(ctx, - 0, - 0, - 500, - 500); - vkvg_fill(ctx);*/ - vkvg_paint(ctx); + vkvg_set_source_surface(ctx, imgSurf, 0, 0); + vkvg_paint(ctx); - //vkvg_set_source_surface(ctx, imgSurf, 0,0); + vkvg_surface_destroy(imgSurf); + vkvg_destroy(ctx); +} +void paint_offset () { + VkvgContext ctx = vkvg_create(surf); + VkvgSurface imgSurf = vkvg_surface_create_from_image(device, "data/miroir.jpg"); - VkvgPattern pat = vkvg_pattern_create_for_surface(imgSurf); - vkvg_pattern_set_extend(pat, VKVG_EXTEND_REPEAT); - vkvg_set_source(ctx, pat); - vkvg_rectangle(ctx,0,0,500,500); - vkvg_fill(ctx); - //vkvg_paint(ctx); + vkvg_set_source_surface(ctx, imgSurf, 100, 100); + vkvg_paint(ctx); - vkvg_pattern_destroy(pat); - /*vkvg_set_operator(ctx, VKVG_OPERATOR_CLEAR); - vkvg_paint(ctx); - vkvg_set_operator(ctx, VKVG_OPERATOR_OVER);*/ - /*vkvg_translate(ctx,200,200); + vkvg_surface_destroy(imgSurf); + vkvg_destroy(ctx); +} +void paint_with_scale(){ + VkvgContext ctx = vkvg_create(surf); + vkvg_scale (ctx, 0.2f,0.2f); + VkvgSurface imgSurf = vkvg_surface_create_from_image(device, "data/miroir.jpg"); + vkvg_set_source_surface(ctx, imgSurf, 0, 0); - vkvg_set_line_width(ctx,20.f); - vkvg_set_source_rgba(ctx,1,0,0,1); - vkvg_arc(ctx,200,200,200,0,2.f*M_PI); - vkvg_new_sub_path(ctx); - vkvg_arc(ctx,200,200,100,0,2.f*M_PI); + vkvg_paint(ctx); - vkvg_set_source_surface(ctx, imgSurf, 00, 00); - vkvg_fill_preserve(ctx); - vkvg_set_source_rgba(ctx,0.2,0.3,0.8,1); + vkvg_surface_destroy(imgSurf); + vkvg_destroy(ctx); +} - vkvg_stroke(ctx);*/ -/* - //vkvg_translate(ctx,200,200); - vkvg_rotate(ctx,0.1f); +void paint_pattern () { + VkvgContext ctx = vkvg_create(surf); + VkvgSurface imgSurf = vkvg_surface_create_from_image(device, "data/miroir.jpg"); + VkvgPattern pat = vkvg_pattern_create_for_surface(imgSurf); + vkvg_set_source(ctx, pat); + vkvg_paint(ctx); + vkvg_pattern_destroy(pat); + vkvg_surface_destroy(imgSurf); + vkvg_destroy(ctx); +} +void paint_pattern_repeat () { + VkvgContext ctx = vkvg_create(surf); + VkvgSurface imgSurf = vkvg_surface_create_from_image(device, "data/miroir.jpg"); + VkvgPattern pat = vkvg_pattern_create_for_surface(imgSurf); + vkvg_pattern_set_extend(pat,VKVG_EXTEND_REPEAT); + vkvg_set_source(ctx, pat); + vkvg_paint(ctx); + vkvg_pattern_destroy(pat); + vkvg_surface_destroy(imgSurf); + vkvg_destroy(ctx); +} +void paint_pattern_repeat_scalled () { + VkvgContext ctx = vkvg_create(surf); + vkvg_scale (ctx, 0.2f,0.2f); + VkvgSurface imgSurf = vkvg_surface_create_from_image(device, "data/miroir.jpg"); + VkvgPattern pat = vkvg_pattern_create_for_surface(imgSurf); + vkvg_pattern_set_extend(pat,VKVG_EXTEND_REPEAT); + vkvg_set_source(ctx, pat); + vkvg_paint(ctx); + vkvg_pattern_destroy(pat); + vkvg_surface_destroy(imgSurf); + vkvg_destroy(ctx); +} +void paint_pattern_pad () { + VkvgContext ctx = vkvg_create(surf); + VkvgSurface imgSurf = vkvg_surface_create_from_image(device, "data/miroir.jpg"); + VkvgPattern pat = vkvg_pattern_create_for_surface(imgSurf); + vkvg_pattern_set_extend(pat,VKVG_EXTEND_PAD); + vkvg_set_source(ctx, pat); + vkvg_paint(ctx); + vkvg_pattern_destroy(pat); + vkvg_surface_destroy(imgSurf); + vkvg_destroy(ctx); +} - //vkvg_scale(ctx,0.5,0.5); - vkvg_set_source_rgb(ctx,0,0,1); - vkvg_paint(ctx); -*/ - /*vkvg_rotate(ctx,0.5); +void test(){ + VkvgContext ctx = vkvg_create(surf); + vkvg_set_fill_rule(ctx,VKVG_FILL_RULE_EVEN_ODD); + VkvgSurface imgSurf = vkvg_surface_create_from_image(device, "data/miroir.jpg"); - vkvg_set_line_width(ctx,20.f); - vkvg_rectangle(ctx,200,200,200,200); - vkvg_stroke(ctx);*/ + vkvg_translate(ctx,200,200); + //vkvg_rotate(ctx,M_PI_4); + vkvg_set_line_width(ctx,20.f); + vkvg_set_source_rgba(ctx,1,0,0,1); + vkvg_arc(ctx,200,200,200,0,2.f*M_PIF); + vkvg_new_sub_path(ctx); + vkvg_arc(ctx,200,200,100,0,2.f*M_PIF); + vkvg_set_source_surface(ctx, imgSurf, 0, 0); + vkvg_fill_preserve(ctx); + vkvg_set_source_rgba(ctx,0.2f,0.3f,0.8f,1); - //vkvg_paint(ctx); + vkvg_stroke(ctx); - vkvg_surface_destroy(imgSurf); + vkvg_surface_destroy(imgSurf); - vkvg_destroy(ctx); + vkvg_destroy(ctx); } int main(int argc, char *argv[]) { + PERFORM_TEST (paint, argc, argv); + PERFORM_TEST (paint_offset, argc, argv); + PERFORM_TEST (paint_with_scale, argc, argv); + PERFORM_TEST (paint_pattern, argc, argv); + PERFORM_TEST (paint_pattern_repeat, argc, argv); + PERFORM_TEST (paint_pattern_repeat_scalled, argc, argv); + PERFORM_TEST (paint_pattern_pad, argc, argv); + PERFORM_TEST (test, argc, argv); - perform_test (test, 1024, 768); - - return 0; + return 0; } diff --git a/tests/line_caps.c b/tests/line_caps.c index 674ebb3..6e12983 100644 --- a/tests/line_caps.c +++ b/tests/line_caps.c @@ -1,59 +1,57 @@ #include "test.h" void test(){ - VkvgContext ctx = vkvg_create(surf); - vkvg_set_source_rgba(ctx,0.9,0.9,0.9,1); - vkvg_paint(ctx); + VkvgContext ctx = vkvg_create(surf); + vkvg_set_source_rgba(ctx,0.9f,0.9f,0.9f,1); + vkvg_paint(ctx); - float x = 20, y = 20, dx = 40, dy = 60; + float x = 20, y = 20, dx = 40, dy = 60; - //vkvg_scale(ctx,5,5); - vkvg_set_line_width(ctx,30); - vkvg_set_source_rgba(ctx,0.0,0.0,0,1); - vkvg_move_to(ctx,x,y); - vkvg_rel_line_to(ctx,0,dy); - vkvg_stroke(ctx); - vkvg_set_line_cap(ctx,VKVG_LINE_CAP_SQUARE); - vkvg_move_to(ctx,x+dx,y); - vkvg_rel_line_to(ctx,0,dy); - vkvg_stroke(ctx); - vkvg_set_line_cap(ctx,VKVG_LINE_CAP_ROUND); - vkvg_move_to(ctx,x+2*dx,y); - vkvg_rel_line_to(ctx,0,dy); - vkvg_rel_move_to(ctx,dx,-dy); - vkvg_rel_line_to(ctx,dx,dy); - vkvg_rel_move_to(ctx,dx,-dy/2); - vkvg_rel_line_to(ctx,dx,0); - vkvg_rel_move_to(ctx,dx,dy/2); - vkvg_rel_line_to(ctx,dx,-dy); - vkvg_rel_move_to(ctx,dx,dy); - vkvg_rel_line_to(ctx,0,-dy); - vkvg_rel_move_to(ctx,2*dx,dy); - vkvg_rel_line_to(ctx,-dx,-dy); - vkvg_rel_move_to(ctx,3*dx,dy/2); - vkvg_rel_line_to(ctx,-dx,0); - //vkvg_rel_line_to(ctx,0,-dy); - //vkvg_rel_move_to(ctx,dx,dy/2); - //vkvg_rel_line_to(ctx,dx,0); - vkvg_stroke(ctx); + //vkvg_scale(ctx,5,5); + vkvg_set_line_width(ctx,30); + vkvg_set_source_rgba(ctx,0.0,0.0,0,1); + vkvg_move_to(ctx,x,y); + vkvg_rel_line_to(ctx,0,dy); + vkvg_stroke(ctx); + vkvg_set_line_cap(ctx,VKVG_LINE_CAP_SQUARE); + vkvg_move_to(ctx,x+dx,y); + vkvg_rel_line_to(ctx,0,dy); + vkvg_stroke(ctx); + vkvg_set_line_cap(ctx,VKVG_LINE_CAP_ROUND); + vkvg_move_to(ctx,x+2*dx,y); + vkvg_rel_line_to(ctx,0,dy); + vkvg_rel_move_to(ctx,dx,-dy); + vkvg_rel_line_to(ctx,dx,dy); + vkvg_rel_move_to(ctx,dx,-dy/2.f); + vkvg_rel_line_to(ctx,dx,0); + vkvg_rel_move_to(ctx,dx,dy/2.f); + vkvg_rel_line_to(ctx,dx,-dy); + vkvg_rel_move_to(ctx,dx,dy); + vkvg_rel_line_to(ctx,0,-dy); + vkvg_rel_move_to(ctx,dx*2.f,dy); + vkvg_rel_line_to(ctx,-dx,-dy); + vkvg_rel_move_to(ctx,dx*3.f,dy/2.f); + vkvg_rel_line_to(ctx,-dx,0); + //vkvg_rel_line_to(ctx,0,-dy); + //vkvg_rel_move_to(ctx,dx,dy/2); + //vkvg_rel_line_to(ctx,dx,0); + vkvg_stroke(ctx); - vkvg_set_line_cap(ctx,VKVG_LINE_CAP_BUTT); - vkvg_set_line_width(ctx,1); - vkvg_set_source_rgba(ctx,1,0,0,1); - vkvg_move_to(ctx,x,y); - vkvg_rel_line_to(ctx,0,dy); - vkvg_rel_move_to(ctx,dx,-dy); - vkvg_rel_line_to(ctx,0,dy); - vkvg_rel_move_to(ctx,dx,-dy); - vkvg_rel_line_to(ctx,0,dy); - vkvg_stroke(ctx); + vkvg_set_line_cap(ctx,VKVG_LINE_CAP_BUTT); + vkvg_set_line_width(ctx,1); + vkvg_set_source_rgba(ctx,1,0,0,1); + vkvg_move_to(ctx,x,y); + vkvg_rel_line_to(ctx,0,dy); + vkvg_rel_move_to(ctx,dx,-dy); + vkvg_rel_line_to(ctx,0,dy); + vkvg_rel_move_to(ctx,dx,-dy); + vkvg_rel_line_to(ctx,0,dy); + vkvg_stroke(ctx); - vkvg_destroy(ctx); + vkvg_destroy(ctx); } int main(int argc, char *argv[]) { - - perform_test (test, 1024, 768); - - return 0; + PERFORM_TEST (test, argc, argv); + return 0; } diff --git a/tests/line_join.c b/tests/line_join.c index 03c9d25..1502825 100644 --- a/tests/line_join.c +++ b/tests/line_join.c @@ -1,53 +1,59 @@ #include "test.h" void test(){ - VkvgContext ctx = vkvg_create(surf); + VkvgContext ctx = vkvg_create(surf); - float x = 50, y = 150, dx = 150, dy = 140; + float x = 250, y = 150; - vkvg_scale(ctx,2,2); + //vkvg_scale(ctx,2,2); - vkvg_set_line_width(ctx,40); - vkvg_set_source_rgba(ctx,0,0,0,1); + vkvg_set_line_width(ctx,100); + vkvg_set_source_rgba(ctx,0,1,0,1); - vkvg_set_line_join(ctx,VKVG_LINE_JOIN_ROUND); - //vkvg_rectangle(ctx,x,y,dx,dy); + vkvg_set_line_join(ctx,VKVG_LINE_JOIN_ROUND); + //vkvg_rectangle(ctx,x,y,dx,dy); - vkvg_move_to(ctx,x,y); - vkvg_rel_line_to(ctx,50,-30); - vkvg_rel_line_to(ctx,50,0); - vkvg_rel_line_to(ctx,50,30); - vkvg_rel_line_to(ctx,0,60); - vkvg_rel_line_to(ctx,-50,70); - vkvg_rel_line_to(ctx,-50,0); - vkvg_rel_line_to(ctx,-50,-70); - vkvg_close_path(ctx); - vkvg_stroke(ctx); + vkvg_move_to(ctx,x,y); + vkvg_rel_line_to(ctx,-50,30); + vkvg_rel_line_to(ctx,0,60); + vkvg_rel_line_to(ctx,50,30); + /* + vkvg_rel_line_to(ctx,50,-30); + vkvg_rel_line_to(ctx,50,0); + vkvg_rel_line_to(ctx,50,30); + vkvg_rel_line_to(ctx,0,60); + vkvg_rel_line_to(ctx,-50,70); + vkvg_rel_line_to(ctx,-50,0); + vkvg_rel_line_to(ctx,-50,-70); + vkvg_close_path(ctx); + vkvg_stroke(ctx); - vkvg_set_source_rgba(ctx,1,0,0,1); - vkvg_move_to(ctx,x+200,y); - vkvg_rel_line_to(ctx,50,70); - vkvg_rel_line_to(ctx,50,0); - vkvg_rel_line_to(ctx,50,-70); - vkvg_rel_line_to(ctx,0,-60); - vkvg_rel_line_to(ctx,-50,-30); - vkvg_rel_line_to(ctx,-50,0); - vkvg_rel_line_to(ctx,-50,30); - vkvg_close_path(ctx); - vkvg_stroke(ctx); + vkvg_set_source_rgba(ctx,1,0,0,1); + vkvg_move_to(ctx,x+200,y); + vkvg_rel_line_to(ctx,50,70); + vkvg_rel_line_to(ctx,50,0); + vkvg_rel_line_to(ctx,50,-70); + vkvg_rel_line_to(ctx,0,-60); + vkvg_rel_line_to(ctx,-50,-30); + vkvg_rel_line_to(ctx,-50,0); + vkvg_rel_line_to(ctx,-50,30);*/ + vkvg_close_path(ctx); + vkvg_stroke(ctx); - vkvg_move_to(ctx,x,y); - vkvg_rel_line_to(ctx,50,-30); - vkvg_rel_line_to(ctx,50,0); - vkvg_rel_line_to(ctx,50,30); - vkvg_rel_line_to(ctx,0,60); - vkvg_rel_line_to(ctx,-50,70); - vkvg_rel_line_to(ctx,-50,0); - vkvg_rel_line_to(ctx,-50,-70); - vkvg_close_path(ctx); - vkvg_stroke(ctx); + vkvg_set_source_rgba(ctx,0,0,1,1); + vkvg_move_to(ctx,x+250,y); + vkvg_rel_line_to(ctx,50,-30); + vkvg_rel_line_to(ctx,50,0); + vkvg_rel_line_to(ctx,50,30); + vkvg_rel_line_to(ctx,0,60); + vkvg_rel_line_to(ctx,-50,70); + vkvg_rel_line_to(ctx,-50,0); + vkvg_rel_line_to(ctx,-50,-70); + vkvg_close_path(ctx); + vkvg_stroke(ctx); +// float dx = 150, dy = 140; // vkvg_rel_line_to(ctx,dx,-dy); // vkvg_rel_line_to(ctx,dx,dy); // vkvg_stroke(ctx); @@ -63,12 +69,113 @@ void test(){ // vkvg_stroke(ctx); // vkvg_set_line_join(ctx,VKVG_LINE_JOIN_MITER); - vkvg_destroy(ctx); + vkvg_destroy(ctx); } -int main(int argc, char *argv[]) { +void test2() { + VkvgContext ctx = vkvg_create(surf); + + vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD); + vkvg_set_line_width(ctx, 30); + + vkvg_set_line_join(ctx, VKVG_LINE_JOIN_ROUND); + + //vkvg_arc (ctx, 200, 500, 100, 0, M_PI); + + vkvg_translate(ctx, -50, -50); + + vkvg_set_source_rgb(ctx, 0.5, 0, 0); + + for (int j = 0; j < 2; j++) { + int i = 0; + vkvg_move_to(ctx, 100, 100); + for (i = 0; i < 5; i++) { + vkvg_rel_line_to(ctx, 70, 50); + vkvg_rel_line_to(ctx, -70, 50); + } + vkvg_stroke(ctx); + + vkvg_move_to(ctx, 200, 600); + for (i = 0; i < 5; i++) { + vkvg_rel_line_to(ctx, 70, -50); + vkvg_rel_line_to(ctx, -70, -50); + } + vkvg_stroke(ctx); + + vkvg_move_to(ctx, 400, 100); + for (i = 0; i < 5; i++) { + vkvg_rel_line_to(ctx, -70, 50); + vkvg_rel_line_to(ctx, 70, 50); + } + vkvg_stroke(ctx); + + vkvg_move_to(ctx, 500, 600); + for (i = 0; i < 5; i++) { + vkvg_rel_line_to(ctx, -70, -50); + vkvg_rel_line_to(ctx, 70, -50); + } + vkvg_stroke(ctx); + vkvg_set_line_join(ctx, VKVG_LINE_JOIN_BEVEL); + vkvg_translate(ctx, 500, 0); + } + + vkvg_destroy(ctx); +} + +void test3() { + VkvgContext ctx = vkvg_create(surf); - perform_test (test, 1024, 768); + vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD); + vkvg_set_line_width(ctx, 30); - return 0; + vkvg_set_line_join(ctx, VKVG_LINE_JOIN_ROUND); + + //vkvg_arc (ctx, 200, 500, 100, 0, M_PI); + + vkvg_translate(ctx, -50, -50); + + vkvg_set_source_rgb(ctx, 0.5, 0, 0); + + for (int j = 0; j < 2; j++) { + int i = 0; + vkvg_move_to(ctx, 100, 100); + for (i = 0; i < 4; i++) { + vkvg_rel_line_to(ctx, 50, 70); + vkvg_rel_line_to(ctx, 50, -70); + } + vkvg_stroke(ctx); + + vkvg_move_to(ctx, 500, 200); + for (i = 0; i < 4; i++) { + vkvg_rel_line_to(ctx, -50, 70); + vkvg_rel_line_to(ctx, -50, -70); + } + vkvg_stroke(ctx); + + vkvg_move_to(ctx, 100, 400); + for (i = 0; i < 4; i++) { + vkvg_rel_line_to(ctx, 50, -70); + vkvg_rel_line_to(ctx, 50, 70); + } + vkvg_stroke(ctx); + + vkvg_move_to(ctx, 500, 500); + for (i = 0; i < 4; i++) { + vkvg_rel_line_to(ctx, -50, -70); + vkvg_rel_line_to(ctx, -50, 70); + } + vkvg_stroke(ctx); + vkvg_set_line_join(ctx, VKVG_LINE_JOIN_BEVEL); + vkvg_translate(ctx, 450, 0); + } + + vkvg_destroy(ctx); +} + + +int main(int argc, char *argv[]) { + PERFORM_TEST(test, argc, argv); + PERFORM_TEST(test2, argc, argv); + PERFORM_TEST(test3, argc, argv); + return 0; } diff --git a/tests/line_join_2.c b/tests/line_join_2.c deleted file mode 100644 index 3c736fd..0000000 --- a/tests/line_join_2.c +++ /dev/null @@ -1,58 +0,0 @@ -#include "test.h" - -void test(){ - VkvgContext ctx = vkvg_create(surf); - - //vkvg_set_fill_rule(ctx, VKVG_FILL_RULE); - vkvg_set_line_width(ctx, 30); - - vkvg_set_line_join(ctx, VKVG_LINE_JOIN_ROUND); - - //vkvg_arc (ctx, 200, 500, 100, 0, M_PI); - - vkvg_translate(ctx,-50,-50); - - vkvg_set_source_rgba (ctx, 0.2f,0.2f,1.0f,1); - - for (int j=0;j<2;j++) { - int i=0; - vkvg_move_to(ctx,100,100); - for (i=0;i<5;i++) { - vkvg_rel_line_to(ctx,70,50); - vkvg_rel_line_to(ctx,-70,50); - } - vkvg_stroke(ctx); - - vkvg_move_to(ctx,200,600); - for (i=0;i<5;i++) { - vkvg_rel_line_to(ctx,70,-50); - vkvg_rel_line_to(ctx,-70,-50); - } - vkvg_stroke(ctx); - - vkvg_move_to(ctx,400,100); - for (i=0;i<5;i++) { - vkvg_rel_line_to(ctx,-70,50); - vkvg_rel_line_to(ctx,70,50); - } - vkvg_stroke(ctx); - - vkvg_move_to(ctx,500,600); - for (i=0;i<5;i++) { - vkvg_rel_line_to(ctx,-70,-50); - vkvg_rel_line_to(ctx,70,-50); - } - vkvg_stroke(ctx); - //vkvg_set_line_join(ctx, VKVG_LINE_JOIN_BEVEL); - vkvg_translate(ctx,500,0); - } - - vkvg_destroy(ctx); -} - -int main(int argc, char *argv[]) { - - perform_test (test, 1024, 768); - - return 0; -} diff --git a/tests/line_join_3.c b/tests/line_join_3.c deleted file mode 100644 index 5e0e48b..0000000 --- a/tests/line_join_3.c +++ /dev/null @@ -1,58 +0,0 @@ -#include "test.h" - -void test(){ - VkvgContext ctx = vkvg_create(surf); - - vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD); - vkvg_set_line_width(ctx, 30); - - vkvg_set_line_join(ctx, VKVG_LINE_JOIN_ROUND); - - //vkvg_arc (ctx, 200, 500, 100, 0, M_PI); - - vkvg_translate(ctx,-50,-50); - - vkvg_set_source_rgb (ctx, 0.5,0,0); - - for (int j=0;j<2;j++) { - int i=0; - vkvg_move_to(ctx,100,100); - for (i=0;i<4;i++) { - vkvg_rel_line_to(ctx,50,70); - vkvg_rel_line_to(ctx,50,-70); - } - vkvg_stroke(ctx); - - vkvg_move_to(ctx,500,200); - for (i=0;i<4;i++) { - vkvg_rel_line_to(ctx,-50,70); - vkvg_rel_line_to(ctx,-50,-70); - } - vkvg_stroke(ctx); - - vkvg_move_to(ctx,100,400); - for (i=0;i<4;i++) { - vkvg_rel_line_to(ctx,50,-70); - vkvg_rel_line_to(ctx,50,70); - } - vkvg_stroke(ctx); - - vkvg_move_to(ctx,500,500); - for (i=0;i<4;i++) { - vkvg_rel_line_to(ctx,-50,-70); - vkvg_rel_line_to(ctx,-50,70); - } - vkvg_stroke(ctx); - vkvg_set_line_join(ctx, VKVG_LINE_JOIN_BEVEL); - vkvg_translate(ctx,450,0); - } - - vkvg_destroy(ctx); -} - -int main(int argc, char *argv[]) { - - perform_test (test, 1024, 768); - - return 0; -} diff --git a/tests/lines.c b/tests/lines.c index 4433c6e..98bde9f 100644 --- a/tests/lines.c +++ b/tests/lines.c @@ -1,41 +1,39 @@ #include "test.h" void test(){ - vkvg_surface_clear(surf); + vkvg_surface_clear(surf); - struct timeval currentTime; - gettimeofday(¤tTime, NULL); - srand((unsigned) currentTime.tv_usec); + struct timeval currentTime; + gettimeofday(¤tTime, NULL); + srand((unsigned) currentTime.tv_usec); - const float w = 1024.f; - const float h = 800.f; + const float w = 1024.f; + const float h = 800.f; - VkvgContext ctx = vkvg_create(surf); - //vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD); - vkvg_set_line_width (ctx,1); - //vkvg_set_line_join(ctx,VKVG_LINE_JOIN_BEVEL); + VkvgContext ctx = vkvg_create(surf); + //vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD); + vkvg_set_line_width (ctx,1); + //vkvg_set_line_join(ctx,VKVG_LINE_JOIN_BEVEL); - for (uint i=0; i<test_size; i++) { - randomize_color(ctx); + for (uint32_t i=0; i<test_size; i++) { + randomize_color(ctx); - float x1 = w*rand()/RAND_MAX; - float y1 = h*rand()/RAND_MAX; - float x2 = (w*rand()/RAND_MAX) + 1; - float y2 = (h*rand()/RAND_MAX) + 1; + float x1 = w*rand()/RAND_MAX; + float y1 = h*rand()/RAND_MAX; + float x2 = (w*rand()/RAND_MAX) + 1; + float y2 = (h*rand()/RAND_MAX) + 1; - vkvg_move_to (ctx, x1, y1); - vkvg_line_to (ctx, x2, y2); - vkvg_stroke (ctx); + vkvg_move_to (ctx, x1, y1); + vkvg_line_to (ctx, x2, y2); + vkvg_stroke (ctx); - /*if (i%100==0) - vkvg_flush(ctx);*/ - } - vkvg_destroy(ctx); + /*if (i%100==0) + vkvg_flush(ctx);*/ + } + vkvg_destroy(ctx); } int main(int argc, char *argv[]) { - - perform_test (test, 1024, 768); - - return 0; + PERFORM_TEST(test, argc, argv); + return 0; } diff --git a/tests/multilines.c b/tests/multilines.c index b4616c3..f9d6c06 100644 --- a/tests/multilines.c +++ b/tests/multilines.c @@ -1,41 +1,39 @@ #include "test.h" void test(){ - vkvg_surface_clear(surf); - struct timeval currentTime; - gettimeofday(¤tTime, NULL); + vkvg_surface_clear(surf); + struct timeval currentTime; + gettimeofday(¤tTime, NULL); - srand((unsigned) currentTime.tv_usec); - const float w = 1024.f; - const float h = 800.f; + srand((unsigned) currentTime.tv_usec); + const float w = 1024.f; + const float h = 800.f; - VkvgContext ctx = vkvg_create(surf); - //vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD); - vkvg_set_line_width(ctx,1); - //vkvg_set_line_join(ctx,VKVG_LINE_JOIN_BEVEL); + VkvgContext ctx = vkvg_create(surf); + //vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD); + vkvg_set_line_width(ctx,1); + //vkvg_set_line_join(ctx,VKVG_LINE_JOIN_BEVEL); - randomize_color(ctx); + randomize_color(ctx); - for (int i=0; i<test_size; i++) { + for (uint32_t i=0; i<test_size; i++) { - float x1 = w*rand()/RAND_MAX; - float y1 = h*rand()/RAND_MAX; - float x2 = (w*rand()/RAND_MAX) + 1; - float y2 = (h*rand()/RAND_MAX) + 1; + float x1 = w*rand()/RAND_MAX; + float y1 = h*rand()/RAND_MAX; + float x2 = (w*rand()/RAND_MAX) + 1; + float y2 = (h*rand()/RAND_MAX) + 1; - vkvg_move_to (ctx, x1, y1); - vkvg_line_to (ctx, x2, y2); + vkvg_move_to (ctx, x1, y1); + vkvg_line_to (ctx, x2, y2); - /*if (i%100==0) - vkvg_flush(ctx);*/ - } - vkvg_stroke (ctx); - vkvg_destroy(ctx); + /*if (i%100==0) + vkvg_flush(ctx);*/ + } + vkvg_stroke (ctx); + vkvg_destroy(ctx); } int main(int argc, char *argv[]) { - - perform_test (test, 1024, 768); - - return 0; + PERFORM_TEST (test, argc, argv); + return 0; } diff --git a/tests/painting.c b/tests/painting.c deleted file mode 100644 index 25f7d3b..0000000 --- a/tests/painting.c +++ /dev/null @@ -1,75 +0,0 @@ -#include "test.h" - -static VkvgSurface surf2; - -void test(){ - - VkvgContext ctx = vkvg_create (surf); - - /*vkvg_set_source_surface(ctx,surf2,0,0); - vkvg_paint (ctx); - vkvg_destroy (ctx); - - return;*/ - - //vkvg_set_source_rgba(ctx,0.1,0.1,0.3,1.0); - //vkvg_paint (ctx); - - /*for (int i=0; i<10; i++) { - vkvg_translate(ctx,50,50); - - vkvg_save(ctx); - - vkvg_set_source_rgba(ctx,0.0,0.0,0.0,0.3f); - vkvg_move_to(ctx,0,0); - vkvg_line_to(ctx,0,200); - vkvg_set_line_width(ctx,10); - vkvg_stroke(ctx); - vkvg_set_source_surface(ctx,surf2,0,0); - vkvg_paint (ctx); - - vkvg_restore(ctx); - }*/ - - //VkvgPattern pat = vkvg_get_source (ctx); - VkvgPattern pat = vkvg_pattern_create_for_surface(surf2); - //vkvg_pattern_set_extend (pat,VKVG_EXTEND_REFLECT); - vkvg_set_source(ctx,pat); - //vkvg_set_source_rgba(ctx,0,1,0,1.0); - //vkvg_rectangle(ctx,100,100,200,200); - //vkvg_fill(ctx); - vkvg_paint (ctx); - - vkvg_destroy (ctx); - - vkvg_pattern_destroy (pat); -} - -int main(int argc, char *argv[]) { - - init_test(1024, 768); - - surf2 = vkvg_surface_create (device,400,400); - - VkvgContext ctx = vkvg_create (surf2); - - vkvg_set_source_rgba(ctx,1.0,0.,0.,0.2f); - vkvg_paint (ctx); - /*vkvg_set_source_rgba(ctx,1.0,1.0,0.,0.5f); - vkvg_move_to(ctx,10,10); - vkvg_line_to(ctx,200,200); - vkvg_set_line_width(ctx,10); - vkvg_stroke(ctx); - vkvg_set_source_rgba(ctx,1.0,1.0,1.0,0.6f); - vkvg_rectangle(ctx,0,0,400,400); - vkvg_stroke(ctx);*/ - - vkvg_destroy (ctx); - - run_test_func(test, 1024, 768); - - vkvg_surface_destroy (surf2); - - clear_test(); - return 0; -} diff --git a/tests/random_cirles.c b/tests/random_cirles.c index 9c78f63..9004961 100644 --- a/tests/random_cirles.c +++ b/tests/random_cirles.c @@ -1,38 +1,33 @@ #include "test.h" void test(){ - vkvg_surface_clear(surf); - struct timeval currentTime; - gettimeofday(¤tTime, NULL); + vkvg_surface_clear(surf); + struct timeval currentTime; + gettimeofday(¤tTime, NULL); - srand((unsigned) currentTime.tv_usec); - const float w = 800.f; + srand((unsigned) currentTime.tv_usec); + const float w = 800.f; - VkvgContext ctx = vkvg_create(surf); - //vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD); + VkvgContext ctx = vkvg_create(surf); + vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD); - vkvg_set_line_width(ctx, 1.0f); - //vkvg_set_line_join(ctx,VKVG_LINE_JOIN_BEVEL); + vkvg_set_line_width(ctx, 1.0f); + //vkvg_set_line_join(ctx,VKVG_LINE_JOIN_BEVEL); - for (uint i=0; i<test_size; i++) { - randomize_color(ctx); + for (uint32_t i=0; i<test_size; i++) { + randomize_color(ctx); - float r = 0.5f*w*rand()/RAND_MAX; - float x = truncf(0.5f * w*rand()/RAND_MAX + r); - float y = truncf(0.5f * w*rand()/RAND_MAX + r); + float r = 0.5f*w*rand()/RAND_MAX; + float x = truncf(0.5f * w*rand()/RAND_MAX + r); + float y = truncf(0.5f * w*rand()/RAND_MAX + r); - vkvg_arc(ctx, x, y, r, 0, M_PI * 2.0f); - //vkvg_fill(ctx); - vkvg_fill_preserve(ctx); - randomize_color(ctx); - vkvg_stroke(ctx); - } - vkvg_destroy(ctx); + vkvg_arc(ctx, x, y, r, 0, M_PIF * 2.0f); + vkvg_fill(ctx); + } + vkvg_destroy(ctx); } int main(int argc, char *argv[]) { - - perform_test (test, 1024, 768); - - return 0; + PERFORM_TEST(test, argc, argv); + return 0; } diff --git a/tests/random_rects.c b/tests/random_rects.c index 9a6e965..34f3512 100644 --- a/tests/random_rects.c +++ b/tests/random_rects.c @@ -1,41 +1,122 @@ #include "test.h" -void test(){ - struct timeval currentTime; - gettimeofday(¤tTime, NULL); +/*void drawRandomRect (VkvgContext ctx) { + float w = (float)test_width; + float h = (float)test_height; + randomize_color(ctx); - srand((unsigned) currentTime.tv_usec); - const float w = 800.f; + float z = truncf((0.5f*w*rand()/RAND_MAX)+1.f); + float v = truncf((0.5f*w*rand()/RAND_MAX)+1.f); + float x = truncf((w-z)*rand()/RAND_MAX); + float y = truncf((h-v)*rand()/RAND_MAX); - vkvg_surface_clear(surf); + vkvg_rectangle(ctx, x, y, z, v); +}*/ +static vkvg_fill_rule_t fill_rule = VKVG_FILL_RULE_NON_ZERO; +static float line_width = 5.f; +static float shape_size = 0.1f; - VkvgContext ctx = vkvg_create(surf); - vkvg_set_source_rgba(ctx,0,0,0,1); - vkvg_paint(ctx); +void _shape_fill(shape_t shape){ + vkvg_surface_clear(surf); + VkvgContext ctx = vkvg_create(surf); + vkvg_set_fill_rule(ctx, fill_rule); + for (uint32_t i=0; i<test_size; i++) { + draw_random_shape(ctx, shape, shape_size); + vkvg_fill(ctx); + } + vkvg_destroy(ctx); +} +void _shape_stroke(shape_t shape){ + vkvg_surface_clear (surf); + VkvgContext ctx = vkvg_create(surf); + vkvg_set_line_width (ctx, line_width); + vkvg_set_fill_rule(ctx, fill_rule); + for (uint32_t i=0; i<test_size; i++) { + draw_random_shape(ctx, shape, shape_size); + vkvg_stroke (ctx); + } + vkvg_destroy(ctx); +} +void _shape_fill_stroke(shape_t shape){ + vkvg_surface_clear(surf); + VkvgContext ctx = vkvg_create(surf); + vkvg_set_line_width (ctx, line_width); + vkvg_set_fill_rule(ctx, fill_rule); + for (uint32_t i=0; i<test_size; i++) { + draw_random_shape(ctx, shape, shape_size); + vkvg_fill_preserve(ctx); + vkvg_stroke(ctx); + } + vkvg_destroy(ctx); +} + +void rectangles_fill () { + _shape_fill(SHAPE_RECTANGLE); +} +void rectangles_stroke () { + _shape_stroke(SHAPE_RECTANGLE); +} +void rectangles_fill_stroke () { + _shape_fill_stroke(SHAPE_RECTANGLE); +} +void rounded_rects_fill () { + _shape_fill(SHAPE_ROUNDED_RECTANGLE); +} +void rounded_rects_stroke () { + _shape_stroke(SHAPE_ROUNDED_RECTANGLE); +} +void rounded_rects_fill_stroke () { + _shape_fill_stroke(SHAPE_ROUNDED_RECTANGLE); +} +void circles_fill () { + _shape_fill(SHAPE_CIRCLE); +} +void circles_stroke () { + _shape_stroke(SHAPE_CIRCLE); +} +void circles_fill_stroke () { + _shape_fill_stroke(SHAPE_CIRCLE); +} +void stars_fill () { + _shape_fill(SHAPE_STAR); +} +void stars_stroke () { + _shape_stroke(SHAPE_STAR); +} +void stars_fill_stroke () { + _shape_fill_stroke(SHAPE_STAR); +} +void random_fill () { + _shape_fill(SHAPE_RANDOM); +} +void random_stroke () { + _shape_stroke(SHAPE_RANDOM); +} +void random_fill_stroke () { + _shape_fill_stroke(SHAPE_RANDOM); +} - //vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_NON_ZERO); - //vkvg_set_line_width(ctx,10); +int main(int argc, char *argv[]) { - for (uint j=0;j<2;j++) { - for (uint i=0; i<test_size/2; i++) { - randomize_color(ctx); + PERFORM_TEST (rectangles_fill, argc, argv); + PERFORM_TEST (rectangles_stroke, argc, argv); + PERFORM_TEST (rectangles_fill_stroke, argc, argv); - float x = truncf(0.5f*w*rand()/RAND_MAX); - float y = truncf(0.5f*w*rand()/RAND_MAX); - float z = truncf((0.5f*w*rand()/RAND_MAX)+1.f); - float v = truncf((0.5f*w*rand()/RAND_MAX)+1.f); + PERFORM_TEST (rounded_rects_fill, argc, argv); + PERFORM_TEST (rounded_rects_stroke, argc, argv); + PERFORM_TEST (rounded_rects_fill_stroke, argc, argv); - vkvg_rectangle(ctx, x, y, z, v); - vkvg_fill(ctx); - } - vkvg_flush(ctx); - } - vkvg_destroy(ctx); -} + PERFORM_TEST (circles_fill, argc, argv); + PERFORM_TEST (circles_stroke, argc, argv); + PERFORM_TEST (circles_fill_stroke, argc, argv); -int main(int argc, char *argv[]) { + PERFORM_TEST (stars_fill, argc, argv); + PERFORM_TEST (stars_stroke, argc, argv); + PERFORM_TEST (stars_fill_stroke, argc, argv); - perform_test (test, 800, 600); + PERFORM_TEST (random_fill, argc, argv); + PERFORM_TEST (random_stroke, argc, argv); + PERFORM_TEST (random_fill_stroke, argc, argv); - return 0; + return 0; } diff --git a/tests/rect_fill.c b/tests/rect_fill.c index 3aae4c5..ab5785a 100644 --- a/tests/rect_fill.c +++ b/tests/rect_fill.c @@ -1,58 +1,42 @@ #include "test.h" void test(){ - //vkvg_surface_clear(surf); + vkvg_surface_clear(surf); - VkvgSurface surf2 = vkvg_surface_create (device,400,400); + VkvgContext ctx = vkvg_create(surf); - VkvgContext ctx = vkvg_create (surf2); + vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_NON_ZERO); - vkvg_set_source_rgba(ctx,0.0,1.,0.,1.0f); - vkvg_paint (ctx); - vkvg_destroy(ctx); + vkvg_set_source_rgba(ctx,0,0,1,0.5); + vkvg_rectangle(ctx,100,100,200,200); + vkvg_fill(ctx); + vkvg_rectangle(ctx,200,200,200,200); + vkvg_set_source_rgba(ctx,1,0,0,0.5); + vkvg_fill(ctx); - //vkvg_surface_write_to_png(surf2, "/home/jp/test.png"); - - ctx = vkvg_create(surf); - - /*vkvg_set_source_rgba(ctx,0,0,1,0.5); - - */ - - vkvg_translate(ctx, -150,-150); - - vkvg_set_source_surface(ctx, surf2, 200,200); - //vkvg_rectangle(ctx,10,10,300,300); - //vkvg_fill(ctx); - vkvg_paint(ctx); - - //vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD); - - /*vkvg_rotate(ctx,0.1f); - - vkvg_set_source_rgba(ctx,0,0,1,0.5); - vkvg_rectangle(ctx,100,100,200,200); - vkvg_fill(ctx); - + vkvg_destroy(ctx); +} +void test_evenodd(){ + vkvg_surface_clear(surf); - vkvg_set_source_rgba(ctx,1,0,0,0.5); - vkvg_rectangle(ctx,200,200,200,200); - vkvg_fill(ctx); + VkvgContext ctx = vkvg_create(surf); - vkvg_set_source_rgba(ctx,0,1,0,0.5); - vkvg_rectangle(ctx,500,500,200,200); - vkvg_fill(ctx);*/ + vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD); + vkvg_set_source_rgba(ctx,0,0,1,0.5); + vkvg_rectangle(ctx,100,100,200,200); + vkvg_fill(ctx); - vkvg_destroy(ctx); + vkvg_rectangle(ctx,200,200,200,200); + vkvg_set_source_rgba(ctx,1,0,0,0.5); + vkvg_fill(ctx); - vkvg_surface_destroy(surf2); + vkvg_destroy(ctx); } - int main(int argc, char *argv[]) { - perform_test (test, 1024, 768); - - return 0; + PERFORM_TEST (test, argc, argv); + PERFORM_TEST (test_evenodd, argc, argv); + return 0; } diff --git a/tests/save_restore.c b/tests/save_restore.c index 2024fef..834e88a 100644 --- a/tests/save_restore.c +++ b/tests/save_restore.c @@ -1,35 +1,33 @@ #include "test.h" void recurse_draw(VkvgContext ctx, int depth) { - depth++; - vkvg_save(ctx); + depth++; + vkvg_save(ctx); - vkvg_translate (ctx, 5,5); - vkvg_rectangle(ctx, depth,depth,200,200); - 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_stroke(ctx); + vkvg_translate (ctx, 5,5); + vkvg_rectangle(ctx, (float)depth,(float)depth,200,200); + 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_stroke(ctx); - if (depth < 20) - recurse_draw (ctx, depth); + if (depth < 20) + recurse_draw (ctx, depth); - vkvg_restore(ctx); + vkvg_restore(ctx); } void test(){ - VkvgContext ctx = vkvg_create(surf); + VkvgContext ctx = vkvg_create(surf); - recurse_draw(ctx, 0); + recurse_draw(ctx, 0); - vkvg_destroy(ctx); + vkvg_destroy(ctx); } int main(int argc, char *argv[]) { - - perform_test (test, 600, 800); - - return 0; + PERFORM_TEST (test, argc, argv); + return 0; } diff --git a/tests/simple_paint.c b/tests/simple_paint.c index 4f56a50..abc66ef 100644 --- a/tests/simple_paint.c +++ b/tests/simple_paint.c @@ -1,26 +1,55 @@ #include "test.h" -void test(){ - VkvgContext ctx = vkvg_create(surf); - vkvg_set_source_rgba(ctx,1,0,0,1); - vkvg_paint(ctx); - - /*vkvg_set_line_width(ctx, 5); - vkvg_set_source_rgba(ctx,0,1,0,1); - vkvg_rectangle(ctx,100,100,300,200); - vkvg_fill(ctx); - - vkvg_translate(ctx,300,100); - - vkvg_set_source_rgba(ctx,1,0,0,1); - vkvg_rectangle(ctx,100,100,300,200); - vkvg_stroke(ctx);*/ - vkvg_destroy(ctx); +void paint(){ + VkvgContext ctx = vkvg_create(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_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_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_source_rgba(ctx,1,0,0,1); + vkvg_rectangle(ctx,100,100,300,200); + vkvg_paint(ctx); + vkvg_destroy(ctx); +} +//TODO:test failed: full screen paint instead of rotated rect +void paint_rect_with_rotation(){ + VkvgContext ctx = vkvg_create(surf); + vkvg_rotate(ctx, 45); + vkvg_set_source_rgba(ctx,1,0,0,1); + vkvg_rectangle(ctx,100,100,300,200); + vkvg_paint(ctx); + vkvg_destroy(ctx); +} +void paint_rect_with_scale(){ + VkvgContext ctx = vkvg_create(surf); + vkvg_scale (ctx, 0.2f,0.2f); + vkvg_set_source_rgba(ctx,1,0,0,1); + vkvg_rectangle(ctx,100,100,300,200); + vkvg_paint(ctx); + vkvg_destroy(ctx); } - int main(int argc, char *argv[]) { - - perform_test (test, 1024, 768); - - return 0; + PERFORM_TEST (paint, argc, argv); + 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); + return 0; } diff --git a/tests/stroke.c b/tests/stroke.c index 028e9bc..648da83 100644 --- a/tests/stroke.c +++ b/tests/stroke.c @@ -1,61 +1,59 @@ #include "test.h" void test(){ - VkvgContext ctx = vkvg_create(surf); + VkvgContext ctx = vkvg_create(surf); - vkvg_set_line_width(ctx, 1); - vkvg_set_source_rgba(ctx,1,0,0,1); - vkvg_move_to(ctx,200.5,200.5); - vkvg_line_to(ctx,400.5,200.5); - vkvg_line_to(ctx,400.5,400.5); - vkvg_line_to(ctx,200.5,400.5); - vkvg_close_path(ctx); - vkvg_stroke(ctx); + vkvg_set_line_width(ctx, 1); + vkvg_set_source_rgba(ctx,1,0,0,1); + vkvg_move_to(ctx,200.5f,200.5f); + vkvg_line_to(ctx,400.5f,200.5f); + vkvg_line_to(ctx,400.5f,400.5f); + vkvg_line_to(ctx,200.5f,400.5f); + vkvg_close_path(ctx); + vkvg_stroke(ctx); - vkvg_set_source_rgba(ctx,0,1,0,1); - vkvg_move_to(ctx,300.5,300.5); - vkvg_line_to(ctx,500.5,300.5); - vkvg_line_to(ctx,500.5,500.5); - vkvg_line_to(ctx,300.5,500.5); - vkvg_stroke(ctx); + vkvg_set_source_rgba(ctx,0,1,0,1); + vkvg_move_to(ctx,300.5f,300.5f); + vkvg_line_to(ctx,500.5f,300.5f); + vkvg_line_to(ctx,500.5f,500.5f); + vkvg_line_to(ctx,300.5f,500.5f); + vkvg_stroke(ctx); - //vkvg_set_source_rgba(ctx,0,0.2,0.35,1); - //vkvg_fill(ctx); + //vkvg_set_source_rgba(ctx,0,0.2,0.35,1); + //vkvg_fill(ctx); - vkvg_set_source_rgba(ctx,0.5,1,0,1); - vkvg_move_to(ctx,320.5,320.5); - vkvg_line_to(ctx,520.5,320.5); - vkvg_line_to(ctx,520.5,520.5); - vkvg_line_to(ctx,320.5,520.5); - //vkvg_close_path(ctx); - vkvg_stroke(ctx); - vkvg_set_line_width(ctx, 40); - vkvg_set_source_rgba(ctx,0.5,0.6,1,1.0); - vkvg_move_to(ctx,700,475); - vkvg_line_to(ctx,400,475); - vkvg_stroke(ctx); - vkvg_set_source_rgba(ctx,0,0.5,0.5,0.5); - vkvg_move_to(ctx,300,200); - vkvg_arc(ctx, 200,200,100,0, M_PI); - vkvg_stroke(ctx); + vkvg_set_source_rgba(ctx,0.5f,1,0,1); + vkvg_move_to(ctx,320.5f,320.5f); + vkvg_line_to(ctx,520.5f,320.5f); + vkvg_line_to(ctx,520.5f,520.5f); + vkvg_line_to(ctx,320.5f,520.5f); + //vkvg_close_path(ctx); + vkvg_stroke(ctx); + vkvg_set_line_width(ctx, 40); + vkvg_set_source_rgba(ctx,0.5f,0.6f,1,1.0f); + vkvg_move_to(ctx,700,475); + vkvg_line_to(ctx,400,475); + vkvg_stroke(ctx); + vkvg_set_source_rgba(ctx,0,0.5f,0.5f,0.5f); + vkvg_move_to(ctx,300,200); + vkvg_arc(ctx, 200,200,100,0, M_PIF); + vkvg_stroke(ctx); - vkvg_set_line_width(ctx, 20); - vkvg_set_source_rgba(ctx,0.1,0.1,0.1,0.5); - vkvg_move_to(ctx,100,60); - vkvg_line_to(ctx,400,600); - vkvg_stroke(ctx); + vkvg_set_line_width(ctx, 20); + vkvg_set_source_rgba(ctx,0.1f,0.1f,0.1f,0.5f); + vkvg_move_to(ctx,100,60); + vkvg_line_to(ctx,400,600); + vkvg_stroke(ctx); - vkvg_set_source_rgba(ctx,1,1,1,1); - vkvg_set_line_width(ctx, 1); - vkvg_rectangle(ctx,600.5,200.5,100,60); - vkvg_stroke(ctx); + vkvg_set_source_rgba(ctx,1,1,1,1); + vkvg_set_line_width(ctx, 1); + vkvg_rectangle(ctx,600.5f,200.5f,100,60); + vkvg_stroke(ctx); - vkvg_destroy(ctx); + vkvg_destroy(ctx); } int main(int argc, char *argv[]) { - - perform_test (test, 1024, 768); - - return 0; + PERFORM_TEST (test, argc, argv); + return 0; } diff --git a/tests/svg.c b/tests/svg.c index 37c3f28..d004302 100644 --- a/tests/svg.c +++ b/tests/svg.c @@ -3,125 +3,50 @@ #include "string.h" //for nanosvg //#define NANOSVG_IMPLEMENTATION // Expands implementation #include "nanosvg.h" + static float rotation = 0.f; static const char* path = "data/tiger.svg"; //static const char* path = "data/vkvg.svg"; //static const char* path = "data/testPiece.svg"; void test_svg_surface() { - VkvgSurface svgSurf = vkvg_surface_create_from_svg(device, path); + VkvgSurface svgSurf = vkvg_surface_create_from_svg(device, path); - VkvgContext ctx = vkvg_create(surf); + VkvgContext ctx = vkvg_create(surf); - vkvg_set_source_rgb(ctx,0,0,0); - vkvg_paint(ctx); + vkvg_set_source_rgb(ctx,0,0,0); + vkvg_paint(ctx); - vkvg_set_source_surface(ctx, svgSurf, 0,0); - vkvg_paint(ctx); + vkvg_set_source_surface(ctx, svgSurf, 0,0); + vkvg_paint(ctx); - vkvg_destroy(ctx); - vkvg_surface_destroy(svgSurf); + vkvg_destroy(ctx); + vkvg_surface_destroy(svgSurf); } void test_nsvg() { - NSVGimage* svg = nsvg_load_file(device, path); - - VkvgContext ctx = vkvg_create(surf); - //vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD); - vkvg_set_source_rgba(ctx,0.9f,1.0,1.0,1); - vkvg_paint(ctx); - - vkvg_scale(ctx,1.0f,1.0f); - //vkvg_render_svg(ctx, svg, "wq"); - vkvg_render_svg(ctx, svg, NULL); - - vkvg_destroy(ctx); - - nsvg_destroy(svg); -} - -void test_svg () { - rotation+=0.01f; - - vkvg_matrix_t mat; - vkvg_matrix_init_translate (&mat, 512,400); - vkvg_matrix_rotate(&mat,rotation); - vkvg_matrix_translate(&mat,-512,-400); - - VkvgContext ctx = vkvg_create(surf); - vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_NON_ZERO); - vkvg_set_source_rgba(ctx,1.0,1.0,1.0,1); - vkvg_paint(ctx); + NSVGimage* svg = nsvg_load_file(device, path); + if (svg == NULL) { + fprintf (stderr, "svg file not found: %s", path); + return; + } - //vkvg_set_matrix(ctx,&mat); + VkvgContext ctx = vkvg_create(surf); + vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD); + vkvg_set_source_rgba(ctx,0.9f,1.0,1.0f,1); + vkvg_paint(ctx); - NSVGimage* svg; - NSVGshape* shape; - NSVGpath* path; - //svg = nsvgParseFromFile("/mnt/data/images/svg/tux.svg", "px", 96); - //svg = nsvgParseFromFile("/mnt/data/images/svg/world.svg", "px", 96); - svg = nsvgParseFromFile("data/tiger.svg", "px", 96); - //svg = nsvgParseFromFile("/mnt/data/images/svg/koch_curve.svg", "px", 96); - //svg = nsvgParseFromFile("/mnt/data/images/svg/diamond1.svg", "px", 96); - //svg = nsvgParseFromFile("/mnt/data/images/svg/diamond2.svg", "px", 96); - //svg = nsvgParseFromFile("/home/jp/yahweh-protosinaitic.svg", "px", 96); - //svg = nsvgParseFromFile("/mnt/data/images/svg/WMD-biological.svg", "px", 96); - //svg = nsvgParseFromFile("/mnt/data/images/svg/Skull_and_crossbones.svg", "px", 96); - //svg = nsvgParseFromFile("/mnt/data/images/svg/IconAlerte.svg", "px", 96); - //svg = nsvgParseFromFile("/mnt/data/images/svg/Svg_example4.svg", "px", 96); + vkvg_scale(ctx,1.0f,1.0f); + //vkvg_render_svg(ctx, svg, "wq"); - //vkvg_scale(ctx, 3,3); - vkvg_set_source_rgba(ctx,0.0,0.0,0.0,1); + vkvg_render_svg(ctx, svg, NULL); - for (shape = svg->shapes; shape != NULL; shape = shape->next) { - vkvg_new_path(ctx); + vkvg_destroy(ctx); - float o = shape->opacity; - - vkvg_set_line_width(ctx, shape->strokeWidth); - - for (path = shape->paths; path != NULL; path = path->next) { - float* p = path->pts; - vkvg_move_to(ctx, p[0],p[1]); - for (int i = 1; i < path->npts-2; i += 3) { - p = &path->pts[i*2]; - vkvg_curve_to(ctx, p[0],p[1], p[2],p[3], p[4],p[5]); - } - if (path->closed) - vkvg_close_path(ctx); - } - - if (shape->fill.type == NSVG_PAINT_COLOR) - _svg_set_color(ctx, shape->fill.color, o); - else if (shape->fill.type == NSVG_PAINT_LINEAR_GRADIENT){ - NSVGgradient* g = shape->fill.gradient; - _svg_set_color(ctx, g->stops[0].color, o); - } - - if (shape->fill.type != NSVG_PAINT_NONE){ - if (shape->stroke.type == NSVG_PAINT_NONE){ - vkvg_fill(ctx); - continue; - } - vkvg_fill_preserve (ctx); - } - - if (shape->stroke.type == NSVG_PAINT_COLOR) - _svg_set_color(ctx, shape->stroke.color, o); - else if (shape->stroke.type == NSVG_PAINT_LINEAR_GRADIENT){ - NSVGgradient* g = shape->stroke.gradient; - _svg_set_color(ctx, g->stops[0].color, o); - } - - vkvg_stroke(ctx); - } - - nsvgDelete(svg); - vkvg_destroy(ctx); + nsvg_destroy(svg); } int main(int argc, char *argv[]) { - - perform_test (test_nsvg, 1024, 800); - return 0; + PERFORM_TEST (test_nsvg, argc, argv); + return 0; } diff --git a/tests/test1.c b/tests/test1.c index baa1f9b..5fb17bf 100644 --- a/tests/test1.c +++ b/tests/test1.c @@ -23,331 +23,355 @@ #include "test.h" void cairo_test_fill_rule (VkvgContext cr){ - vkvg_set_line_width (cr, 6); + vkvg_set_line_width (cr, 6); - //vkvg_scale(cr,3,3); - vkvg_set_source_rgba(cr,1,0,0,1); - vkvg_move_to(cr,50,150); - vkvg_rel_line_to(cr,50,70); - vkvg_rel_line_to(cr,50,0); - vkvg_rel_line_to(cr,50,-70); - vkvg_rel_line_to(cr,0,-60); - vkvg_rel_line_to(cr,-50,-30); - vkvg_rel_line_to(cr,-50,0); - vkvg_rel_line_to(cr,-50,30); - vkvg_close_path(cr); + //vkvg_scale(cr,3,3); + vkvg_set_source_rgba(cr,1,0,0,1); + vkvg_move_to(cr,50,150); + vkvg_rel_line_to(cr,50,70); + vkvg_rel_line_to(cr,50,0); + vkvg_rel_line_to(cr,50,-70); + vkvg_rel_line_to(cr,0,-60); + vkvg_rel_line_to(cr,-50,-30); + vkvg_rel_line_to(cr,-50,0); + vkvg_rel_line_to(cr,-50,30); + vkvg_close_path(cr); // vkvg_set_line_join(cr,VKVG_LINE_JOIN_ROUND); - vkvg_set_source_rgb (cr, 0, 0.7, 0); - vkvg_rectangle (cr, 12, 12, 232, 70); - //vkvg_stroke (cr); + vkvg_set_source_rgb (cr, 0, 0.7f, 0); + vkvg_rectangle (cr, 12, 12, 232, 70); + //vkvg_stroke (cr); // vkvg_new_sub_path (cr); - vkvg_arc (cr, 64, 64, 40, 0, (float)M_PI*2.f); - //vkvg_close_path(cr); + vkvg_arc (cr, 64, 64, 40, 0, M_PIF*2.f); + //vkvg_close_path(cr); - vkvg_new_sub_path (cr); - vkvg_arc_negative (cr, 192, 64, 40, (float)M_PI*2.f, 0); - //vkvg_close_path(cr); + vkvg_new_sub_path (cr); + vkvg_arc_negative (cr, 192, 64, 40, M_PIF*2.f, 0); + //vkvg_close_path(cr); - //vkvg_rectangle (cr, 30, 30, 20, 200); - //vkvg_rectangle (cr, 130, 30, 20, 200); - //vkvg_set_fill_rule (cr, vkvg_FILL_RULE_EVEN_ODD); + //vkvg_rectangle (cr, 30, 30, 20, 200); + //vkvg_rectangle (cr, 130, 30, 20, 200); + //vkvg_set_fill_rule (cr, vkvg_FILL_RULE_EVEN_ODD); - vkvg_fill_preserve(cr); + vkvg_fill_preserve(cr); - vkvg_set_source_rgb (cr, 0, 0, 0); - vkvg_stroke (cr); + vkvg_set_source_rgb (cr, 0, 0, 0); + vkvg_stroke (cr); } void cairo_test_text (VkvgContext cr) { - vkvg_text_extents_t extents; + vkvg_text_extents_t extents; + vkvg_font_extents_t ft; - const char *utf8 = "vkvg"; - float x,y; + //vkvg_set_fill_rule(cr, VKVG_FILL_RULE_NON_ZERO); + const char *utf8 = "vkvg|Ãp"; + float x,y; - vkvg_select_font_face (cr, "times"); - vkvg_set_font_size (cr, 100.0); - vkvg_text_extents (cr, utf8, &extents); - vkvg_set_source_rgb(cr,0,0,0); + //vkvg_select_font_face (cr, "times"); + vkvg_select_font_face (cr, "linux biolinum keyboard"); + vkvg_set_font_size (cr, 50); + vkvg_font_extents(cr, &ft); + vkvg_text_extents (cr, utf8, &extents); + vkvg_set_source_rgb(cr,0,0,0); - x=25.0; - y=150.0; + x=25.0f; + y=150.0f; - vkvg_move_to (cr, x,y); - vkvg_show_text (cr, utf8); + vkvg_move_to (cr, x,y); + vkvg_show_text (cr, utf8); - /* draw helping lines */ - vkvg_set_source_rgba (cr, 1, 0.2, 0.2, 0.6); - vkvg_set_line_width (cr, 6.0); - vkvg_new_path(cr); - vkvg_arc (cr, x, y, 10.0, 0, 2*M_PI); - vkvg_fill (cr); - vkvg_move_to (cr, x,y); - vkvg_rel_line_to (cr, 0, -extents.height); - vkvg_rel_line_to (cr, extents.width, 0); - vkvg_rel_line_to (cr, extents.x_bearing, -extents.y_bearing); - vkvg_stroke (cr); + /* draw helping lines */ + vkvg_set_source_rgba (cr, 0, 0.2f, 0.2f, 0.6f); + vkvg_set_line_width (cr, 1.0f); + vkvg_new_path(cr); + vkvg_arc (cr, x, y, 10.0f, 0, 2.f*M_PIF); + vkvg_fill (cr); + vkvg_move_to (cr, x,y); + //vkvg_rel_line_to (cr, 0, -30); + vkvg_rel_line_to (cr, 0, -ft.ascent); + vkvg_rel_line_to (cr, extents.width, 0); + vkvg_rel_line_to (cr, extents.x_bearing, -extents.y_bearing); + + vkvg_stroke (cr); + + vkvg_move_to (cr, x,y); + vkvg_rel_line_to (cr, extents.width, 0); + vkvg_set_source_rgba (cr, 0.0, 0.0, 0.9f, 0.6f); + + vkvg_stroke (cr); + + vkvg_move_to (cr, x,y); + vkvg_rel_line_to (cr, 0, -ft.descent); + vkvg_rel_line_to (cr, extents.width, 0); + vkvg_set_source_rgba (cr, 0.9f, 0.0, 0.0, 0.6f); + + vkvg_stroke (cr); + + vkvg_move_to (cr, x-10,y-ft.ascent); + vkvg_rel_line_to (cr, 0, ft.height); + vkvg_set_source_rgba (cr, 0.0, 0.1f, 0.0, 0.6f); + + vkvg_stroke (cr); } void cairo_test_clip (VkvgContext cr){ - vkvg_arc (cr, 128.0, 128.0, 76.8, 0, 2 * M_PI); - vkvg_clip (cr); - //vkvg_new_path (cr); /* current path is not - // consumed by vkvg_clip() */ - vkvg_set_source_rgba(cr, 0, 0, 0, 1); - vkvg_rectangle (cr, 0, 0, 256, 256); - vkvg_fill (cr); - vkvg_set_source_rgba (cr, 0, 1, 0, 1); - vkvg_move_to (cr, -100, -100); - vkvg_line_to (cr, 256, 256); - vkvg_move_to (cr, 356, -100); - vkvg_line_to (cr, 0, 256); - vkvg_set_line_width (cr, 10.0); - vkvg_stroke (cr); + vkvg_arc (cr, 128.0f, 128.0f, 76.8f, 0, 2.f * M_PIF); + vkvg_clip (cr); + //vkvg_new_path (cr); /* current path is not + // consumed by vkvg_clip() */ + vkvg_set_source_rgba(cr, 0, 0, 0, 1); + vkvg_rectangle (cr, 0, 0, 256, 256); + vkvg_fill (cr); + vkvg_set_source_rgba (cr, 0, 1, 0, 1); + vkvg_move_to (cr, -100, -100); + vkvg_line_to (cr, 256, 256); + vkvg_move_to (cr, 356, -100); + vkvg_line_to (cr, 0, 256); + vkvg_set_line_width (cr, 10.0f); + vkvg_stroke (cr); } void cairo_test_curves (VkvgContext cr){ - float x=25.6, y=128.0; - float x1=102.4, y1=230.4, - x2=153.6, y2=25.6, - x3=230.4, y3=128.0; + float x=25.6f, y=128.0f; + float x1=102.4f, y1=230.4f, + x2=153.6f, y2=25.6f, + x3=230.4f, y3=128.0f; - vkvg_set_source_rgb (cr, 0, 0, 0); - vkvg_move_to (cr, x, y); - vkvg_curve_to (cr, x1, y1, x2, y2, x3, y3); + vkvg_set_source_rgb (cr, 0, 0, 0); + vkvg_move_to (cr, x, y); + vkvg_curve_to (cr, x1, y1, x2, y2, x3, y3); - vkvg_set_line_width (cr, 10.0); - vkvg_stroke (cr); + vkvg_set_line_width (cr, 10.0f); + vkvg_stroke (cr); - vkvg_set_source_rgba (cr, 1, 0.2, 0.2, 0.6); - vkvg_set_line_width (cr, 6.0); - vkvg_move_to (cr,x,y); vkvg_line_to (cr,x1,y1); - vkvg_move_to (cr,x2,y2); vkvg_line_to (cr,x3,y3); - vkvg_stroke (cr); + vkvg_set_source_rgba (cr, 1, 0.2f, 0.2f, 0.6f); + vkvg_set_line_width (cr, 6.0f); + vkvg_move_to (cr,x,y); vkvg_line_to (cr,x1,y1); + vkvg_move_to (cr,x2,y2); vkvg_line_to (cr,x3,y3); + vkvg_stroke (cr); } void cairo_test_rounded_rect (VkvgContext cr) { - /* a custom shape that could be wrapped in a function */ - float x0 = 25.6, /* parameters like vkvg_rectangle */ - y0 = 25.6, - rect_width = 204.8, - rect_height = 204.8, - radius = 102.4; /* and an approximate curvature radius */ + /* a custom shape that could be wrapped in a function */ + float x0 = 25.6f, /* parameters like vkvg_rectangle */ + y0 = 25.6f, + rect_width = 204.8f, + rect_height = 204.8f, + radius = 102.4f; /* and an approximate curvature radius */ - float x1,y1; + 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); + 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.5, 0.5, 1); - vkvg_fill_preserve (cr); - vkvg_set_source_rgba (cr, 0.5, 0, 0, 0.5); - vkvg_set_line_width (cr, 10.0); - vkvg_stroke (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); } void cairo_test_fill_and_stroke2 (VkvgContext cr){ - vkvg_move_to (cr, 128.0, 25.6); - vkvg_line_to (cr, 230.4, 230.4); - vkvg_rel_line_to (cr, -102.4, 0.0); - vkvg_curve_to (cr, 51.2, 230.4, 51.2, 128.0, 128.0, 128.0); - vkvg_close_path (cr); + vkvg_move_to (cr, 128.0f, 25.6f); + vkvg_line_to (cr, 230.4f, 230.4f); + vkvg_rel_line_to (cr, -102.4f, 0.0); + vkvg_curve_to (cr, 51.2f, 230.4f, 51.2f, 128.0f, 128.0f, 128.0f); + vkvg_close_path (cr); - vkvg_move_to (cr, 64.0, 25.6); - vkvg_rel_line_to (cr, 51.2, 51.2); - vkvg_rel_line_to (cr, -51.2, 51.2); - vkvg_rel_line_to (cr, -51.2, -51.2); - vkvg_close_path (cr); + vkvg_move_to (cr, 64.0f, 25.6f); + vkvg_rel_line_to (cr, 51.2f, 51.2f); + vkvg_rel_line_to (cr, -51.2f, 51.2f); + vkvg_rel_line_to (cr, -51.2f, -51.2f); + vkvg_close_path (cr); - /*vkvg_translate(cr,100,100); - vkvg_move_to (cr, 100, 100); - vkvg_line_to(cr,300,300); - vkvg_line_to(cr,100,300);*/ + /*vkvg_translate(cr,100,100); + vkvg_move_to (cr, 100, 100); + vkvg_line_to(cr,300,300); + vkvg_line_to(cr,100,300);*/ - vkvg_set_line_width (cr, 10.0); - vkvg_set_source_rgb (cr, 0, 0, 1); - vkvg_fill_preserve (cr); - vkvg_set_source_rgb (cr, 0, 0, 0); - vkvg_stroke (cr); + vkvg_set_line_width (cr, 10.0f); + vkvg_set_source_rgb (cr, 0, 0, 1); + vkvg_fill_preserve (cr); + vkvg_set_source_rgb (cr, 0, 0, 0); + vkvg_stroke (cr); } void cairo_print_arc_neg (VkvgContext cr){ - float xc = 128.0; - float yc = 128.0; - float radius = 100.0; - float angle1 = 45.0 * (M_PI/180.0); /* angles are specified */ - float angle2 = 180.0 * (M_PI/180.0); /* in radians */ + float xc = 128.0f; + float yc = 128.0f; + float radius = 100.0f; + float angle1 = 45.0f * (M_PIF/180.0f); /* angles are specified */ + float angle2 = 180.0f * (M_PIF/180.0f); /* in radians */ - vkvg_set_source_rgba(cr, 0, 0, 0, 1); - vkvg_set_line_width (cr, 5.0); - vkvg_arc_negative (cr, xc, yc, radius, angle1, angle2); - vkvg_stroke (cr); + vkvg_set_source_rgba(cr, 0, 0, 0, 1); + vkvg_set_line_width (cr, 5.0f); + vkvg_arc_negative (cr, xc, yc, radius, angle1, angle2); + vkvg_stroke (cr); - /* draw helping lines */ - vkvg_set_source_rgba (cr, 1, 0.2, 0.2, 0.6); - vkvg_set_line_width (cr, 10.0); + /* draw helping lines */ + vkvg_set_source_rgba (cr, 1, 0.2f, 0.2f, 0.6f); + vkvg_set_line_width (cr, 10.0f); - vkvg_arc (cr, xc, yc, 10.0, 0, 2*M_PI); - vkvg_fill (cr); + vkvg_arc (cr, xc, yc, 10.0f, 0, 2.f*M_PIF); + vkvg_fill (cr); - vkvg_arc (cr, xc, yc, radius, angle1, angle1); - vkvg_line_to (cr, xc, yc); - vkvg_arc (cr, xc, yc, radius, angle2, angle2); - //vkvg_line_to (cr, xc, yc); - vkvg_stroke (cr); + vkvg_arc (cr, xc, yc, radius, angle1, angle1); + vkvg_line_to (cr, xc, yc); + vkvg_arc (cr, xc, yc, radius, angle2, angle2); + //vkvg_line_to (cr, xc, yc); + vkvg_stroke (cr); } void cairo_test_line_caps (VkvgContext cr) { - vkvg_set_source_rgb (cr, 0, 0, 0); - vkvg_set_line_width (cr, 30.0); - vkvg_set_line_cap (cr, VKVG_LINE_CAP_BUTT); /* default */ - vkvg_move_to (cr, 64.0, 50.0); vkvg_line_to (cr, 64.0, 200.0); - vkvg_stroke (cr); - vkvg_set_line_cap (cr, VKVG_LINE_CAP_ROUND); - vkvg_move_to (cr, 128.0, 50.0); vkvg_line_to (cr, 128.0, 200.0); - vkvg_stroke (cr); - vkvg_set_line_cap (cr, VKVG_LINE_CAP_SQUARE); - vkvg_move_to (cr, 192.0, 50.0); vkvg_line_to (cr, 192.0, 200.0); - vkvg_stroke (cr); + vkvg_set_source_rgb (cr, 0, 0, 0); + vkvg_set_line_width (cr, 30.0f); + vkvg_set_line_cap (cr, VKVG_LINE_CAP_BUTT); /* default */ + vkvg_move_to (cr, 64.0f, 50.0f); vkvg_line_to (cr, 64.0f, 200.0f); + vkvg_stroke (cr); + vkvg_set_line_cap (cr, VKVG_LINE_CAP_ROUND); + vkvg_move_to (cr, 128.0f, 50.0f); vkvg_line_to (cr, 128.0f, 200.0f); + vkvg_stroke (cr); + vkvg_set_line_cap (cr, VKVG_LINE_CAP_SQUARE); + vkvg_move_to (cr, 192.0f, 50.0f); vkvg_line_to (cr, 192.0f, 200.0f); + vkvg_stroke (cr); - /* draw helping lines */ - vkvg_set_source_rgb (cr, 1, 0.2, 0.2); - vkvg_set_line_width (cr, 2.56); - vkvg_move_to (cr, 64.0, 50.0); vkvg_line_to (cr, 64.0, 200.0); - vkvg_move_to (cr, 128.0, 50.0); vkvg_line_to (cr, 128.0, 200.0); - vkvg_move_to (cr, 192.0, 50.0); vkvg_line_to (cr, 192.0, 200.0); - vkvg_stroke (cr); + /* draw helping lines */ + vkvg_set_source_rgb (cr, 1, 0.2f, 0.2f); + vkvg_set_line_width (cr, 2.56f); + vkvg_move_to (cr, 64.0f, 50.0f); vkvg_line_to (cr, 64.0f, 200.0f); + vkvg_move_to (cr, 128.0f, 50.0f); vkvg_line_to (cr, 128.0f, 200.0f); + vkvg_move_to (cr, 192.0f, 50.0f); vkvg_line_to (cr, 192.0f, 200.0f); + vkvg_stroke (cr); } void cairo_test_line_joins (VkvgContext cr) { - vkvg_set_source_rgb (cr, 0, 0, 0); - vkvg_set_line_width (cr, 40.96); - vkvg_move_to (cr, 76.8, 84.48); - vkvg_rel_line_to (cr, 51.2, -51.2); - vkvg_rel_line_to (cr, 51.2, 51.2); - vkvg_set_line_join (cr, VKVG_LINE_JOIN_MITER); /* default */ - vkvg_stroke (cr); + vkvg_set_source_rgb (cr, 0, 0, 0); + vkvg_set_line_width (cr, 40.96f); + vkvg_move_to (cr, 76.8f, 84.48f); + vkvg_rel_line_to (cr, 51.2f, -51.2f); + vkvg_rel_line_to (cr, 51.2f, 51.2f); + vkvg_set_line_join (cr, VKVG_LINE_JOIN_MITER); /* default */ + vkvg_stroke (cr); - vkvg_move_to (cr, 76.8, 161.28); - vkvg_rel_line_to (cr, 51.2, -51.2); - vkvg_rel_line_to (cr, 51.2, 51.2); - vkvg_set_line_join (cr, VKVG_LINE_JOIN_BEVEL); - vkvg_stroke (cr); + vkvg_move_to (cr, 76.8f, 161.28f); + vkvg_rel_line_to (cr, 51.2f, -51.2f); + vkvg_rel_line_to (cr, 51.2f, 51.2f); + vkvg_set_line_join (cr, VKVG_LINE_JOIN_BEVEL); + vkvg_stroke (cr); - vkvg_move_to (cr, 76.8, 238.08); - vkvg_rel_line_to (cr, 51.2, -51.2); - vkvg_rel_line_to (cr, 51.2, 51.2); - vkvg_set_line_join (cr, VKVG_LINE_JOIN_ROUND); - vkvg_stroke (cr); + vkvg_move_to (cr, 76.8f, 238.08f); + vkvg_rel_line_to (cr, 51.2f, -51.2f); + vkvg_rel_line_to (cr, 51.2f, 51.2f); + vkvg_set_line_join (cr, VKVG_LINE_JOIN_ROUND); + vkvg_stroke (cr); } void cairo_print_arc (VkvgContext cr) { - float xc = 128.0; - float yc = 128.0; - float radius = 100.0; - float angle1 = 45.0 * (M_PI/180.0); /* angles are specified */ - float angle2 = 180.0 * (M_PI/180.0); /* in radians */ + float xc = 128.0f; + float yc = 128.0f; + float radius = 100.0f; + float angle1 = 45.0f * (M_PIF/180.0f); /* angles are specified */ + float angle2 = 180.0f * (M_PIF/180.0f); /* in radians */ - vkvg_set_source_rgba(cr, 0, 0, 0, 1); - vkvg_set_line_width (cr, 10.0); - vkvg_arc (cr, xc, yc, radius, angle1, angle2); - vkvg_stroke (cr); + vkvg_set_source_rgba(cr, 0, 0, 0, 1); + vkvg_set_line_width (cr, 10.0f); + vkvg_arc (cr, xc, yc, radius, angle1, angle2); + vkvg_stroke (cr); - /* draw helping lines */ - vkvg_set_source_rgba(cr, 1, 0.2, 0.2, 0.6); - vkvg_set_line_width (cr, 6.0); + /* draw helping lines */ + vkvg_set_source_rgba(cr, 1, 0.2f, 0.2f, 0.6f); + vkvg_set_line_width (cr, 6.0f); - vkvg_arc (cr, xc, yc, 10.0, 0, 2*M_PI); - vkvg_fill (cr); + vkvg_arc (cr, xc, yc, 10.0f, 0, 2.f*M_PIF); + vkvg_fill (cr); - vkvg_arc (cr, xc, yc, radius, angle1, angle1); - vkvg_line_to (cr, xc, yc); - vkvg_arc (cr, xc, yc, radius, angle2, angle2); - vkvg_stroke (cr); + vkvg_arc (cr, xc, yc, radius, angle1, angle1); + vkvg_line_to (cr, xc, yc); + vkvg_arc (cr, xc, yc, radius, angle2, angle2); + vkvg_stroke (cr); } static float rotation = 0.f; void cairo_tests () { - rotation+=0.01f; + rotation+=0.002f; - vkvg_matrix_t mat; - vkvg_matrix_init_translate (&mat, 512,400); - vkvg_matrix_rotate(&mat,rotation); - vkvg_matrix_scale(&mat,zoom,zoom); - vkvg_matrix_translate(&mat,-512.f + panX,-400.f +panY); + vkvg_matrix_t mat; + vkvg_matrix_init_translate (&mat, 512,400); + vkvg_matrix_rotate(&mat,rotation); + vkvg_matrix_scale(&mat,zoom,zoom); + vkvg_matrix_translate(&mat,-512.f + panX,-400.f +panY); - 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); + 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_matrix(ctx,&mat); + //vkvg_set_matrix(ctx,&mat); - cairo_print_arc(ctx); + cairo_print_arc(ctx); - vkvg_translate(ctx,200,0); - cairo_test_fill_rule(ctx); + vkvg_translate(ctx,200,0); + cairo_test_fill_rule(ctx); - vkvg_translate(ctx,250,0); - cairo_test_rounded_rect(ctx); + vkvg_translate(ctx,250,0); + cairo_test_rounded_rect(ctx); - vkvg_translate(ctx,-450,250); - cairo_test_fill_and_stroke2(ctx); + vkvg_translate(ctx,-450,250); + cairo_test_fill_and_stroke2(ctx); - vkvg_translate(ctx,250,0); - cairo_print_arc_neg(ctx); + vkvg_translate(ctx,250,0); + cairo_print_arc_neg(ctx); - vkvg_translate(ctx,250,0); - cairo_test_text(ctx); + vkvg_translate(ctx,250,0); + cairo_test_text(ctx); - vkvg_translate(ctx,-500,250); - cairo_test_curves(ctx); + vkvg_translate(ctx,-500,250); + cairo_test_curves(ctx); - vkvg_translate(ctx,250,0); - cairo_test_line_joins(ctx); + vkvg_translate(ctx,250,0); + cairo_test_line_joins(ctx); - vkvg_translate(ctx,250,0); - cairo_test_line_caps(ctx); + vkvg_translate(ctx,250,0); + cairo_test_line_caps(ctx); - vkvg_destroy(ctx); + vkvg_destroy(ctx); } int main(int argc, char *argv[]) { - - perform_test (cairo_tests, 1024, 768); - return 0; + PERFORM_TEST (cairo_tests, argc, argv); + return 0; } diff --git a/tests/text.c b/tests/text.c index a7b46e5..c39db43 100644 --- a/tests/text.c +++ b/tests/text.c @@ -3,160 +3,161 @@ static const char* txt = "The quick brown fox jumps over the lazy dog"; void print(VkvgContext ctx, float penY, uint32_t size) { - vkvg_set_font_size(ctx,size); - vkvg_move_to(ctx, 10,penY); - vkvg_show_text (ctx,txt); + vkvg_set_font_size(ctx,size); + vkvg_move_to(ctx, 10,penY); + vkvg_show_text (ctx,txt); } void test2() { - VkvgContext ctx = vkvg_create(surf); + VkvgContext ctx = vkvg_create(surf); - vkvg_color_t bg = {0.0,0.0,0.0,1}; - vkvg_color_t fg = {1.0,1.0,1.0,1}; + vkvg_color_t bg = {0.0,0.0,0.0,1}; + vkvg_color_t fg = {1.0f,1.0f,1.0f,1}; - vkvg_set_source_rgba(ctx,bg.r,bg.g,bg.b,bg.a); - vkvg_paint(ctx); - vkvg_set_source_rgba(ctx,fg.r,fg.g,fg.b,fg.a); - //vkvg_select_font_face(ctx, "droid"); - vkvg_select_font_face(ctx, "times"); + vkvg_set_source_rgba(ctx,bg.r,bg.g,bg.b,bg.a); + vkvg_paint(ctx); + vkvg_set_source_rgba(ctx,fg.r,fg.g,fg.b,fg.a); + //vkvg_select_font_face(ctx, "droid"); + vkvg_select_font_face(ctx, "times"); - float penY = 10.f; + float penY = 10.f; - for (uint32_t size=4;size<39;size++) { - print(ctx,penY+=size,size); - } + for (uint32_t size=4;size<39;size++) { + print(ctx,(float)penY,size); + penY+=size; + } - vkvg_destroy(ctx); + vkvg_destroy(ctx); } void test1() { - VkvgContext ctx = vkvg_create(surf); + VkvgContext ctx = vkvg_create(surf); - vkvg_color_t fg = {0.0,0.0,0.0,1}; - vkvg_color_t bg = {0.9,0.9,0.9,1}; + vkvg_color_t fg = {0.0,0.0,0.0,1}; + vkvg_color_t bg = {0.9f,0.9f,0.9f,1}; - vkvg_set_source_rgba(ctx,bg.r,bg.g,bg.b,bg.a); - vkvg_paint(ctx); - vkvg_set_source_rgba(ctx,fg.r,fg.g,fg.b,fg.a); + vkvg_set_source_rgba(ctx,bg.r,bg.g,bg.b,bg.a); + vkvg_paint(ctx); + vkvg_set_source_rgba(ctx,fg.r,fg.g,fg.b,fg.a); - uint32_t size = 8; - float penY = 100.f; + uint32_t size = 8; + float penY = 100.f; - vkvg_set_font_size(ctx,size); + vkvg_set_font_size(ctx,size); - vkvg_select_font_face(ctx, "mono"); - vkvg_move_to(ctx, 100,penY); - vkvg_show_text (ctx,txt); + vkvg_select_font_face(ctx, "mono"); + vkvg_move_to(ctx, 100.f,penY); + vkvg_show_text (ctx,txt); - penY += 1.2f * size; + penY += 1.2f * size; - vkvg_select_font_face(ctx, "times"); - vkvg_move_to(ctx, 100, penY); - vkvg_show_text (ctx,txt); + vkvg_select_font_face(ctx, "times"); + vkvg_move_to(ctx, 100.f, penY); + vkvg_show_text (ctx,txt); - penY += 1.2f * size; + penY += 1.2f * size; - vkvg_select_font_face(ctx, "arial:italic"); - vkvg_move_to(ctx, 100, penY); - vkvg_show_text (ctx,txt); + vkvg_select_font_face(ctx, "arial:italic"); + vkvg_move_to(ctx, 100.f, penY); + vkvg_show_text (ctx,txt); - vkvg_destroy(ctx); + vkvg_destroy(ctx); } void test(){ - VkvgContext ctx = vkvg_create(surf); + VkvgContext ctx = vkvg_create(surf); - //vkvg_color_t fg = {0.2,0.2,0.2,1}; - vkvg_color_t fg = {0.0,0.0,0.0,1}; - vkvg_color_t bg = {1.0,1.0,1.0,1}; - vkvg_set_source_rgba(ctx,bg.r,bg.g,bg.b,bg.a); - vkvg_paint(ctx); + //vkvg_color_t fg = {0.2,0.2,0.2,1}; + vkvg_color_t fg = {0.0,0.0,0.0,1}; + vkvg_color_t bg = {1.0f,1.0f,1.0f,1}; + vkvg_set_source_rgba(ctx,bg.r,bg.g,bg.b,bg.a); + vkvg_paint(ctx); - int size = 19; - int penY = 50; - int penX = 10; + float size = 19; + float penY = 50; + float penX = 10; - /*vkvg_rectangle(ctx,30,0,100,400); - vkvg_clip(ctx);*/ + /*vkvg_rectangle(ctx,30,0,100,400); + vkvg_clip(ctx);*/ - //vkvg_select_font_face(ctx, "/usr/local/share/fonts/DroidSansMono.ttf"); - //vkvg_select_font_face(ctx, "/usr/share/fonts/truetype/unifont/unifont.ttf"); + //vkvg_select_font_face(ctx, "/usr/local/share/fonts/DroidSansMono.ttf"); + //vkvg_select_font_face(ctx, "/usr/share/fonts/truetype/unifont/unifont.ttf"); - vkvg_set_font_size(ctx,12); - vkvg_select_font_face(ctx, "droid"); - vkvg_font_extents_t fe; - vkvg_font_extents (ctx,&fe); - vkvg_move_to(ctx, penX,penY); - vkvg_set_source_rgba(ctx,fg.r,fg.g,fg.b,fg.a); - vkvg_text_extents_t te; - vkvg_text_extents(ctx,"abcdefghijk",&te); - vkvg_show_text (ctx,"abcdefghijk"); - penX+= te.x_advance; - vkvg_move_to(ctx, penX,penY); - vkvg_show_text (ctx,"*abcdefghijk2"); - penY+=2*size; + vkvg_set_font_size(ctx,12); + vkvg_select_font_face(ctx, "droid"); + vkvg_font_extents_t fe; + vkvg_font_extents (ctx,&fe); + vkvg_move_to(ctx, penX,penY); + vkvg_set_source_rgba(ctx,fg.r,fg.g,fg.b,fg.a); + vkvg_text_extents_t te; + vkvg_text_extents(ctx,"abcdefghijk",&te); + vkvg_show_text (ctx,"abcdefghijk"); + penX+= te.x_advance; + vkvg_move_to(ctx, penX,penY); + vkvg_show_text (ctx,"*abcdefghijk2"); + penY+=2.f*size; - vkvg_select_font_face(ctx, "times"); - vkvg_move_to(ctx, penX,penY); - vkvg_show_text (ctx,"abcdefghijklmnopqrstuvwxyz"); - penY+=size; + vkvg_select_font_face(ctx, "times"); + vkvg_move_to(ctx, penX,penY); + vkvg_show_text (ctx,"abcdefghijklmnopqrstuvwxyz"); + penY+=size; - vkvg_select_font_face(ctx, "droid"); - vkvg_move_to(ctx, penX,penY); - vkvg_show_text (ctx,"lmnopqrstuvwxyz123456789"); - penY+=size; + vkvg_select_font_face(ctx, "droid"); + vkvg_move_to(ctx, penX,penY); + vkvg_show_text (ctx,"lmnopqrstuvwxyz123456789"); + penY+=size; - vkvg_select_font_face(ctx, "times:bold"); - vkvg_move_to(ctx, penX,penY); - vkvg_show_text (ctx,"abcdefghijklmnopqrstuvwxyz"); - penY+=size; + vkvg_select_font_face(ctx, "times:bold"); + vkvg_move_to(ctx, penX,penY); + vkvg_show_text (ctx,"abcdefghijklmnopqrstuvwxyz"); + penY+=size; - vkvg_select_font_face(ctx, "droid"); - vkvg_move_to(ctx, penX,penY); - vkvg_show_text (ctx,"ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - penY+=size; + vkvg_select_font_face(ctx, "droid"); + vkvg_move_to(ctx, penX,penY); + vkvg_show_text (ctx,"ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + penY+=size; - vkvg_select_font_face(ctx, "arial:italic"); - vkvg_move_to(ctx, penX,penY); - vkvg_show_text (ctx,"abcdefghijklmnopqrstuvwxyz"); - penY+=size; + vkvg_select_font_face(ctx, "arial:italic"); + vkvg_move_to(ctx, penX,penY); + vkvg_show_text (ctx,"abcdefghijklmnopqrstuvwxyz"); + penY+=size; - vkvg_select_font_face(ctx, "arial"); - vkvg_move_to(ctx, penX,penY); - vkvg_show_text (ctx,"ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - penY+=size; - vkvg_move_to(ctx, penX,penY); - vkvg_show_text (ctx,"this is a test"); - penY+=size; - vkvg_move_to(ctx, penX,penY); - vkvg_show_text (ctx,"this is another test to see if label is working"); - penY+=size; + vkvg_select_font_face(ctx, "arial"); + vkvg_move_to(ctx, penX,penY); + vkvg_show_text (ctx,"ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + penY+=size; + vkvg_move_to(ctx, penX,penY); + vkvg_show_text (ctx,"this is a test"); + penY+=size; + vkvg_move_to(ctx, penX,penY); + vkvg_show_text (ctx,"this is another test to see if label is working"); + penY+=size; - vkvg_select_font_face(ctx, "mono"); - vkvg_move_to(ctx, penX,penY); - vkvg_show_text (ctx,"ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - penY+=size; + vkvg_select_font_face(ctx, "mono"); + vkvg_move_to(ctx, penX,penY); + vkvg_show_text (ctx,"ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + penY+=size; - vkvg_move_to(ctx, 80,400); - vkvg_show_text (ctx,"Ленивый рыжий кот"); + vkvg_move_to(ctx, 80,400); + vkvg_show_text (ctx,"Ленивый рыжий кот"); - /*vkvg_move_to(ctx, 150,250); - vkvg_show_text (ctx,"test string é€"); - vkvg_move_to(ctx, 150,300); - vkvg_show_text (ctx,"كسول الزنجبيل القط"); - vkvg_move_to(ctx, 150,350); - vkvg_show_text (ctx,"懶惰的姜貓");*/ + /*vkvg_move_to(ctx, 150,250); + vkvg_show_text (ctx,"test string é€"); + vkvg_move_to(ctx, 150,300); + vkvg_show_text (ctx,"كسول الزنجبيل القط"); + vkvg_move_to(ctx, 150,350); + vkvg_show_text (ctx,"懶惰的姜貓");*/ - //vkvg_show_text (ctx,"ABCDABCD"); - //vkvg_show_text (ctx,"j"); + //vkvg_show_text (ctx,"ABCDABCD"); + //vkvg_show_text (ctx,"j"); - vkvg_destroy(ctx); + vkvg_destroy(ctx); } int main(int argc, char *argv[]) { - perform_test (test2, 1024, 768); - perform_test (test1, 1024, 768); - perform_test (test, 1024, 768); + PERFORM_TEST (test, argc, argv); + PERFORM_TEST (test1, argc, argv); + PERFORM_TEST (test2, argc, argv); - return 0; + return 0; } diff --git a/tests/vlines.c b/tests/vlines.c index 5ae3be4..302457d 100644 --- a/tests/vlines.c +++ b/tests/vlines.c @@ -1,36 +1,34 @@ #include "test.h" void test(){ - vkvg_surface_clear(surf); - struct timeval currentTime; - gettimeofday(¤tTime, NULL); + vkvg_surface_clear(surf); + struct timeval currentTime; + gettimeofday(¤tTime, NULL); - srand((unsigned) currentTime.tv_usec); - const float w = 1024.f; - const float h = 800.f; + srand((unsigned) currentTime.tv_usec); + const float w = 1024.f; + const float h = 800.f; - VkvgContext ctx = vkvg_create(surf); - //vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD); - vkvg_set_line_width(ctx,1); - //vkvg_set_line_join(ctx,VKVG_LINE_JOIN_BEVEL); - //vkvg_set_source_rgba(ctx,1.0,0.0,0.0,0.1); + VkvgContext ctx = vkvg_create(surf); + //vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD); + vkvg_set_line_width(ctx,1); + //vkvg_set_line_join(ctx,VKVG_LINE_JOIN_BEVEL); + //vkvg_set_source_rgba(ctx,1.0,0.0,0.0,0.1); - for (int i=0; i<test_size; i++) { - randomize_color(ctx); - float x1 = w*rand()/RAND_MAX; - float y1 = h*rand()/RAND_MAX; - float v = (500.f*rand()/RAND_MAX) + 1; + for (uint32_t i=0; i<test_size; i++) { + randomize_color(ctx); + float x1 = w*rand()/RAND_MAX; + float y1 = h*rand()/RAND_MAX; + float v = (500.f*rand()/RAND_MAX) + 1; - vkvg_move_to (ctx, x1, y1); - vkvg_line_to (ctx, x1, y1 + v); - vkvg_stroke (ctx); - } - vkvg_destroy(ctx); + vkvg_move_to (ctx, x1, y1); + vkvg_line_to (ctx, x1, y1 + v); + vkvg_stroke (ctx); + } + vkvg_destroy(ctx); } int main(int argc, char *argv[]) { - - perform_test (test, 1024, 768); - - return 0; + PERFORM_TEST (test, argc, argv); + return 0; } |