Skip to content
Myr

render: sync rounded corners implementation with fnott's

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Daniel Eklöf · committed by Daniel Eklöf · parent 6d36913 · Browse files · 1 file+46 added−14 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+46 added−14 removed

  • other:+46 added−14 removed

1 file+46 added−14 removed

modified:render.c+46 added-14 removed
127 unmodified lines
128 ? round(pt_or_px->pt * scale * dpi / 72.)129 : pt_or_px->px;130}131132static void133fill_rounded_rectangle(pixman_op_t op, pixman_image_t* dest,134 const pixman_color_t* color, int16_t x, int16_t y,135 uint16_t width, uint16_t height, uint16_t radius)132static pixman_region32_t133rounded_rectangle_region(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t radius)134{135136 int rect_count = ( radius + radius ) + 1;138 pixman_rectangle16_t rects[rect_count];137 pixman_box32_t rects[rect_count];138140 for (int i = 0; i <= radius; i++){139 for (int i = 0; i <= radius; i++) {140 uint16_t ydist = radius - i;141 uint16_t curve = sqrt(radius * radius - ydist * ydist);142144 rects[i] = (pixman_rectangle16_t){145 x + radius - curve, y + i, width - radius * 2 + curve * 2, 1143 rects[i] = (pixman_box32_t) {144 x + radius - curve,145 y + i,146 x + width - radius + curve,147 y + i + 1148 };149148 rects[radius + i] = (pixman_rectangle16_t){149 x + radius - curve, y + height - i, width - radius * 2 + curve * 2, 1150 rects[radius + i] = (pixman_box32_t) {151 x + radius - curve,152 y + height - i,153 x + width - radius + curve,154 y + height - i + 1155 };156 }157153 rects[(radius * 2)] = (pixman_rectangle16_t){154 x, y + radius, width, height + 1 - radius * 2158 rects[(radius * 2)] = (pixman_box32_t){159 x,160 y + radius,161 x + width,162 y + height + 1 - radius163 };156 pixman_image_fill_rectangles(op, dest, color,rect_count, rects);164165 pixman_region32_t region;166 pixman_region32_init_rects(&region, rects, rect_count);167 return region;168}169170static inline void171fill_region32(pixman_op_t op, pixman_image_t* dest,172 const pixman_color_t* color, pixman_region32_t* region)173{174 int rectc;175 pixman_box32_t *rects = pixman_region32_rectangles(region, &rectc);176 pixman_image_fill_boxes(op, dest, color, rectc, rects);177178}179180static inline void181fill_rounded_rectangle(pixman_op_t op, pixman_image_t* dest,182 const pixman_color_t* color, int16_t x, int16_t y,183 uint16_t width, uint16_t height, uint16_t radius)184{185 pixman_region32_t region = rounded_rectangle_region(x, y, width, height, radius);186 fill_region32(op, dest, color, &region);187 pixman_region32_fini(&region);188}189190void191render_background(const struct render *render, struct buffer *buf)192{193 unsigned bw = render->conf->border.size;
32 unmodified lines
226 const double brd_sz_scaled = bw * msaa_scale;227 const double brd_rad_scaled = radius * msaa_scale;228 int w = buf->width * msaa_scale;229 int h = buf->height * msaa_scale;230 int bg_rad = brd_rad_scaled * (1.0 - (float)brd_sz_scaled / (float)brd_rad_scaled);231232 pixman_image_t *bg_img;233 if (msaa_scale != 1){234 bg_img = pixman_image_create_bits(PIXMAN_a8r8g8b8, w, h, NULL, w*4);
9 unmodified lines
244 fill_rounded_rectangle(245 PIXMAN_OP_SRC, bg_img, &bg, brd_sz_scaled, brd_sz_scaled,246 w-(brd_sz_scaled*2),247 h-(brd_sz_scaled*2),216 max(brd_rad_scaled - brd_sz_scaled, 0));248 bg_rad);249250 if (msaa_scale != 1){251 pixman_f_transform_t ftrans;252 pixman_transform_t trans;
1444 unmodified lines