]> git.mdlowis.com Git - proto/labwc.git/commitdiff
scaled-scene-buffer: store all the scaled_scene_buffers in a single list
authortokyo4j <hrak1529@gmail.com>
Sun, 12 Jan 2025 09:14:59 +0000 (18:14 +0900)
committerHiroaki Yamamoto <hrak1529@gmail.com>
Mon, 13 Jan 2025 09:24:10 +0000 (18:24 +0900)
include/common/scaled-scene-buffer.h
src/common/scaled-font-buffer.c
src/common/scaled-img-buffer.c
src/common/scaled-rect-buffer.c
src/common/scaled-scene-buffer.c

index 989600d9672e2ddaa89d11f942f2e86f8cd464f8..29f058132a1b2470131db6f0ec2f907b28a26348 100644 (file)
@@ -36,12 +36,7 @@ struct scaled_scene_buffer {
        struct wl_listener destroy;
        struct wl_listener outputs_update;
        const struct scaled_scene_buffer_impl *impl;
-       /*
-        * Pointer to the per-implementation list of scaled-scene-buffers.
-        * This is used to share the backing wlr_buffers.
-        */
-       struct wl_list *cached_buffers;
-       struct wl_list link; /* struct scaled_scene_buffer.cached_buffers */
+       struct wl_list link; /* all_scaled_buffers */
 };
 
 /*
@@ -89,8 +84,8 @@ struct scaled_scene_buffer {
  * allocations.
  *
  * Besides caching buffers for each scale per scaled_scene_buffer, we also
- * store all the scaled_scene_buffers in a per-implementer list passed as
- * @cached_buffers in order to reuse backing buffers for visually duplicated
+ * store all the scaled_scene_buffers from all the implementers in a list
+ * in order to reuse backing buffers for visually duplicated
  * scaled_scene_buffers found via impl->equal().
  *
  * All requested lab_data_buffers via impl->create_buffer() will be locked
@@ -119,7 +114,7 @@ struct scaled_scene_buffer {
 struct scaled_scene_buffer *scaled_scene_buffer_create(
        struct wlr_scene_tree *parent,
        const struct scaled_scene_buffer_impl *implementation,
-       struct wl_list *cached_buffers, bool drop_buffer);
+       bool drop_buffer);
 
 /**
  * scaled_scene_buffer_request_update - mark the buffer that needs to be
index e8a9b0a5741695ff836e818370e582eaac953d5a..7bd0f1dc0cce2093164fd484b902c46cb0b1e21a 100644 (file)
@@ -7,14 +7,10 @@
 #include <wlr/util/log.h>
 #include "buffer.h"
 #include "common/font.h"
-#include "common/list.h"
 #include "common/mem.h"
 #include "common/scaled-scene-buffer.h"
 #include "common/scaled-font-buffer.h"
 
-/* This holds all the scaled-font-buffers and used for sharing backing buffers */
-static struct wl_list cached_buffers = WL_LIST_INIT(&cached_buffers);
-
 static struct lab_data_buffer *
 _create_buffer(struct scaled_scene_buffer *scaled_buffer, double scale)
 {
@@ -78,7 +74,7 @@ scaled_font_buffer_create(struct wlr_scene_tree *parent)
        assert(parent);
        struct scaled_font_buffer *self = znew(*self);
        struct scaled_scene_buffer *scaled_buffer = scaled_scene_buffer_create(
-               parent, &impl, &cached_buffers, /* drop_buffer */ true);
+               parent, &impl, /* drop_buffer */ true);
        if (!scaled_buffer) {
                free(self);
                return NULL;
index 0d24a6dd082071fa0249b3c3a0564ea5ee006a56..ed5d02768c2fde2747e22bbd3b13c6e446b8778e 100644 (file)
@@ -4,15 +4,12 @@
 #include <wayland-server-core.h>
 #include <wlr/types/wlr_scene.h>
 #include "buffer.h"
-#include "common/list.h"
 #include "common/mem.h"
 #include "common/scaled-img-buffer.h"
 #include "common/scaled-scene-buffer.h"
 #include "img/img.h"
 #include "node.h"
 
-static struct wl_list cached_buffers = WL_LIST_INIT(&cached_buffers);
-
 static struct lab_data_buffer *
 _create_buffer(struct scaled_scene_buffer *scaled_buffer, double scale)
 {
@@ -55,7 +52,7 @@ scaled_img_buffer_create(struct wlr_scene_tree *parent, struct lab_img *img,
 {
        assert(img);
        struct scaled_scene_buffer *scaled_buffer = scaled_scene_buffer_create(
-               parent, &impl, &cached_buffers, /* drop_buffer */ true);
+               parent, &impl, /* drop_buffer */ true);
        struct scaled_img_buffer *self = znew(*self);
        self->scaled_buffer = scaled_buffer;
        self->scene_buffer = scaled_buffer->scene_buffer;
index 04b5e6d7dd708ca5ffaf0280c486ff60e269a590..9bb173ee3fec968cde1ad13e2faf7c86b683bd56 100644 (file)
@@ -7,14 +7,11 @@
 #include <wlr/util/log.h>
 #include "buffer.h"
 #include "common/graphic-helpers.h"
-#include "common/list.h"
 #include "common/macros.h"
 #include "common/mem.h"
 #include "common/scaled-scene-buffer.h"
 #include "common/scaled-rect-buffer.h"
 
-static struct wl_list cached_buffers = WL_LIST_INIT(&cached_buffers);
-
 static void
 draw_rectangle_path(cairo_t *cairo, int width, int height, int border_width)
 {
@@ -100,7 +97,7 @@ struct scaled_rect_buffer *scaled_rect_buffer_create(
        assert(parent);
        struct scaled_rect_buffer *self = znew(*self);
        struct scaled_scene_buffer *scaled_buffer = scaled_scene_buffer_create(
-               parent, &impl, &cached_buffers, /* drop_buffer */ true);
+               parent, &impl, /* drop_buffer */ true);
        scaled_buffer->data = self;
        self->scaled_buffer = scaled_buffer;
        self->scene_buffer = scaled_buffer->scene_buffer;
index 7ab0b8cefa29e385870498b7f449dba35d8e3624..c45fc9835d2cb63a8f49077b769d3c43435eee87 100644 (file)
@@ -8,11 +8,18 @@
 #include <wlr/types/wlr_scene.h>
 #include <wlr/util/log.h>
 #include "buffer.h"
+#include "common/list.h"
 #include "common/macros.h"
 #include "common/mem.h"
 #include "common/scaled-scene-buffer.h"
 #include "node.h"
 
+/*
+ * This holds all the scaled_scene_buffers from all the implementers.
+ * This is used to share visually duplicated buffers found via impl->equal().
+ */
+static struct wl_list all_scaled_buffers = WL_LIST_INIT(&all_scaled_buffers);
+
 /* Internal API */
 static void
 _cache_entry_destroy(struct scaled_scene_buffer_cache_entry *cache_entry, bool drop_buffer)
@@ -63,13 +70,16 @@ _update_buffer(struct scaled_scene_buffer *self, double scale)
 
        struct wlr_buffer *wlr_buffer = NULL;
 
-       if (self->impl->equal && self->cached_buffers) {
+       if (self->impl->equal) {
                /* Search from other cached scaled-scene-buffers */
                struct scaled_scene_buffer *scene_buffer;
-               wl_list_for_each(scene_buffer, self->cached_buffers, link) {
+               wl_list_for_each(scene_buffer, &all_scaled_buffers, link) {
                        if (scene_buffer == self) {
                                continue;
                        }
+                       if (self->impl != scene_buffer->impl) {
+                               continue;
+                       }
                        if (!self->impl->equal(self, scene_buffer)) {
                                continue;
                        }
@@ -174,7 +184,7 @@ _handle_outputs_update(struct wl_listener *listener, void *data)
 struct scaled_scene_buffer *
 scaled_scene_buffer_create(struct wlr_scene_tree *parent,
                const struct scaled_scene_buffer_impl *impl,
-               struct wl_list *cached_buffers, bool drop_buffer)
+               bool drop_buffer)
 {
        assert(parent);
        assert(impl);
@@ -199,13 +209,7 @@ scaled_scene_buffer_create(struct wlr_scene_tree *parent,
        self->drop_buffer = drop_buffer;
        wl_list_init(&self->cache);
 
-       self->cached_buffers = cached_buffers;
-       if (self->cached_buffers) {
-               wl_list_insert(self->cached_buffers, &self->link);
-       } else {
-               /* Ensure self->link can be removed safely in the destroy handler */
-               wl_list_init(&self->link);
-       }
+       wl_list_insert(&all_scaled_buffers, &self->link);
 
        /* Listen to outputs_update so we get notified about scale changes */
        self->outputs_update.notify = _handle_outputs_update;