Format region.h

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-03-27 15:33:55 +00:00
parent 8155e5e453
commit 6344ae2a46
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
1 changed files with 25 additions and 30 deletions

View File

@ -1,13 +1,13 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2018 Yuxuan Shui <yshuiv7@gmail.com> // Copyright (c) 2018 Yuxuan Shui <yshuiv7@gmail.com>
#pragma once #pragma once
#include <xcb/xcb.h>
#include <stdlib.h>
#include <pixman.h> #include <pixman.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <xcb/xcb.h>
#include "utils.h"
#include "log.h" #include "log.h"
#include "utils.h"
typedef struct pixman_region32 pixman_region32_t; typedef struct pixman_region32 pixman_region32_t;
typedef struct pixman_box32 pixman_box32_t; typedef struct pixman_box32 pixman_box32_t;
@ -16,38 +16,33 @@ typedef pixman_box32_t rect_t;
RC_TYPE(region_t, rc_region, pixman_region32_init, pixman_region32_fini, static inline) RC_TYPE(region_t, rc_region, pixman_region32_init, pixman_region32_fini, static inline)
/// copy a region_t static inline void dump_region(const region_t *x) {
static inline void if (log_get_level_tls() < LOG_LEVEL_TRACE) {
copy_region(region_t *dst, const region_t *p) { return;
pixman_region32_copy(dst, (region_t *)p); }
} int nrects;
const rect_t *rects = pixman_region32_rectangles((region_t *)x, &nrects);
static inline void log_trace("nrects: %d", nrects);
dump_region(const region_t *x) { for (int i = 0; i < nrects; i++)
int nrects; log_trace("(%d, %d) - (%d, %d)", rects[i].x1, rects[i].y1, rects[i].x2,
const rect_t *rects = pixman_region32_rectangles((region_t *)x, &nrects); rects[i].y2);
log_trace("nrects: %d", nrects);
for (int i = 0; i < nrects; i++)
log_trace("(%d, %d) - (%d, %d)", rects[i].x1, rects[i].y1, rects[i].x2, rects[i].y2);
} }
/// Convert one xcb rectangle to our rectangle type /// Convert one xcb rectangle to our rectangle type
static inline rect_t static inline rect_t from_x_rect(const xcb_rectangle_t *rect) {
from_x_rect(const xcb_rectangle_t *rect) { return (rect_t){
return (rect_t) { .x1 = rect->x,
.x1 = rect->x, .y1 = rect->y,
.y1 = rect->y, .x2 = rect->x + rect->width,
.x2 = rect->x + rect->width, .y2 = rect->y + rect->height,
.y2 = rect->y + rect->height, };
};
} }
/// Convert an array of xcb rectangles to our rectangle type /// Convert an array of xcb rectangles to our rectangle type
/// Returning an array that needs to be freed /// Returning an array that needs to be freed
static inline rect_t * static inline rect_t *from_x_rects(int nrects, const xcb_rectangle_t *rects) {
from_x_rects(int nrects, const xcb_rectangle_t *rects) { rect_t *ret = ccalloc(nrects, rect_t);
rect_t *ret = ccalloc(nrects, rect_t); for (int i = 0; i < nrects; i++)
for (int i = 0; i < nrects; i++) ret[i] = from_x_rect(rects + i);
ret[i] = from_x_rect(rects+i); return ret;
return ret;
} }