]> O.S.I.I.S - jp/vkvg.git/commitdiff
quadratic, don't fault on missing current point for relative funcs
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 27 Nov 2021 05:08:28 +0000 (06:08 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 27 Nov 2021 05:08:28 +0000 (06:08 +0100)
include/vkvg.h
src/vkvg_context.c
src/vkvg_device.c
tests/common/test.c
vkh

index 638c84e6c2f4b6966ca48a06492e8b979c19b3b2..99a6a1b991252c5b47883c8a112c818b6aa2fcdf 100644 (file)
@@ -310,14 +310,6 @@ vkvg_debug_stats_t vkvg_device_reset_stats (VkvgDevice dev);
  * Matrix computations in vkvg are taken from the cairo library.
  * @{ */
 #define VKVG_IDENTITY_MATRIX {1,0,0,1,0,0}/*!< The identity matrix*/
-/**
- * @xx: xx component of the affine transformation
- * @yx: yx component of the affine transformation
- * @xy: xy component of the affine transformation
- * @yy: yy component of the affine transformation
- * @x0: X translation component of the affine transformation
- * @y0: Y translation component of the affine transformation
- *
 /**
  * @brief vkvg matrix structure
  *
@@ -328,6 +320,12 @@ vkvg_debug_stats_t vkvg_device_reset_stats (VkvgDevice dev);
  * x_new = xx * x + xy * y + x0;
  * y_new = yx * x + yy * y + y0;
  * @endcode
+ * @xx: xx component of the affine transformation
+ * @yx: yx component of the affine transformation
+ * @xy: xy component of the affine transformation
+ * @yy: yy component of the affine transformation
+ * @x0: X translation component of the affine transformation
+ * @y0: Y translation component of the affine transformation
  */
 typedef struct {
        float xx; float yx;
@@ -829,6 +827,14 @@ void vkvg_new_sub_path (VkvgContext ctx);
  */
 vkvg_public
 void vkvg_path_extents (VkvgContext ctx, float *x1, float *y1, float *x2, float *y2);
+/**
+ * @brief Get the current point of the context, return 0,0 if no point is defined.
+ * @param ctx
+ * @param x
+ * @param y
+ */
+vkvg_public
+void vkvg_get_current_point (VkvgContext ctx, float* x, float* y);
 /**
  * @brief Add a line to the current path from the current point to the coordinate given in arguments.
  *
@@ -941,6 +947,46 @@ void vkvg_arc_negative (VkvgContext ctx, float xc, float yc, float radius, float
 vkvg_public
 void vkvg_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, float x3, float y3);
 /**
+ * @brief Adds a cubic Bézier spline to the current path relative to the current point.
+ *
+ * Adds a cubic Bézier spline to the path from the current point to position (x3, y3) in relative coordinate to the current point,
+ * using (x1, y1) and (x2, y2) as the control points relative to the current point.
+ * After this call the current point will be (x3, y3).
+ *
+ * If there is no current point before the call to vkvg_rel_curve_to() => error:VKVG_STATUS_NO_CURRENT_POINT.
+ * @param ctx The vkvg context pointer.
+ * @param x1 The X coordinate of the first control point.
+ * @param y1 The Y coordinate of the first control point.
+ * @param x2 The X coordinate of the second control point.
+ * @param y2 The Y coordinate of the second control point.
+ * @param x3 The X coordinate of the end of the curve.
+ * @param y3 The Y coordinate of the end of the curve.
+ */
+vkvg_public
+void vkvg_rel_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, float x3, float y3);
+/**
+ * @brief Add a quadratic Bezizer curve to the current path
+ *
+ * If there is no current point before the call to vkvg_quadratic_to() this function will behave as if preceded by a call to vkvg_move_to(ctx, x1, y1).
+ * @param ctx The vkvg context pointer.
+ * @param x1 The X coordinate of the control point.
+ * @param y1 The Y coordinate of the control point.
+ * @param x2 The X coordinate of the end point of the curve.
+ * @param y2 The Y coordinate of the end point of the curve.
+ */
+vkvg_public
+void vkvg_quadratic_to (VkvgContext ctx, float x1, float y1, float x2, float y2);
+/**
+ * @brief Add a quadratic Bezizer curve to the current path relative to the current point
+ *
+ * @param ctx The vkvg context pointer.
+ * @param x1 The X coordinate of the control point relative to the current point.
+ * @param y1 The Y coordinate of the control point relative to the current point.
+ * @param x2 The X coordinate of the end point of the curve relative to the current point.
+ * @param y2 The Y coordinate of the end point of the curve relative to the current point.
+ */
+vkvg_public
+void vkvg_rel_quadratic_to (VkvgContext ctx, float x1, float y1, float x2, float y2);/**
  * @brief Add an axis aligned rectangle subpath to the current path.
  *
  * Adds a closed sub-path rectangle of the given size to the current path at position (x, y).
@@ -1016,7 +1062,13 @@ void vkvg_clip (VkvgContext ctx);
  */
 vkvg_public
 void vkvg_clip_preserve (VkvgContext ctx);
-
+/**
+ * @brief Set current source for drawing to the solid color defined by the supplied 32bit integer.
+ * @param ctx a valid vkvg @ref context
+ * @param rgba color coded in 32bit integer.
+ */
+vkvg_public
+void vkvg_set_source_color (VkvgContext ctx, uint32_t c);
 /**
  * @brief set color with alpha.
  *
index 65374bb80238e85c04ea72cf7da9364091097aaf..5f912e63f248d71aa18efc5ecaeff1df14a18a40 100644 (file)
@@ -327,10 +327,8 @@ void vkvg_close_path (VkvgContext ctx){
 void vkvg_rel_line_to (VkvgContext ctx, float dx, float dy){
        if (ctx->status)
                return;
-       if (_current_path_is_empty(ctx)){
-               ctx->status = VKVG_STATUS_NO_CURRENT_POINT;
-               return;
-       }
+       if (_current_path_is_empty(ctx))
+               _add_point(ctx, 0, 0);
        vec2 cp = _get_current_position(ctx);
        vkvg_line_to(ctx, cp.x + dx, cp.y + dy);
 }
@@ -441,10 +439,8 @@ void vkvg_rel_move_to (VkvgContext ctx, float x, float y)
 {
        if (ctx->status)
                return;
-       if (_current_path_is_empty(ctx)){
-               ctx->status = VKVG_STATUS_NO_CURRENT_POINT;
-               return;
-       }
+       if (_current_path_is_empty(ctx))
+               _add_point(ctx, 0, 0);
        vec2 cp = _get_current_position(ctx);
        vkvg_move_to(ctx, cp.x + x, cp.y + y);
 }
@@ -455,7 +451,37 @@ void vkvg_move_to (VkvgContext ctx, float x, float y)
        _finish_path(ctx);
        _add_point (ctx, x, y);
 }
-
+void vkvg_get_current_point (VkvgContext ctx, float* x, float* y) {
+       if (_current_path_is_empty(ctx)) {
+               *x = *y = 0;
+               return;
+       }
+       vec2 cp = _get_current_position(ctx);
+       *x = cp.x;
+       *y = cp.y;
+}
+void vkvg_rel_quadratic_to (VkvgContext ctx, float x1, float y1, float x2, float y2) {
+       if (ctx->status)
+               return;
+       vec2 cp = _get_current_position(ctx);
+       vkvg_quadratic_to (ctx, cp.x + x1, cp.y + y1, cp.x + x2, cp.y + y2);
+}
+void vkvg_quadratic_to (VkvgContext ctx, float x1, float y1, float x2, float y2) {
+       if (ctx->status)
+               return;
+       _set_curve_start (ctx);
+       if (_current_path_is_empty(ctx))
+               _add_point(ctx, x1, y1);
+       float x0, y0;
+       vkvg_get_current_point (ctx, &x0, &y0);
+       vkvg_curve_to (ctx,
+                                 2.0 / 3.0 * x1 + 1.0 / 3.0 * x0,
+                                 2.0 / 3.0 * y1 + 1.0 / 3.0 * y0,
+                                 2.0 / 3.0 * x1 + 1.0 / 3.0 * x2,
+                                 2.0 / 3.0 * y1 + 1.0 / 3.0 * y2,
+                                 y1, y2);
+       _set_curve_end (ctx);
+}
 void vkvg_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, float x3, float y3) {
        if (ctx->status)
                return;
@@ -480,10 +506,6 @@ void vkvg_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, flo
 void vkvg_rel_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, float x3, float y3) {
        if (ctx->status)
                return;
-       if (_current_path_is_empty(ctx)){
-               ctx->status = VKVG_STATUS_NO_CURRENT_POINT;
-               return;
-       }
        vec2 cp = _get_current_position(ctx);
        vkvg_curve_to (ctx, cp.x + x1, cp.y + y1, cp.x + x2, cp.y + y2, cp.x + x3, cp.y + y3);
 }
@@ -888,6 +910,12 @@ void vkvg_paint (VkvgContext ctx){
        _ensure_renderpass_is_started (ctx);
        _draw_full_screen_quad (ctx, true);
 }
+void vkvg_set_source_color (VkvgContext ctx, uint32_t c) {
+       if (ctx->status)
+               return;
+       ctx->curColor = c;
+       _update_cur_pattern (ctx, NULL);
+}
 void vkvg_set_source_rgb (VkvgContext ctx, float r, float g, float b) {
        vkvg_set_source_rgba (ctx, r, g, b, 1);
 }
index 251e5bffb310ad54761bc839977464048a2142fb..2eb833e94564aeab1c7a1cb4543a5a211dde8307 100644 (file)
@@ -36,8 +36,8 @@ VkvgDevice vkvg_device_create_multisample(VkInstance inst, VkPhysicalDevice phy,
        VkvgDevice dev = (vkvg_device*)calloc(1,sizeof(vkvg_device));
 
        dev->instance = inst;
-       dev->hdpi       = 96;
-       dev->vdpi       = 96;
+       dev->hdpi       = 72;
+       dev->vdpi       = 72;
        dev->samples= samples;
        dev->deferredResolve = deferredResolve;
        dev->vkDev      = vkdev;
index 4fbc818cfa1502f746a5e921c6ea59f7921ba6aa..f0d47ec955dfe1a4a0bc8a0a6d8009f4f8cec218 100644 (file)
@@ -150,9 +150,6 @@ void init_test (uint32_t width, uint32_t height){
        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);
-
        surf = vkvg_surface_create(device, width, height);
 
        vkh_presenter_build_blit_cmd (r, vkvg_surface_get_vk_image(surf), width, height);
@@ -392,7 +389,7 @@ void perform_test_offscreen (void(*testfunc)(void), const char *testName, int ar
 
 
        device  = vkvg_device_create_multisample(vkh_app_get_inst(app), dev->phy, dev->dev, pi->gQueue, 0, samples, deferredResolve);
-       vkvg_device_set_dpy(device, 96, 96);
+       //vkvg_device_set_dpy(device, 96, 96);
 
        vkh_app_free_phyinfos (phyCount, phys);
 
diff --git a/vkh b/vkh
index 97cdc0fb23b33356cc1d4c1be8973891d7661ac5..7dfff1a2e601e142583c122c9f716578d8e85039 160000 (submodule)
--- a/vkh
+++ b/vkh
@@ -1 +1 @@
-Subproject commit 97cdc0fb23b33356cc1d4c1be8973891d7661ac5
+Subproject commit 7dfff1a2e601e142583c122c9f716578d8e85039