| 1 | // SPDX-License-Identifier: MPL-2.0 |
| 2 | // Copyright (c) Yuxuan Shui <[email protected]> |
| 3 | |
| 4 | #pragma once |
| 5 | #include <pixman.h> |
| 6 | #include <stdint.h> |
| 7 | #include <xcb/xproto.h> |
| 8 | |
| 9 | #include <picom/types.h> |
| 10 | |
| 11 | #include "config.h" |
| 12 | #include "region.h" |
| 13 | #include "wm/wm.h" |
| 14 | |
| 15 | /// A layer to be rendered in a render layout |
| 16 | struct layer { |
| 17 | /// Window that will be rendered in this layer |
| 18 | wm_treeid key; |
| 19 | /// The window, this is only valid for the current layout. Once |
| 20 | /// a frame has passed, windows could have been freed. |
| 21 | struct win *win; |
| 22 | struct window_options options; |
| 23 | /// Damaged region of this layer, in screen coordinates |
| 24 | region_t damaged; |
| 25 | /// Window rectangle in screen coordinates, before it's scaled. |
| 26 | struct ibox window; |
| 27 | /// Shadow rectangle in screen coordinates, before it's scaled. |
| 28 | struct ibox shadow; |
| 29 | /// Scale of the window. The origin of scaling is the top left corner of the |
| 30 | /// window. |
| 31 | vec2 scale; |
| 32 | /// Scale of the shadow. The origin of scaling is the top left corner of the |
| 33 | /// shadow. |
| 34 | vec2 shadow_scale; |
| 35 | /// Opacity of this window |
| 36 | float opacity; |
| 37 | /// Opacity of the background blur of this window |
| 38 | float blur_opacity; |
| 39 | /// Color of this window's shadow, alpha is shadow opacity |
| 40 | struct color shadow_color; |
| 41 | /// How much the image of this window should be blended with the saved image |
| 42 | float saved_image_blend; |
| 43 | /// Crop the content of this layer to this box, in screen coordinates. |
| 44 | struct ibox crop; |
| 45 | |
| 46 | /// How many commands are needed to render this layer |
| 47 | unsigned number_of_commands; |
| 48 | |
| 49 | /// Rank of this layer in the previous frame, -1 if this window |
| 50 | /// appears in this frame for the first time |
| 51 | int prev_rank; |
| 52 | /// Rank of this layer in the next frame, -1 if this window is |
| 53 | /// removed in the next frame |
| 54 | int next_rank; |
| 55 | |
| 56 | // TODO(yshui) make opaqueness/blur finer grained maybe? to support |
| 57 | // things like blur-background-frame |
| 58 | // region_t opaque_region; |
| 59 | // region_t blur_region; |
| 60 | }; |
| 61 | |
| 62 | /// Layout of windows at a specific frame |
| 63 | struct layout { |
| 64 | ivec2 size; |
| 65 | /// The root image generation, see `struct session::root_image_generation` |
| 66 | uint64_t root_image_generation; |
| 67 | /// Layers as a flat array, from bottom to top in stack order. This is a dynarr. |
| 68 | struct layer *layers; |
| 69 | /// Number of commands in `commands` |
| 70 | unsigned number_of_commands; |
| 71 | /// Where does the commands for the bottom most layer start. |
| 72 | /// Any commands before that is for the desktop background. |
| 73 | unsigned first_layer_start; |
| 74 | /// Commands that are needed to render this layout. Commands |
| 75 | /// are recorded in the same order as the layers they correspond to. Each layer |
| 76 | /// can have 0 or more commands associated with it. |
| 77 | struct backend_command *commands; |
| 78 | }; |
| 79 | |
| 80 | struct wm; |
| 81 | struct layout_manager; |
| 82 | |
| 83 | /// Compute the layout of windows to be rendered in the current frame, and append it to |
| 84 | /// the end of layout manager's ring buffer. The layout manager has a ring buffer of |
| 85 | /// layouts, with its size chosen at creation time. Calling this will push at new layout |
| 86 | /// at the end of the ring buffer, and remove the oldest layout if the buffer is full. |
| 87 | void layout_manager_append_layout(struct layout_manager *lm, struct wm *wm, |
| 88 | uint64_t root_pixmap_generation, ivec2 size); |
| 89 | /// Get the layout `age` frames into the past. Age `0` is the most recently appended |
| 90 | /// layout. |
| 91 | struct layout *layout_manager_layout(struct layout_manager *lm, unsigned age); |
| 92 | void layout_manager_free(struct layout_manager *lm); |
| 93 | /// Clear all layouts in the layout manager, so that the next render will start from |
| 94 | /// scratch instead of incremental based on damage information. |
| 95 | void layout_manager_clear(struct layout_manager *lm); |
| 96 | /// Create a new render lm with a ring buffer for `max_buffer_age` layouts. |
| 97 | struct layout_manager *layout_manager_new(unsigned max_buffer_age); |
| 98 | /// Collect damage from the window for the past `buffer_age` frames. |
| 99 | void layout_manager_collect_window_damage(const struct layout_manager *lm, unsigned index, |
| 100 | unsigned buffer_age, region_t *damage); |
| 101 | /// Find where layer at `index` was `buffer_age` frames ago. |
| 102 | int layer_prev_rank(struct layout_manager *lm, unsigned buffer_age, unsigned index_); |
| 103 | /// Find layer that was at `index` `buffer_age` aga in the current layout. |
| 104 | int layer_next_rank(struct layout_manager *lm, unsigned buffer_age, unsigned index_); |
| 105 | unsigned layout_manager_max_buffer_age(const struct layout_manager *lm); |