]> O.S.I.I.S - jp/vkvg.git/commitdiff
vkvg_surface_resize resizeSurf
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 14 Jul 2022 04:17:32 +0000 (06:17 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 14 Jul 2022 04:17:32 +0000 (06:17 +0200)
include/vkvg.h
src/vkvg_context.c
src/vkvg_surface.c
src/vkvg_surface_internal.h

index 3483a1ee37e85894ec5ac857514312bd71bb744b..164ef616373ddff24b8b6168d829383cdf1f1788 100644 (file)
@@ -789,6 +789,11 @@ void vkvg_surface_destroy (VkvgSurface surf);
  */
 vkvg_public
 vkvg_status_t vkvg_surface_status (VkvgSurface surf);
+/**
+ * @brief Resize the surface.
+ */
+vkvg_public
+void vkvg_surface_resize(VkvgSurface surf, uint32_t width, uint32_t height);
 /**
  * @brief Clear surface's content.
  *
index ea5b1f5dc7a83d6242ea107987611b1d2e0a3dea..a88f71b1dae58dff6a917234e87904a886dd4f6a 100644 (file)
@@ -47,7 +47,7 @@ void _init_ctx (VkvgContext ctx) {
        ctx->miterLimit         = 10;
        ctx->curOperator        = VKVG_OPERATOR_OVER;
        ctx->curFillRule        = VKVG_FILL_RULE_NON_ZERO;
-       ctx->bounds = (VkRect2D) {{0,0},{ctx->pSurf->width,ctx->pSurf->height}};
+       ctx->bounds = (VkRect2D) { {0,0}, { ctx->pSurf->width, ctx->pSurf->height } };
        ctx->pushConsts = (push_constants) {
                        {.a = 1},
                        {(float)ctx->pSurf->width,(float)ctx->pSurf->height},
@@ -575,7 +575,7 @@ void _curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, float x
        //compute dyn distanceTolerance depending on current scale
        float sx = 1, sy = 1;
        vkvg_matrix_get_scale (&ctx->pushConsts.mat, &sx, &sy);
-       float distanceTolerance = fabs(0.25f / fmaxf(sx,sy));
+       float distanceTolerance = fabs(0.01f / fmaxf(sx,sy));
 
        _recursive_bezier (ctx, distanceTolerance, cp.x, cp.y, x1, y1, x2, y2, x3, y3, 0);
        /*cp.x = x3;
index 369adbd26c1363cea09c77aa561848e7f85a3576..c70e2aa1b5233a4a465946f621f3efa701184771 100644 (file)
@@ -65,8 +65,8 @@ VkvgSurface vkvg_surface_create (VkvgDevice dev, uint32_t width, uint32_t height
        if (surf->status)
                return surf;
 
-       surf->width = MAX(1, width);
-       surf->height = MAX(1, height);
+       surf->imgWidth = surf->width = MAX(1, width);
+       surf->imgHeight = surf->height = MAX(1, height);
        surf->newSurf = true;//used to clear all attacments on first render pass
 
        _create_surface_images (surf);
@@ -88,8 +88,8 @@ VkvgSurface vkvg_surface_create_for_VkhImage (VkvgDevice dev, void* vkhImg) {
        }
 
        VkhImage img = (VkhImage)vkhImg;
-       surf->width = img->infos.extent.width;
-       surf->height= img->infos.extent.height;
+       surf->imgWidth = img->infos.extent.width;
+       surf->imgHeight = img->infos.extent.height;
 
        surf->img = img;
 
@@ -116,8 +116,8 @@ VkvgSurface vkvg_surface_create_from_bitmap (VkvgDevice dev, unsigned char* img,
                return surf;
        }
 
-       surf->width = MAX(1, width);
-       surf->height = MAX(1, height);
+       surf->imgWidth = surf->width = MAX(1, width);
+       surf->imgHeight = surf->height = MAX(1, height);
 
        _create_surface_images (surf);
 
@@ -275,7 +275,31 @@ uint32_t vkvg_surface_get_reference_count (VkvgSurface surf) {
                return 0;
        return surf->references;
 }
+void vkvg_surface_resize(VkvgSurface surf, uint32_t width, uint32_t height) {
+       if (surf->status)
+               return;
+
+       surf->width = MAX(1, width);
+       surf->height = MAX(1, height);
+
+       vkDestroyFramebuffer(surf->dev->vkDev, surf->fb, NULL);
+
+       if (width > surf->imgWidth || height > surf->imgHeight) {
+               if (!surf->img->imported)
+                       vkh_image_destroy(surf->img);
+               vkh_image_destroy(surf->imgMS);
+               vkh_image_destroy(surf->stencil);
 
+               surf->newSurf = true;//used to clear all attacments on first render pass
+               _create_surface_images (surf);
+               _transition_surf_images (surf);
+
+               surf->imgWidth = surf->width;
+               surf->imgHeight = surf->height;
+       }
+
+       _create_framebuffer (surf);
+}
 VkImage vkvg_surface_get_vk_image(VkvgSurface surf)
 {
        if (surf->status)
index 5cc47c670445d324940c5ad61f8574a3dee09a9a..f89573feca8d325c9f3f84cd031bbf77a66b08ee 100644 (file)
@@ -30,8 +30,10 @@ typedef struct _vkvg_surface_t {
        vkvg_status_t   status;                                 /**< Current status of surface, affected by last operation */
        uint32_t                references;
        VkvgDevice              dev;
-       uint32_t                width;
-       uint32_t                height;
+       uint32_t                width;                                  /**< surface width, underlying vulkan image may be larger */
+       uint32_t                height;                                 /**< surface height, underlying vulkan image may be larger */
+       uint32_t                imgWidth;                               /**< physical surface image width */
+       uint32_t                imgHeight;                              /**< physical surface image height */
        VkFormat                format;
        VkFramebuffer   fb;
        VkhImage                img;