File: border.sksl

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (62 lines) | stat: -rw-r--r-- 2,145 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// These are taken from kColorSysOutline
const float4 dark_color = vec4(142.0, 145.0, 143.0, 255.0) / 255.0;
const float4 light_color = vec4(116.0, 119.0, 117.0, 255.0) / 255.0;

const float max_extent = 25.0;
const float border_width = 5.0;
const float half_pixel = 0.5;
uniform float u_time;
uniform int u_dark;
uniform float u_emphasis;
uniform float u_progress;
uniform float u_corner_radius;
uniform float u_insets;
uniform float2 u_resolution;

// Applies a uniform insets to coords.
float2 InsetsCoord(float2 coord, float2 resolution, float insets) {
  return (1.0 - 2.0 * insets / resolution) * coord + insets;
}

void BorderDistance(float2 coord, out float delta, out float aa) {
  float2 tl = vec2(border_width) + 2 * u_insets;
  float2 br = u_resolution - tl;
  float2 dtl = coord - tl;
  float2 dbr = br - coord;

  float extent = max_extent * u_emphasis;
  float rounded_extent = extent + u_corner_radius - border_width - half_pixel;
  if (dtl.y < extent && dtl.x < extent) {
    delta = extent - distance(coord, tl + vec2(extent));
  } else if (dtl.y < extent && dbr.x < extent) {
    delta = extent - distance(coord, vec2(br.x - extent, tl.y + extent));
  } else if (dbr.y < rounded_extent && dtl.x < rounded_extent) {
    delta = rounded_extent -
            distance(coord, vec2(tl.x + rounded_extent, br.y - rounded_extent));
    aa = half_pixel;
  } else if (dbr.y < rounded_extent && dbr.x < rounded_extent) {
    delta = rounded_extent - distance(coord, br - vec2(rounded_extent));
    aa = half_pixel;
  } else {
    delta = min(min(min(dtl.x, dtl.y), dbr.x), dbr.y);
  }
}

vec4 main(float2 coord) {
  coord = InsetsCoord(coord, u_resolution, u_insets);

  float4 border_color = light_color;
  if (u_dark > 0) {
    border_color = dark_color;
  }
  float extent = max_extent * u_emphasis;
  float delta = 0.0;
  float aa = 0.0;
  BorderDistance(coord, delta, aa);
  float opacity = 1.0 - min(max(delta / (extent + aa), 0.0), 1.0);
  return border_color * (opacity * opacity);
}