Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] New backend interface #1191

Open
yshui opened this issue Feb 11, 2024 · 0 comments
Open

[RFC] New backend interface #1191

yshui opened this issue Feb 11, 2024 · 0 comments
Milestone

Comments

@yshui
Copy link
Owner

yshui commented Feb 11, 2024

Motivation

Current backend interface has some short comings. Here is some examples:

  1. No control where image copying happens. Backend can choose to copy image in clone_image, or it can choose to only increment a reference count there, and only do the actual copy in image_op. And implement it as a reference count increase complexity and indirection.
  2. Image properties doesn't fit the way we use them. We set these properties again and again for each frame despite them being persistent. We should either: 1) set them when they are changed, or 2) stop storing them.
  3. Some image operations should be generic, but we are creating specialized interfaces for them. For example, we should be able to blur any texture, but now we can only blur the back buffer. This creates code duplication, for example, we have shadow_from_mask and blur as separate interfaces while they are basically doing the same thing behind the scenes.

Proposal

To address this, I want to propose a new set of interfaces:

New image ops

We extend the image_op interface to include these new operations:

  1. blur. Blur a region of the target image. Arguments: a region, and a blur context.
  2. compose. Compose a second image onto the target image. Arguments: a compose context, an offset, and a source image. See below for the definition of compose context. Offset sets where the top-left corner of the source image is, in the coordinate system of the target image.

Remove indirection in image structure

To support clone_image efficiently, existing picom backends all use reference counting. And clone_image is there to support attaching different sets image properties to the same underlying image. This is cumbersome, esp. considering we set image properties repeatedly, once per frame.

Instead, we drop the concept of image properties, and instead use a compose context. The compose context changes how an image is composed onto the target image. It contains the following information:

  1. a mask image.
  2. a mask region. together with (1), can be used to mask out part of the image. the reason for two masks is because depending on the mask, it might be more efficient to store it as either a image or a list of regions.
  3. corner radius.
  4. opacity
  5. max brightness.
  6. if color is inverted.
  7. multiplicative factor, for dimming.
  8. border width. This is used together with corner radius to make sure when rounding a window with a border, the border extend into the rounded corner.
  9. optionally a custom shader.
  10. tiling parameters. how big is the tiled image, and how the image repeats.
  11. dithering. if the target texture has lower bit depth than the source image, setting this to true enabling dithering.

We setup the compose context each time we need to compose a window on to the backbuffer.

The compose operation with the compose context can also be used to:

  1. Create a mask with rounded corners. By composing a 1x1 source image, tiled to the desired size, and with a corner radius, onto an empty image.
  2. Implement the monitor repaint feature.

Support creating empty images

This is needed for things like shadow_from_mask, make_mask, and for when we actually need to create a copy of an image. It would look something like this:

image_handle new_image(size, format, clear_color)
@yshui yshui added this to the v13 milestone Feb 11, 2024
yshui added a commit that referenced this issue Apr 2, 2024
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
yshui added a commit that referenced this issue Apr 9, 2024
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
yshui added a commit that referenced this issue Apr 9, 2024
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
yshui added a commit that referenced this issue Apr 9, 2024
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
yshui added a commit that referenced this issue Apr 10, 2024
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
yshui added a commit that referenced this issue Apr 10, 2024
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
yshui added a commit that referenced this issue Apr 10, 2024
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
@absolutelynothelix absolutelynothelix added the discussion Not a bug label Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants