From 243da9bbb9aaf277f50a1f9234f0f1798e55f6c3 Mon Sep 17 00:00:00 2001 From: IterioDev Date: Thu, 19 Nov 2026 16:42:44 +0200 Subject: [PATCH 1/3] cluster-render: an optional edge for a host's picture A scene that hosts another target may show it in a shape taller than the picture's rect (a picture scaled to the shape's width only). host now takes edge_top, edge_bottom, edge_fade, edge_dim and edge_blur: the service draws the rows 2 px in from the top and the bottom of each video another client draws inside the host's rect on past it (held within the target), blurred along the row (nine taps, sigma edge_blur), darkened with the distance to max(1/4, 1 - d / edge_dim), the picture's own rows fading into them over edge_fade px. Two quads a kind over the video (its order + 2), sampling what its atlas or packed quad samples, shown, ordered and faded with it. The two effects are compiled at the first edge asked for; refused, no edge is drawn. Without the fields nothing changes (the renderer traces as before). The status names a host's edge. Both clients send the fields. Tests: service_test (an edge: two quads over the producer's video, their rects and uniforms, held within the panel; out of range refused; none again without it), client_test.js (the five fields sent only with edge_top or edge_bottom; a refusal). Co-Authored-By: Claude Opus 5.5 --- native/cluster-render/client/client.cpp | 4 + .../include/cluster_render/client.h | 7 +- .../js/cluster_render_client.js | 12 +- native/cluster-render/js/test/client_test.js | 10 + native/cluster-render/src/compositor.cpp | 55 ++++++ native/cluster-render/src/compositor.h | 9 +- native/cluster-render/src/server.cpp | 15 ++ native/cluster-render/src/video_layer.cpp | 171 +++++++++++++++++- native/cluster-render/src/video_layer.h | 33 ++++ native/cluster-render/test/service_test.cpp | 33 ++++ 10 files changed, 342 insertions(+), 7 deletions(-) diff --git a/native/cluster-render/client/client.cpp b/native/cluster-render/client/client.cpp index 20b715fd..5ab43dc7 100644 --- a/native/cluster-render/client/client.cpp +++ b/native/cluster-render/client/client.cpp @@ -556,6 +556,10 @@ bool Client::host(uint32_t ref, const Host &h) if (h.src_w && h.src_h) kv.insert(kv.end(), {{"src_x", num(h.src_x)}, {"src_y", num(h.src_y)}, {"src_w", num(h.src_w)}, {"src_h", num(h.src_h)}}); + if (h.edge_top || h.edge_bottom) + kv.insert(kv.end(), {{"edge_top", num(h.edge_top)}, {"edge_bottom", num(h.edge_bottom)}, + {"edge_fade", num(h.edge_fade)}, {"edge_dim", num(h.edge_dim)}, + {"edge_blur", num(h.edge_blur)}}); const std::string json = json_object(kv); it->second.hosts[h.target] = json; queue(json); diff --git a/native/cluster-render/include/cluster_render/client.h b/native/cluster-render/include/cluster_render/client.h index 6b3598f3..433f57d6 100644 --- a/native/cluster-render/include/cluster_render/client.h +++ b/native/cluster-render/include/cluster_render/client.h @@ -167,10 +167,15 @@ struct Host { int src_x = 0, src_y = 0; unsigned src_w = 0, src_h = 0; /* 0: the whole target */ bool shown = true; + /* the edge drawn on the hosted picture (sent, all five, with edge_top or + * edge_bottom; the event never carries it) */ + unsigned edge_top = 0, edge_bottom = 0, edge_fade = 0, edge_dim = 0, edge_blur = 0; bool operator==(const Host &o) const { return target == o.target && into == o.into && x == o.x && y == o.y && w == o.w && h == o.h && - src_x == o.src_x && src_y == o.src_y && src_w == o.src_w && src_h == o.src_h && shown == o.shown; + src_x == o.src_x && src_y == o.src_y && src_w == o.src_w && src_h == o.src_h && shown == o.shown && + edge_top == o.edge_top && edge_bottom == o.edge_bottom && edge_fade == o.edge_fade && + edge_dim == o.edge_dim && edge_blur == o.edge_blur; } bool operator!=(const Host &o) const { return !(*this == o); } }; diff --git a/native/cluster-render/js/cluster_render_client.js b/native/cluster-render/js/cluster_render_client.js index 436b4aca..747d047f 100644 --- a/native/cluster-render/js/cluster_render_client.js +++ b/native/cluster-render/js/cluster_render_client.js @@ -394,10 +394,12 @@ class ClusterRender extends EventEmitter { /* The scene (made with layers) hosts another target (PROTOCOL.md * "host"): opts target, x, y, w, h (in the scene's target), src_x, * src_y, src_w, src_h (in the hosted target's pixels; sent, all four, - * when src_w and src_h are set, else all of it), shown. Kept by target - * and sent again after a reconnect, until the service refuses it or the - * scene is replaced; false, nothing sent, for a scene without layers or - * a host of its own target. */ + * when src_w and src_h are set, else all of it), shown; edge_top, + * edge_bottom, edge_fade, edge_dim, edge_blur (the edge drawn on the + * hosted picture; sent, all five, when edge_top or edge_bottom is set). + * Kept by target and sent again after a reconnect, until the service + * refuses it or the scene is replaced; false, nothing sent, for a scene + * without layers or a host of its own target. */ host(ref, opts) { const l = this.layers.get(ref); /* what the service refuses whatever it holds is not sent or kept */ @@ -411,6 +413,8 @@ class ClusterRender extends EventEmitter { m.src_w = opts.src_w; m.src_h = opts.src_h; } + if (opts.edge_top || opts.edge_bottom) + ['edge_top', 'edge_bottom', 'edge_fade', 'edge_dim', 'edge_blur'].forEach((k) => { m[k] = opts[k] || 0; }); l.hosts.set(opts.target, m); this._send(m); return true; diff --git a/native/cluster-render/js/test/client_test.js b/native/cluster-render/js/test/client_test.js index 89e39efd..538cb0d3 100644 --- a/native/cluster-render/js/test/client_test.js +++ b/native/cluster-render/js/test/client_test.js @@ -181,7 +181,17 @@ async function main() { ovl.host(over, { target: 'map', x: 700, y: 160, w: 560, h: 400, src_x: 264, src_w: 560, src_h: 400, src_y: 40 }); const sent = ovl.layers.get(over).hosts.get('map'); ok('with them, all four', sent.src_x === 264 && sent.src_y === 40 && sent.src_w === 560 && sent.src_h === 400); + ok('no edge unless edge_top or edge_bottom is set', !('edge_fade' in sent)); ok('it hosts the map: the other client told', await until(() => hosted.indexOf('map:panel:1:560') >= 0, 2000)); + ovl.host(over, { target: 'map', x: 700, y: 160, w: 560, h: 400, edge_top: 40, edge_blur: 9 }); + const edged = ovl.layers.get(over).hosts.get('map'); + ok('an edge: all five sent, kept', edged.edge_top === 40 && edged.edge_bottom === 0 && edged.edge_fade === 0 && + edged.edge_dim === 0 && edged.edge_blur === 9); + ovl.host(over, { target: 'map', x: 700, y: 160, w: 560, h: 400, src_x: 264, src_w: 560, src_h: 400, src_y: 40, edge_top: 40, edge_blur: 33 }); + ok('an edge out of range refused', await until(() => + eo.refused.some((r) => r.indexOf('host: edge_blur must be a number from 0 to 32') === 0), 2000)); + ovl.host(over, { target: 'map', x: 700, y: 160, w: 560, h: 400, src_x: 264, src_w: 560, src_h: 400, src_y: 40 }); + ok('hosted again', await until(() => hosted[hosted.length - 1] === 'map:panel:1:560', 2000)); ovl.host(over, { target: 'map', x: 1800, y: 160, w: 560, h: 400 }); ok('a host refused: the client forgets it, the service ends it', await until(() => !ovl.layers.get(over).hosts.has('map') && hosted[hosted.length - 1] === 'map:-' && diff --git a/native/cluster-render/src/compositor.cpp b/native/cluster-render/src/compositor.cpp index 2255a6e6..e465f51b 100644 --- a/native/cluster-render/src/compositor.cpp +++ b/native/cluster-render/src/compositor.cpp @@ -113,6 +113,8 @@ Compositor::~Compositor() if (atlas_fx_) gpu_->drop_effect(atlas_fx_); if (block_fx_) gpu_->drop_effect(block_fx_); if (image_fx_) gpu_->drop_effect(image_fx_); + for (int fx : edge_fx_) + if (fx) gpu_->drop_effect(fx); } bool Compositor::init(std::string *err) @@ -126,6 +128,21 @@ bool Compositor::init(std::string *err) return image_fx_ != 0; } +/* Compiled at the first edge a host asks for; refused, the service draws + * none (and runs as without them). */ +bool Compositor::edge_effects() +{ + if (!edge_tried_) { + edge_tried_ = true; + std::string why; + if (!(edge_fx_[0] = gpu_->effect(kQuadVertexShader, kEdgeAtlasFragmentShader, &why))) + log_warn("compositor: no edges for hosts: %s", why.c_str()); + else if (!(edge_fx_[1] = gpu_->effect(kQuadVertexShader, kEdgeBlockFragmentShader, &why))) + log_warn("compositor: no edges for hosts' packed videos: %s", why.c_str()); + } + return edge_fx_[0] != 0; +} + uint32_t Compositor::admit(uint64_t owner, int target, int64_t pixel_bytes, std::string *err) { if (target < 0 || target >= (int)targets_.size()) { @@ -671,6 +688,12 @@ std::string Compositor::scene_text(uint32_t id) const slots_->targets()[kv.first].name.c_str(), h.rect.w, h.rect.h, h.rect.x, h.rect.y, h.src.w, h.src.h, h.src.x, h.src.y, h.shown ? "" : ", not shown"); text += b; + if (h.edge.on()) { + std::snprintf(b, sizeof b, ", its edge %u up and %u down (fade %u, dim %u, blur %u)%s", h.edge.top, + h.edge.bottom, h.edge.fade, h.edge.dim, h.edge.blur, + edge_tried_ && !edge_fx_[0] ? ", not drawn here" : ""); + text += b; + } } return text; } @@ -878,12 +901,44 @@ void Compositor::arrange(int64_t now_ms) t.dirty = true; mark(e, t.arr.order[pos], t); } + if (!std::strcmp(e.layer->kind(), "video")) { + VideoEdge ed = edge_for((int)ti, e); + if (ed.on() && !edge_effects()) + ed = VideoEdge(); + if (static_cast(e.layer.get())->set_edge(ed, edge_fx_[0], edge_fx_[1])) { + t.dirty = true; + mark(e, t.arr.order[pos], t); + } + } } if (t.composite && t.composite->arranged()) t.dirty = true; } } +VideoEdge Compositor::edge_for(int ti, const Entry &e) const +{ + const Rect &r = e.layer->params.rect; + const int64_t x0 = r.x, y0 = r.y, x1 = x0 + r.w, y1 = y0 + r.h, th = slots_->targets()[ti].height; + for (const auto &kv : scenes_) { + const SceneEntry &s = kv.second; + if (s.target != ti || s.owner == e.owner || !s.error.empty()) + continue; + for (const auto &hk : s.hosts) { + const Host &h = hk.second; + if (!h.shown || !h.edge.on() || x0 < h.rect.x || y0 < h.rect.y || x1 > (int64_t)h.rect.x + h.rect.w || + y1 > (int64_t)h.rect.y + h.rect.h) + continue; + VideoEdge v = h.edge; + v.top = (uint32_t)std::min(v.top, y0); + v.bottom = (uint32_t)std::min(v.bottom, std::max(0, th - y1)); + v.fade = std::min(v.fade, r.h / 2); + return v; + } + } + return VideoEdge(); +} + void Compositor::fade(int ti, Target &t, int64_t now_ms) { const int64_t dt = std::max(0, now_ms - t.fade_ms); diff --git a/native/cluster-render/src/compositor.h b/native/cluster-render/src/compositor.h index 004b8d03..52f8f3bb 100644 --- a/native/cluster-render/src/compositor.h +++ b/native/cluster-render/src/compositor.h @@ -216,10 +216,12 @@ struct SceneLayers { /* A scene content showing another target's content (PROTOCOL.md "host"): at * rect in its own target, the part src of the hosted target; shown 0: - * nowhere. */ + * nowhere. edge: drawn on the videos other clients draw inside rect there + * (the hosted producer's), held within the target. */ struct Host { Rect rect, src; bool shown = true; + VideoEdge edge; }; class Compositor : public Scenes { @@ -654,6 +656,11 @@ class Compositor : public Scenes { int64_t second_ms_ = 0; int64_t (*clock_us_)() = nullptr; int atlas_fx_ = 0, block_fx_ = 0, image_fx_ = 0; + int edge_fx_[2] = {0, 0}; /* kEdgeAtlasFragmentShader, kEdgeBlockFragmentShader; 0: no edges */ + bool edge_tried_ = false; + bool edge_effects(); + /* The edge of the host whose rect holds e's video on target ti, or none. */ + VideoEdge edge_for(int ti, const Entry &e) const; int atlas_view_fx_ = 0, block_view_fx_ = 0; /* the composite's, made with the first one */ std::string plan_error_; /* why the last reconcile changed nothing; logged once */ std::map layers_; diff --git a/native/cluster-render/src/server.cpp b/native/cluster-render/src/server.cpp index a180aef8..0a826b47 100644 --- a/native/cluster-render/src/server.cpp +++ b/native/cluster-render/src/server.cpp @@ -833,10 +833,25 @@ void Server::op_host(Client &c, uint32_t ref, const cr::Json &j) refuse("src_x, src_y, src_w, src_h go together (none: all of " + from.name + ")"); return; } + /* the optional edge drawn on the hosted picture (PROTOCOL.md "host") */ + static const char *const edge_keys[] = {"edge_top", "edge_bottom", "edge_fade", "edge_dim", "edge_blur"}; + static const double edge_max[] = {720, 720, 360, 4096, 32}; + double ev[5] = {0, 0, 0, 0, 0}; + for (size_t i = 0; i < 5; i++) + if (!num(j, edge_keys[i], 0, edge_max[i], &ev[i], &err)) { + comp_->unhost(c.id, scene, hosted); + refuse(err); + return; + } Host h; h.rect = Rect{(int32_t)v[0], (int32_t)v[1], (uint32_t)v[2], (uint32_t)v[3]}; h.src = Rect{(int32_t)v[4], (int32_t)v[5], (uint32_t)v[6], (uint32_t)v[7]}; h.shown = v[8] != 0; + h.edge.top = (uint32_t)ev[0]; + h.edge.bottom = (uint32_t)ev[1]; + h.edge.fade = (uint32_t)ev[2]; + h.edge.dim = (uint32_t)ev[3]; + h.edge.blur = (uint32_t)ev[4]; if (!comp_->host(c.id, scene, hosted, h, &err)) { refuse(err); return; diff --git a/native/cluster-render/src/video_layer.cpp b/native/cluster-render/src/video_layer.cpp index 827e19fd..2f0c6e31 100644 --- a/native/cluster-render/src/video_layer.cpp +++ b/native/cluster-render/src/video_layer.cpp @@ -15,6 +15,94 @@ namespace crs { using crk::PixelRect; using crk::UploadPlan; +/* An edge quad (VideoEdge): rgb_at(x) is the picture's colour at x on row + * u_edge.x (a pixel centre), as its own shader draws it; d, the distance + * past the rect, runs from u_edge.y at the quad's top to u_edge.z at its + * bottom (negative: inside, where the picture fades into the edge over + * u_edge.w px); u_look is dim and the blur's sigma in the frame's pixels: + * nine taps sigma / 2 apart. The two differ in rgb_at only. */ + +/* yuv_atlas.cpp's colour at a point of the row */ +const char *const kEdgeAtlasFragmentShader = R"(#version 100 +precision highp float; +uniform sampler2D u_image; +uniform vec2 u_size; +uniform vec4 u_edge; +uniform vec2 u_look; +uniform float u_opacity; +varying vec2 v_uv; +vec3 rgb_at(float px) { + vec2 l = vec2(clamp(px, 0.5, u_size.x - 0.5), u_edge.x); + float th = u_size.y * 1.5; + vec2 c = clamp(vec2(l.x * 0.5 + 0.25, l.y * 0.5), vec2(0.5), u_size * 0.5 - 0.5); + float y = texture2D(u_image, vec2(l.x / u_size.x, l.y / th)).r; + float u = texture2D(u_image, vec2(c.x / u_size.x, (u_size.y + c.y) / th)).r - 128.0 / 255.0; + float v = texture2D(u_image, vec2((u_size.x * 0.5 + c.x) / u_size.x, (u_size.y + c.y) / th)).r - 128.0 / 255.0; + return clamp(vec3(y + 1.402 * v, y - 0.344136 * u - 0.714136 * v, y + 1.772 * u), 0.0, 1.0); +} +void main() { + float d = mix(u_edge.y, u_edge.z, v_uv.y); + float x = v_uv.x * u_size.x; + vec3 c = vec3(0.0); + float n = 0.0; + for (int k = -4; k <= 4; k++) { + float o = float(k) * 0.5; + float w = exp(-0.5 * o * o); + c += w * rgb_at(x + o * u_look.y); + n += w; + } + float dim = u_look.x > 0.0 ? max(0.25, 1.0 - max(d, 0.0) / u_look.x) : 1.0; + float a = d >= 0.0 ? 1.0 : clamp(1.0 + d / max(u_edge.w, 1.0), 0.0, 1.0); + gl_FragColor = vec4(c / n * dim, a * u_opacity); +})"; + +/* block_pack.cpp's colour at a point of the row */ +const char *const kEdgeBlockFragmentShader = R"(#version 100 +precision highp float; +uniform sampler2D u_image; +uniform vec2 u_size; +uniform vec4 u_edge; +uniform vec2 u_look; +uniform float u_opacity; +varying vec2 v_uv; +float byte_of(float s) { return floor(s * 255.0 + 0.5); } +vec3 rgb565(float lo, float hi) { + float v = hi * 256.0 + lo; + float r = floor(v / 2048.0); + float g = floor(mod(v, 2048.0) / 32.0); + float b = mod(v, 32.0); + return vec3(r / 31.0, g / 63.0, b / 31.0); +} +vec3 rgb_at(float px) { + vec2 p = clamp(floor(vec2(px, u_edge.x)), vec2(0.0), u_size - 1.0); + vec2 blk = floor(p / 4.0); + vec2 q = p - blk * 4.0; + vec2 tex = vec2(u_size.x * 0.5, u_size.y * 0.25); + vec4 e = texture2D(u_image, vec2(blk.x * 2.0 + 0.5, blk.y + 0.5) / tex); + vec4 s = texture2D(u_image, vec2(blk.x * 2.0 + 1.5, blk.y + 0.5) / tex); + vec3 c0 = rgb565(byte_of(e.r), byte_of(e.g)); + vec3 c1 = rgb565(byte_of(e.b), byte_of(e.a)); + float row = byte_of(q.y < 1.0 ? s.r : q.y < 2.0 ? s.g : q.y < 3.0 ? s.b : s.a); + float div = q.x < 1.0 ? 1.0 : q.x < 2.0 ? 4.0 : q.x < 3.0 ? 16.0 : 64.0; + float sel = mod(floor(row / div), 4.0); + return sel < 0.5 ? c0 : sel < 1.5 ? c1 : sel < 2.5 ? (2.0 * c0 + c1) / 3.0 : (c0 + 2.0 * c1) / 3.0; +} +void main() { + float d = mix(u_edge.y, u_edge.z, v_uv.y); + float x = v_uv.x * u_size.x; + vec3 c = vec3(0.0); + float n = 0.0; + for (int k = -4; k <= 4; k++) { + float o = float(k) * 0.5; + float w = exp(-0.5 * o * o); + c += w * rgb_at(x + o * u_look.y); + n += w; + } + float dim = u_look.x > 0.0 ? max(0.25, 1.0 - max(d, 0.0) / u_look.x) : 1.0; + float a = d >= 0.0 ? 1.0 : clamp(1.0 + d / max(u_edge.w, 1.0), 0.0, 1.0); + gl_FragColor = vec4(c / n * dim, a * u_opacity); +})"; + VideoLayer::VideoLayer(uint32_t id, int target, uint64_t seq, crk::UploadPacer &pacer, int atlas_effect, int block_effect, const VideoParams &p, int64_t now_ms) : Layer(id, target, seq, pacer), p_(p), atlas_effect_(atlas_effect), block_effect_(block_effect), @@ -248,6 +336,7 @@ bool VideoLayer::attach(Graph *g, int64_t now_ms, std::string *err) detach(true); return false; } + make_edge_quads(); clock_.reset(now_ms); return true; } @@ -274,6 +363,65 @@ void VideoLayer::drop_quads() { if (atlas_quad_) g_->drop_quad(atlas_quad_); if (block_quad_) g_->drop_quad(block_quad_); + drop_edge_quads(); +} + +bool VideoLayer::set_edge(const VideoEdge &e, int atlas_effect, int block_effect) +{ + if (e == edge_ && (!e.on() || (atlas_effect == edge_fx_[0] && block_effect == edge_fx_[1]))) + return false; + edge_ = e; + edge_fx_[0] = atlas_effect; + edge_fx_[1] = block_effect; + if (g_) { + drop_edge_quads(); + make_edge_quads(); + } + return true; +} + +/* Over the picture (its order + 2), each sampling what its kind's quad + * does, shown and faded as that is; a kind or side the renderer refuses is + * not drawn. */ +void VideoLayer::make_edge_quads() +{ + if (!g_ || !edge_.on()) + return; + const Rect r = edge_at_ = drawn_params().rect; + const float size[2] = {(float)p_.w, (float)p_.h}, zero = 0.0f; + const float look[2] = {(float)edge_.dim, r.w ? (float)edge_.blur * p_.w / r.w : 0.0f}; + const uint32_t in = std::min(kEdgeInset, p_.h - 1); + for (int k = 0; k < (p_.pan_blocks ? 2 : 1); k++) + for (int side = 0; side < 2; side++) { + const uint32_t past = side ? edge_.bottom : edge_.top; + if (!past || !edge_fx_[k]) + continue; + const Rect er = side ? Rect{r.x, r.y + (int32_t)(r.h - edge_.fade), r.w, edge_.fade + past} + : Rect{r.x, r.y - (int32_t)past, r.w, past + edge_.fade}; + const float e[4] = {(float)(side ? p_.h - 1 - in : in) + 0.5f, side ? -(float)edge_.fade : (float)past, + side ? (float)past : -(float)edge_.fade, (float)edge_.fade}; + int &q = edge_quad_[k][side]; + q = g_->quad(edge_fx_[k], er); + if (q && !(g_->texture(q, "u_image", k ? block_buf_[block_bank_] : atlas_buf_) && + g_->uniform(q, "u_size", size, 2) && g_->uniform(q, "u_edge", e, 4) && + g_->uniform(q, "u_look", look, 2) && g_->uniform(q, "u_opacity", &zero, 1) && + g_->order(q, order_ + 2))) { + g_->drop_quad(q); + q = 0; + } + } + show_quads(blocks_shown_); + set_opacity(); +} + +void VideoLayer::drop_edge_quads() +{ + for (auto &kind : edge_quad_) + for (int &q : kind) { + if (q && g_) + g_->drop_quad(q); + q = 0; + } } void VideoLayer::drop_objects() @@ -298,6 +446,7 @@ void VideoLayer::detach(bool drop) g_ = nullptr; hiding_ = shown_drawn_ = forced_write_ = false; atlas_buf_ = atlas_quad_ = block_quad_ = 0; + edge_quad_[0][0] = edge_quad_[0][1] = edge_quad_[1][0] = edge_quad_[1][1] = 0; block_buf_[0] = block_buf_[1] = 0; blocks_shown_ = parked_ = false; drawn_ = false; @@ -318,11 +467,19 @@ void VideoLayer::show_quads(bool blocks) g_->show(atlas_quad_, drawn_ && !blocks); if (block_quad_) g_->show(block_quad_, drawn_ && blocks); + for (int side = 0; side < 2; side++) + for (int k = 0; k < 2; k++) + if (edge_quad_[k][side]) + g_->show(edge_quad_[k][side], drawn_ && blocks == (k == 1)); } bool VideoLayer::bank_quads(int buf) { - return g_->texture(block_quad_, "u_image", buf); + bool ok = g_->texture(block_quad_, "u_image", buf); + for (int side = 0; side < 2; side++) + if (edge_quad_[1][side]) + ok = g_->texture(edge_quad_[1][side], "u_image", buf) && ok; + return ok; } void VideoLayer::set_opacity() @@ -331,6 +488,10 @@ void VideoLayer::set_opacity() g_->uniform(atlas_quad_, "u_opacity", &a, 1); if (block_quad_) g_->uniform(block_quad_, "u_opacity", &a, 1); + for (auto &kind : edge_quad_) + for (int q : kind) + if (q) + g_->uniform(q, "u_opacity", &a, 1); } void VideoLayer::arrange(bool drawn, int32_t order) @@ -343,6 +504,10 @@ void VideoLayer::arrange(bool drawn, int32_t order) g_->order(atlas_quad_, order); if (block_quad_) g_->order(block_quad_, order + 1); + for (auto &kind : edge_quad_) + for (int q : kind) + if (q) + g_->order(q, order + 2); } void VideoLayer::place() @@ -355,6 +520,10 @@ void VideoLayer::place() g_->place(block_quad_, drawn_params().rect); g_->turn(block_quad_, drawn_params().turn()); } + if (edge_.on() && drawn_params().rect != edge_at_) { /* the edge's quads and blur follow the rect */ + drop_edge_quads(); + make_edge_quads(); + } set_opacity(); } diff --git a/native/cluster-render/src/video_layer.h b/native/cluster-render/src/video_layer.h index 96604f38..4ac77eb4 100644 --- a/native/cluster-render/src/video_layer.h +++ b/native/cluster-render/src/video_layer.h @@ -76,6 +76,25 @@ struct VideoParams { bool always_packed = false; }; +/* A host's edge (PROTOCOL.md "host"): the picture's rows kEdgeInset in + * from its top and its bottom drawn on past them, top px above its rect and + * bottom px below, blurred along the row by a Gaussian of sigma blur px (0: + * none) and darkened with the distance d from the rect to max(1/4, 1 - d / + * dim) (dim 0: not); the picture's own rows fade into them over fade px + * inside the rect. top and bottom 0: none. */ +struct VideoEdge { + uint32_t top = 0, bottom = 0, fade = 0, dim = 0, blur = 0; + bool on() const { return top || bottom; } + bool operator==(const VideoEdge &o) const + { + return top == o.top && bottom == o.bottom && fade == o.fade && dim == o.dim && blur == o.blur; + } + bool operator!=(const VideoEdge &o) const { return !(*this == o); } +}; +/* The edge quads' effects: the atlas's colour and the packed blocks'. */ +extern const char *const kEdgeAtlasFragmentShader; +extern const char *const kEdgeBlockFragmentShader; + class VideoLayer : public Layer { public: /* The packed quad gives way to the exact atlas once no update has needed @@ -121,6 +140,14 @@ class VideoLayer : public Layer { const VideoParams &video() const { return p_; } + /* Its edge (none by default), within its target (the caller clamps + * it), drawn by these effects of the edge shaders above: two quads a + * kind, over the picture, shown with the atlas or the packed one. True + * when it changed. A turned layer's edge is drawn unturned. */ + bool set_edge(const VideoEdge &e, int atlas_effect, int block_effect); + const VideoEdge &edge() const { return edge_; } + static const uint32_t kEdgeInset = 2; + /* The atlas tiles (row by row, planner's) the next flush shows wholly * under opaque layers, given each tick before stage(); null: none. */ void hide(const uint8_t *tiles); @@ -243,6 +270,12 @@ class VideoLayer : public Layer { bool have_ = false; int atlas_quad_ = 0, block_quad_ = 0; + VideoEdge edge_; + int edge_fx_[2] = {0, 0}; + int edge_quad_[2][2] = {{0, 0}, {0, 0}}; /* [atlas, blocks][top, bottom] */ + Rect edge_at_; /* the rect they were made for */ + void make_edge_quads(); + void drop_edge_quads(); /* parked_: a failed exact write left the atlas unlike any frame; the * target holds its flushes until the next whole write. first_: the * scene's first write is still to go. source_: drawn by the composite. */ diff --git a/native/cluster-render/test/service_test.cpp b/native/cluster-render/test/service_test.cpp index e8b6335f..82fac2a2 100644 --- a/native/cluster-render/test/service_test.cpp +++ b/native/cluster-render/test/service_test.cpp @@ -1319,6 +1319,39 @@ static void layers_and_hosting() r.pump(100); ok("edits flush with the layers", gauge_edited_turn(r.gpu.file("panel"), 45)); + /* The host's edge: two quads over the producer's video draw its rows 2 + * in from its top and bottom on past its rect, held within the panel + * (160 below it), the picture fading into them; out of range refused; + * without it, none. */ + cr::Host eh = h; + eh.edge_top = 50; + eh.edge_bottom = 400; + eh.edge_fade = 36; + eh.edge_dim = 160; + eh.edge_blur = 9; + a.host(sc, eh); + r.pump(100); + g = r.gpu.graph("panel"); + std::vector edges; + for (int q : g->visible()) + if (g->shown.quads.at(q).uniforms.count("u_edge")) + edges.push_back(g->shown.quads.at(q)); + ok("an edge: two quads over the video, 50 up and 160 down (the panel's end), the picture fading into them over 36", + g->visible().size() == 4 && edges.size() == 2 && edges[0].r.x == 700 && edges[0].r.w == 560 && edges[0].r.y == 110 && + edges[0].r.h == 86 && edges[1].r.y == 524 && edges[1].r.h == 196 && + edges[0].uniforms["u_edge"] == std::vector({2.5f, 50, -36, 36}) && + edges[1].uniforms["u_edge"] == std::vector({397.5f, -36, 160, 36}) && + edges[0].uniforms["u_look"] == std::vector({160, 9}) && edges[0].uniforms["u_opacity"][0] > 0 && + eb.layer[video] == "shown" && has(r.svc->server().status_text(r.now), "its edge 50 up and 400 down")); + cr::Host blurry = eh; + blurry.edge_blur = 33; + a.host(sc, blurry); + r.pump(100); + ok("an edge out of range refused", has(ea.errors, "host: edge_blur must be a number from 0 to 32")); + a.host(sc, h); + r.pump(100); + ok("hosted again without an edge: no edge quads", b.hosts.count("map") && g->visible().size() == 2); + /* The video's write refused: it holds the target (a half-written * buffer); the file's edits flush all the same. */ g->write_budget = 0; From f06ef9dbacd3ec22ce8f27399103e1bf6f89ac43 Mon Sep 17 00:00:00 2001 From: IterioDev Date: Thu, 19 Nov 2026 16:42:44 +0200 Subject: [PATCH 2/3] cluster-render: PROTOCOL.md and README for a host's edge Co-Authored-By: Claude Opus 5.5 --- native/cluster-render/PROTOCOL.md | 17 ++++++++++++++++- native/cluster-render/README.md | 5 ++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/native/cluster-render/PROTOCOL.md b/native/cluster-render/PROTOCOL.md index 1ad57a6f..827e28c7 100644 --- a/native/cluster-render/PROTOCOL.md +++ b/native/cluster-render/PROTOCOL.md @@ -45,7 +45,7 @@ lacks. | `stop` | `ref`, `anim` | | `scene` | `ref`, `target`, `file`, `res`, `sha256`, `contend`, `layers`, `layers_order` ([below](#scene-files)); sent again with its ref, another file in place | | `edit` | `ref` (a scene), `lines` ([below](#scene-edits)) | -| `host` | `ref` (a scene with `layers` 1), `target`, `x`, `y`, `w`, `h`, `src_x`, `src_y`, `src_w`, `src_h`, `shown` ([below](#hosting-another-target)) | +| `host` | `ref` (a scene with `layers` 1), `target`, `x`, `y`, `w`, `h`, `src_x`, `src_y`, `src_w`, `src_h`, `shown`; optional `edge_top`, `edge_bottom`, `edge_fade`, `edge_dim`, `edge_blur` ([below](#hosting-another-target)) | | `drop` | `ref`: a layer, a scene, or an asset no layer samples (else refused: `asset in use`) | | `repeat` | `ref` (a video layer): a frame whose atlas is the layer's last frame's, byte for byte, in place of that frame; to a service whose hello has `repeat` 1 | | `status` | — (answered by a `status` event) | @@ -429,6 +429,21 @@ messages and send them again after a reconnect, except one the service refused or one whose scene was sent again since, and send none for a scene without `layers` or for the scene's own target. +A host may also ask for an edge on the hosted picture, for a rect shorter +than the shape the scene shows it in: the service draws the rows 2 px in +from the top and from the bottom of each video another client draws inside +the rect (the hosted producer's) on past it, `edge_top` px above and +`edge_bottom` px below (held within the scene's target), blurred along the +row by a Gaussian of sigma `edge_blur` px (0 to 32; 0: not blurred), and +darkened with the distance d from the rect to max(1/4, 1 - d / `edge_dim`) +(0: not darkened); the picture's own rows fade into the edge over +`edge_fade` px inside the rect. All five default to 0; with `edge_top` and +`edge_bottom` 0 there is none. The edge is drawn by the service over the +video, in its fade, and only while the host is shown; the producer sends +nothing more for it, and the `host` event does not carry it. Unturned +videos only, and not for videos the target draws through one composite. A +service older than these fields ignores them. + ## Service to client Every JSON message has `ev`. diff --git a/native/cluster-render/README.md b/native/cluster-render/README.md index 6d2f374b..bf416f3b 100644 --- a/native/cluster-render/README.md +++ b/native/cluster-render/README.md @@ -230,7 +230,10 @@ Beside the layers: only from under `/var/opt/`, owned by root and writable by no one else, with the SHA-256 the client gives. With `layers` 1 the target's layers are drawn over the file (RAMSES 19 only), and the scene may host another - target's content (PROTOCOL.md "Hosting another target"). + target's content (PROTOCOL.md "Hosting another target"), with an + optional edge: the hosted picture's top and bottom rows drawn on past its + rect, blurred and darkened, for a picture shorter than the shape it shows + in. Each target's changes are flushed together once a tick, so the cluster never shows a half-written frame: a video or exclusive image left half written From 2dcead25c6e32037300ea91649b29f6c54834b8a Mon Sep 17 00:00:00 2001 From: IterioDev Date: Thu, 19 Nov 2026 16:48:24 +0200 Subject: [PATCH 3/3] cluster-render: the hello says the service takes a host's edge host_edge 1 in the hello, as always_packed: a client sends edge_* only to a service that draws them (an older one ignores the fields). The Node client keeps it as hostEdge. Co-Authored-By: Claude Opus 5.5 --- native/cluster-render/PROTOCOL.md | 7 ++++--- native/cluster-render/js/cluster_render_client.js | 1 + native/cluster-render/js/test/client_test.js | 3 ++- native/cluster-render/src/server.cpp | 3 ++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/native/cluster-render/PROTOCOL.md b/native/cluster-render/PROTOCOL.md index 827e28c7..e0dc523b 100644 --- a/native/cluster-render/PROTOCOL.md +++ b/native/cluster-render/PROTOCOL.md @@ -441,8 +441,9 @@ darkened with the distance d from the rect to max(1/4, 1 - d / `edge_dim`) `edge_bottom` 0 there is none. The edge is drawn by the service over the video, in its fade, and only while the host is shown; the producer sends nothing more for it, and the `host` event does not carry it. Unturned -videos only, and not for videos the target draws through one composite. A -service older than these fields ignores them. +videos only, and not for videos the target draws through one composite. +Send them only to a service whose hello has `host_edge` 1 (an older one +ignores them, and draws no edge). ## Service to client @@ -450,7 +451,7 @@ Every JSON message has `ev`. | ev | Fields | When | |---|---|---| -| `hello` | `proto`, `backend` (`id7`, or `id8` on iDrive 8), `targets` (`map:1088x480,panel:1920x720,hud:800x480`; on iDrive 8 `map:874x749,hud:353x203,guide:702x213,widget:2240x896,popup:2240x896`, then any a drop-in adds, README.md "iDrive 8"), `repeat` (1: takes `repeat`), `always_packed` (1: takes a video layer's `always_packed`; absent from older services) | after the client's hello | +| `hello` | `proto`, `backend` (`id7`, or `id8` on iDrive 8), `targets` (`map:1088x480,panel:1920x720,hud:800x480`; on iDrive 8 `map:874x749,hud:353x203,guide:702x213,widget:2240x896,popup:2240x896`, then any a drop-in adds, README.md "iDrive 8"), `repeat` (1: takes `repeat`), `always_packed` (1: takes a video layer's `always_packed`; absent from older services), `host_edge` (1: takes a `host`'s `edge_*`; absent from older services) | after the client's hello | | `layer` | `ref`, `state`, `reason` | the layer's state changed | | `target` | `target`, `state`, `holder`, `reason`, `retry_in_ms`, `rendering`, `guide_disabled`, `disabled` | a target's state changed | | `budget` | `cap_kb_per_s`, `max_kb_per_s`, `floor_kb_per_s`, `reason` | the upload cap changed | diff --git a/native/cluster-render/js/cluster_render_client.js b/native/cluster-render/js/cluster_render_client.js index 747d047f..f34e342f 100644 --- a/native/cluster-render/js/cluster_render_client.js +++ b/native/cluster-render/js/cluster_render_client.js @@ -228,6 +228,7 @@ class ClusterRender extends EventEmitter { if (ev.ev === 'hello') { this.backend = ev.backend; this.targets = ev.targets; + this.hostEdge = ev.host_edge === 1; /* takes a host's edge_* */ this.ready = true; this.backoff = 0; this._pump(); diff --git a/native/cluster-render/js/test/client_test.js b/native/cluster-render/js/test/client_test.js index 538cb0d3..1bb1fd35 100644 --- a/native/cluster-render/js/test/client_test.js +++ b/native/cluster-render/js/test/client_test.js @@ -181,7 +181,8 @@ async function main() { ovl.host(over, { target: 'map', x: 700, y: 160, w: 560, h: 400, src_x: 264, src_w: 560, src_h: 400, src_y: 40 }); const sent = ovl.layers.get(over).hosts.get('map'); ok('with them, all four', sent.src_x === 264 && sent.src_y === 40 && sent.src_w === 560 && sent.src_h === 400); - ok('no edge unless edge_top or edge_bottom is set', !('edge_fade' in sent)); + ok('no edge unless edge_top or edge_bottom is set; the hello says the service takes one', !('edge_fade' in sent) && + ovl.hostEdge === true); ok('it hosts the map: the other client told', await until(() => hosted.indexOf('map:panel:1:560') >= 0, 2000)); ovl.host(over, { target: 'map', x: 700, y: 160, w: 560, h: 400, edge_top: 40, edge_blur: 9 }); const edged = ovl.layers.get(over).hosts.get('map'); diff --git a/native/cluster-render/src/server.cpp b/native/cluster-render/src/server.cpp index 0a826b47..a8b40a74 100644 --- a/native/cluster-render/src/server.cpp +++ b/native/cluster-render/src/server.cpp @@ -605,7 +605,8 @@ void Server::on_json(Client &c, const std::string &body, int64_t now_ms) {"backend", cr::json_quote(backend_)}, {"targets", cr::json_quote(targets)}, {"repeat", "1"}, - {"always_packed", "1"}})); + {"always_packed", "1"}, + {"host_edge", "1"}})); c.target_sent.clear(); c.host_sent.clear(); c.host_gen = 0;