Skip to content

Commit b53f0b3

Browse files
committed
Add dev.html page
1 parent aa4a148 commit b53f0b3

File tree

6 files changed

+59
-0
lines changed

6 files changed

+59
-0
lines changed

deploy/img/dev/img-buf1.png

21.7 KB
Loading

deploy/img/dev/img-buf2.png

23.5 KB
Loading

deploy/img/dev/img-buf3.png

6.63 KB
Loading

deploy/img/dev/img-buf4.png

50 KB
Loading

src/dev.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Developer Section
2+
3+
1. [Image Buffers](#img-buf)
4+
5+
# 1. Image Buffers {#img-buf}
6+
7+
Ref: [#2489](https://github.com/labwc/labwc/pull/2489)
8+
9+
This relates to the structs `lab_img`, `lab_image_cache` and
10+
`scaled_img_buffer`.
11+
12+
- When creating a `scaled_img_buffer`, `lab_img` is replicated via
13+
`lab_img_copy()`
14+
- When destroying a `scaled_img_buffer`, `lab_img` is destroyed via
15+
`lab_img_destroy()`
16+
17+
## The lifetime of `lab_img` and `lab_img_cache`
18+
19+
After startup, theme struct references `lab_img`, which references
20+
`lab_img_cache` with refcount=1. Here, `lab_img_cache` is the wrapper for
21+
`lab_data_buffer` or `RsvgHandle` and represents the actual content of the
22+
loaded image file.
23+
24+
<img src="img/dev/img-buf1.png">
25+
26+
When a window is opened and its decoration is created, the `lab_img` is copied
27+
via `lab_img_copy()` and a new `scaled_img_buffer` references it. Note that the
28+
image content is not copied here; instead, the refcount of `lab_img_cache` is
29+
incremented.
30+
31+
<img src="img/dev/img-buf2.png">
32+
33+
When the theme is de-initialized in `theme_finish()` and the `lab_img`
34+
referenced by theme is destroyed, the `lab_img` referenced by the
35+
`scaled_img_buffer` and `lab_img_cache` outlive. Therefore, it's safe for
36+
`_update_buffer()` in `scaled-img-buffer.c` to be called.
37+
38+
<img src="img/dev/img-buf3.png">
39+
40+
And when the decoration is destroyed via undecorate(), the `scaled_img_buffer`,
41+
`lab_img` and `lab_img_cache` are finally destroyed.
42+
43+
## Motivation for `lab_img_copy()` and `lab_img_cache`
44+
45+
For better understanding of `lab_img` API in general, let me explain the initial
46+
motivation of `lab_img_copy()` and `lab_img_cache`. `lab_img_copy()` was
47+
introduced to share the image content with different variants of buttons
48+
including normal, hovered, rounded, rounded-hovered buttons:
49+
50+
<img src="img/dev/img-buf4.png">
51+
52+
For example, when `close_hover-active.png` is not found, the `lab_img` for
53+
`close-active.png` is copied via `lab_img_copy()` and a "modifier" function
54+
that draws a hover overlay on it is added to the copied `lab_img` via
55+
`lab_img_add_modifier()`. And if the close button is placed at the corner of
56+
the titlebar, the `lab_img` is further copied and the modifier function that
57+
cuts its corner is applied.
58+

src/more.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
- [configuration](configuration.html)
2+
- [dev](dev.html)
23
- [faq](faq.html)
34
- [hidpi scaling](hidpi-scaling.html)
45
- [links](links.html)

0 commit comments

Comments
 (0)