static void draw_view_source_clipped(struct weston_view *view, struct weston_output *output, pixman_region32_t *repaint_global) { struct weston_surface *surface = view->surface; pixman_region32_t surf_region; pixman_region32_t buffer_region; pixman_region32_t repaint_output; /* Do not bother separating the opaque region from non-opaque. * Source clipping requires PIXMAN_OP_OVER in all cases, so painting * opaque separately has no benefit. */ pixman_region32_init_rect(&surf_region, 0, 0, surface->width, surface->height); if (view->geometry.scissor_enabled) pixman_region32_intersect(&surf_region, &surf_region, &view->geometry.scissor); pixman_region32_init(&buffer_region); weston_surface_to_buffer_region(surface, &surf_region, &buffer_region); pixman_region32_init(&repaint_output); pixman_region32_copy(&repaint_output, repaint_global); region_global_to_output(output, &repaint_output); repaint_region(view, output, &repaint_output, &buffer_region, PIXMAN_OP_OVER); pixman_region32_fini(&repaint_output); pixman_region32_fini(&buffer_region); pixman_region32_fini(&surf_region); }
/** * cairo_region_xor_rectangle: * @dst: a #cairo_region_t * @rectangle: a #cairo_rectangle_int_t * * Computes the exclusive difference of @dst with @rectangle and places the * result in @dst. That is, @dst will be set to contain all areas that are * either in @dst or in @rectangle, but not in both. * * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY * * Since: 1.10 **/ cairo_status_t cairo_region_xor_rectangle (cairo_region_t *dst, const cairo_rectangle_int_t *rectangle) { cairo_status_t status = CAIRO_STATUS_SUCCESS; pixman_region32_t region, tmp; if (dst->status) return dst->status; pixman_region32_init_rect (®ion, rectangle->x, rectangle->y, rectangle->width, rectangle->height); pixman_region32_init (&tmp); /* XXX: get an xor function into pixman */ if (! pixman_region32_subtract (&tmp, ®ion, &dst->rgn) || ! pixman_region32_subtract (&dst->rgn, &dst->rgn, ®ion) || ! pixman_region32_union (&dst->rgn, &dst->rgn, &tmp)) status = _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY); pixman_region32_fini (&tmp); pixman_region32_fini (®ion); return status; }
WL_EXPORT int wet_shell_init(struct weston_compositor *ec, int *argc, char *argv[]) { struct desktest_shell *dts; dts = zalloc(sizeof *dts); if (!dts) return -1; dts->compositor_destroy_listener.notify = shell_destroy; wl_signal_add(&ec->destroy_signal, &dts->compositor_destroy_listener); weston_layer_init(&dts->layer, ec); weston_layer_init(&dts->background_layer, ec); weston_layer_set_position(&dts->layer, WESTON_LAYER_POSITION_NORMAL); weston_layer_set_position(&dts->background_layer, WESTON_LAYER_POSITION_BACKGROUND); dts->background_surface = weston_surface_create(ec); if (dts->background_surface == NULL) goto out_free; dts->background_view = weston_view_create(dts->background_surface); if (dts->background_view == NULL) goto out_surface; weston_surface_set_color(dts->background_surface, 0.16, 0.32, 0.48, 1.); pixman_region32_fini(&dts->background_surface->opaque); pixman_region32_init_rect(&dts->background_surface->opaque, 0, 0, 2000, 2000); pixman_region32_fini(&dts->background_surface->input); pixman_region32_init_rect(&dts->background_surface->input, 0, 0, 2000, 2000); weston_surface_set_size(dts->background_surface, 2000, 2000); weston_view_set_position(dts->background_view, 0, 0); weston_layer_entry_insert(&dts->background_layer.view_list, &dts->background_view->layer_link); weston_view_update_transform(dts->background_view); dts->desktop = weston_desktop_create(ec, &shell_desktop_api, dts); if (dts->desktop == NULL) goto out_view; return 0; out_view: weston_view_destroy(dts->background_view); out_surface: weston_surface_destroy(dts->background_surface); out_free: free(dts); return -1; }
static void draw_view(struct weston_view *ev, struct weston_output *output, pixman_region32_t *damage) /* in global coordinates */ { struct pixman_surface_state *ps = get_surface_state(ev->surface); /* repaint bounding region in global coordinates: */ pixman_region32_t repaint; /* non-opaque region in surface coordinates: */ pixman_region32_t surface_blend; /* No buffer attached */ if (!ps->image) return; pixman_region32_init(&repaint); pixman_region32_intersect(&repaint, &ev->transform.boundingbox, damage); pixman_region32_subtract(&repaint, &repaint, &ev->clip); if (!pixman_region32_not_empty(&repaint)) goto out; if (output->zoom.active) { weston_log("pixman renderer does not support zoom\n"); goto out; } /* TODO: Implement repaint_region_complex() using pixman_composite_trapezoids() */ if (ev->transform.enabled && ev->transform.matrix.type != WESTON_MATRIX_TRANSFORM_TRANSLATE) { repaint_region(ev, output, &repaint, NULL, PIXMAN_OP_OVER); } else { /* blended region is whole surface minus opaque region: */ pixman_region32_init_rect(&surface_blend, 0, 0, ev->surface->width, ev->surface->height); pixman_region32_subtract(&surface_blend, &surface_blend, &ev->surface->opaque); if (pixman_region32_not_empty(&ev->surface->opaque)) { repaint_region(ev, output, &repaint, &ev->surface->opaque, PIXMAN_OP_SRC); } if (pixman_region32_not_empty(&surface_blend)) { repaint_region(ev, output, &repaint, &surface_blend, PIXMAN_OP_OVER); } pixman_region32_fini(&surface_blend); } out: pixman_region32_fini(&repaint); }
void DummySurface::setSize(int w, int h) { weston_surface *s = surface(); weston_surface_set_size(s, w, h); pixman_region32_fini(&s->opaque); pixman_region32_init_rect(&s->opaque, 0, 0, w, h); weston_surface_damage(s); if (m_acceptInput) { pixman_region32_fini(&s->input); pixman_region32_init_rect(&s->input, 0, 0, w, h); } }
PIXMAN_EXPORT pixman_bool_t pixman_compute_composite_region (pixman_region16_t * pRegion, pixman_image_t * pSrc, pixman_image_t * pMask, pixman_image_t * pDst, int16_t xSrc, int16_t ySrc, int16_t xMask, int16_t yMask, int16_t xDst, int16_t yDst, uint16_t width, uint16_t height) { pixman_region32_t r32; pixman_bool_t retval; pixman_region32_init (&r32); retval = pixman_compute_composite_region32 (&r32, pSrc, pMask, pDst, xSrc, ySrc, xMask, yMask, xDst, yDst, width, height); if (retval) { if (!pixman_region16_copy_from_region32 (pRegion, &r32)) retval = FALSE; } pixman_region32_fini (&r32); return retval; }
static void copy_to_hw_buffer(struct weston_output *output, pixman_region32_t *region) { struct pixman_output_state *po = get_output_state(output); pixman_region32_t output_region; pixman_region32_init(&output_region); pixman_region32_copy(&output_region, region); region_global_to_output(output, &output_region); pixman_image_set_clip_region32 (po->hw_buffer, &output_region); pixman_region32_fini(&output_region); pixman_image_composite32(PIXMAN_OP_SRC, po->shadow_image, /* src */ NULL /* mask */, po->hw_buffer, /* dest */ 0, 0, /* src_x, src_y */ 0, 0, /* mask_x, mask_y */ 0, 0, /* dest_x, dest_y */ pixman_image_get_width (po->hw_buffer), /* width */ pixman_image_get_height (po->hw_buffer) /* height */); pixman_image_set_clip_region32 (po->hw_buffer, NULL); }
void _cairo_region_fini (cairo_region_t *region) { assert (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (®ion->ref_count)); pixman_region32_fini (®ion->rgn); VG (VALGRIND_MAKE_MEM_NOACCESS (region, sizeof (cairo_region_t))); }
static void draw_view_translated(struct weston_view *view, struct weston_output *output, pixman_region32_t *repaint_global) { struct weston_surface *surface = view->surface; /* non-opaque region in surface coordinates: */ pixman_region32_t surface_blend; /* region to be painted in output coordinates: */ pixman_region32_t repaint_output; pixman_region32_init(&repaint_output); /* Blended region is whole surface minus opaque region, * unless surface alpha forces us to blend all. */ pixman_region32_init_rect(&surface_blend, 0, 0, surface->width, surface->height); if (!(view->alpha < 1.0)) { pixman_region32_subtract(&surface_blend, &surface_blend, &surface->opaque); if (pixman_region32_not_empty(&surface->opaque)) { region_intersect_only_translation(&repaint_output, repaint_global, &surface->opaque, view); region_global_to_output(output, &repaint_output); repaint_region(view, output, &repaint_output, NULL, PIXMAN_OP_SRC); } } if (pixman_region32_not_empty(&surface_blend)) { region_intersect_only_translation(&repaint_output, repaint_global, &surface_blend, view); region_global_to_output(output, &repaint_output); repaint_region(view, output, &repaint_output, NULL, PIXMAN_OP_OVER); } pixman_region32_fini(&surface_blend); pixman_region32_fini(&repaint_output); }
static void region_destroy(struct wl_resource *resource) { struct region *region = wl_resource_get_user_data(resource); pixman_region32_fini(®ion->region); free(region); }
/** * cairo_region_destroy: * @region: a #cairo_region_t * * Destroys a #cairo_region_t object created with * cairo_region_create(), cairo_region_copy(), or * or cairo_region_create_rectangle(). * * Since: 1.10 **/ void cairo_region_destroy (cairo_region_t *region) { if (region == (cairo_region_t *) &_cairo_region_nil) return; pixman_region32_fini (®ion->rgn); free (region); }
void DummySurface::setAcceptInput(bool accept) { if (m_acceptInput == accept) { return; } m_acceptInput = accept; weston_surface *s = surface(); int w = accept ? width() : 0; int h = accept ? height() : 0; pixman_region32_fini(&s->input); pixman_region32_init_rect(&s->input, 0, 0, w, h); }
static void ss_shm_buffer_destroy(struct ss_shm_buffer *buffer) { pixman_image_unref(buffer->pm_image); wl_buffer_destroy(buffer->buffer); munmap(buffer->data, buffer->size); pixman_region32_fini(&buffer->damage); wl_list_remove(&buffer->link); wl_list_remove(&buffer->free_link); free(buffer); }
static void draw_view(struct weston_view *ev, struct weston_output *output, pixman_region32_t *damage) /* in global coordinates */ { static int zoom_logged = 0; struct pixman_surface_state *ps = get_surface_state(ev->surface); /* repaint bounding region in global coordinates: */ pixman_region32_t repaint; /* No buffer attached */ if (!ps->image) return; pixman_region32_init(&repaint); pixman_region32_intersect(&repaint, &ev->transform.boundingbox, damage); pixman_region32_subtract(&repaint, &repaint, &ev->clip); if (!pixman_region32_not_empty(&repaint)) goto out; if (output->zoom.active && !zoom_logged) { weston_log("pixman renderer does not support zoom\n"); zoom_logged = 1; } if (view_transformation_is_translation(ev)) { /* The simple case: The surface regions opaque, non-opaque, * etc. are convertible to global coordinate space. * There is no need to use a source clip region. * It is possible to paint opaque region as PIXMAN_OP_SRC. * Also the boundingbox is accurate rather than an * approximation. */ draw_view_translated(ev, output, &repaint); } else { /* The complex case: the view transformation does not allow * converting opaque etc. regions into global coordinate space. * Therefore we need source clipping to avoid sampling from * unwanted source image areas, unless the source image is * to be used whole. Source clipping does not work with * PIXMAN_OP_SRC. */ draw_view_source_clipped(ev, output, &repaint); } out: pixman_region32_fini(&repaint); }
static void wayland_shm_buffer_destroy(struct wayland_shm_buffer *buffer) { cairo_surface_destroy(buffer->c_surface); pixman_image_unref(buffer->pm_image); wl_buffer_destroy(buffer->buffer); munmap(buffer->data, buffer->size); pixman_region32_fini(&buffer->damage); wl_list_remove(&buffer->link); wl_list_remove(&buffer->free_link); free(buffer); }
nsRegion& nsRegion::Transform (const gfx3DMatrix &aTransform) { int n; pixman_box32_t *boxes = pixman_region32_rectangles(&mImpl, &n); for (int i=0; i<n; i++) { nsRect rect = BoxToRect(boxes[i]); boxes[i] = RectToBox(nsIntRegion::ToRect(TransformRect(nsIntRegion::FromRect(rect), aTransform))); } pixman_region32_t region; // This will union all of the rectangles and runs in about O(n lg(n)) pixman_region32_init_rects(®ion, boxes, n); pixman_region32_fini(&mImpl); mImpl = region; return *this; }
void nsRegion::Inflate(const nsMargin& aMargin) { int n; pixman_box32_t *boxes = pixman_region32_rectangles(&mImpl, &n); for (int i=0; i<n; i++) { nsRect rect = BoxToRect(boxes[i]); rect.Inflate(aMargin); boxes[i] = RectToBox(rect); } pixman_region32_t region; // This will union all of the rectangles and runs in about O(n lg(n)) pixman_region32_init_rects(®ion, boxes, n); pixman_region32_fini(&mImpl); mImpl = region; }
nsRegion& nsRegion::ScaleInverseRoundOut (float aXScale, float aYScale) { int n; pixman_box32_t *boxes = pixman_region32_rectangles(&mImpl, &n); for (int i=0; i<n; i++) { nsRect rect = BoxToRect(boxes[i]); rect.ScaleInverseRoundOut(aXScale, aYScale); boxes[i] = RectToBox(rect); } pixman_region32_t region; // This will union all of the rectangles and runs in about O(n lg(n)) pixman_region32_init_rects(®ion, boxes, n); pixman_region32_fini(&mImpl); mImpl = region; return *this; }
void UwacWindowDestroyBuffers(UwacWindow* w) { int i; for (i = 0; i < w->nbuffers; i++) { UwacBuffer* buffer = &w->buffers[i]; #ifdef HAVE_PIXMAN_REGION pixman_region32_fini(&buffer->damage); #else region16_uninit(&buffer->damage); #endif wl_buffer_destroy(buffer->wayland_buffer); } w->nbuffers = 0; free(w->buffers); w->buffers = NULL; }
/** * cairo_region_union_rectangle: * @dst: a #cairo_region_t * @rectangle: a #cairo_rectangle_int_t * * Computes the union of @dst with @rectangle and places the result in @dst. * * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY * * Since: 1.10 **/ cairo_status_t cairo_region_union_rectangle (cairo_region_t *dst, const cairo_rectangle_int_t *rectangle) { cairo_status_t status = CAIRO_STATUS_SUCCESS; pixman_region32_t region; if (dst->status) return dst->status; pixman_region32_init_rect (®ion, rectangle->x, rectangle->y, rectangle->width, rectangle->height); if (! pixman_region32_union (&dst->rgn, &dst->rgn, ®ion)) status = _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY); pixman_region32_fini (®ion); return status; }
nsRegion nsRegion::ConvertAppUnitsRoundIn (int32_t aFromAPP, int32_t aToAPP) const { if (aFromAPP == aToAPP) { return *this; } nsRegion region = *this; int n; pixman_box32_t *boxes = pixman_region32_rectangles(®ion.mImpl, &n); for (int i=0; i<n; i++) { nsRect rect = BoxToRect(boxes[i]); rect = rect.ConvertAppUnitsRoundIn(aFromAPP, aToAPP); boxes[i] = RectToBox(rect); } pixman_region32_t pixmanRegion; // This will union all of the rectangles and runs in about O(n lg(n)) pixman_region32_init_rects(&pixmanRegion, boxes, n); pixman_region32_fini(®ion.mImpl); region.mImpl = pixmanRegion; return region; }
nsIntRegion nsRegion::ToPixels (nscoord aAppUnitsPerPixel, bool aOutsidePixels) const { nsRegion region = *this; int n; pixman_box32_t *boxes = pixman_region32_rectangles(®ion.mImpl, &n); for (int i=0; i<n; i++) { nsRect rect = BoxToRect(boxes[i]); nsIntRect deviceRect; if (aOutsidePixels) deviceRect = rect.ToOutsidePixels(aAppUnitsPerPixel); else deviceRect = rect.ToNearestPixels(aAppUnitsPerPixel); boxes[i] = RectToBox(deviceRect); } nsIntRegion intRegion; pixman_region32_fini(&intRegion.mImpl.mImpl); // This will union all of the rectangles and runs in about O(n lg(n)) pixman_region32_init_rects(&intRegion.mImpl.mImpl, boxes, n); return intRegion; }
/** * cairo_region_xor: * @dst: a #cairo_region_t * @other: another #cairo_region_t * * Computes the exclusive difference of @dst with @other and places the * result in @dst. That is, @dst will be set to contain all areas that * are either in @dst or in @other, but not in both. * * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY * * Since: 1.10 **/ cairo_status_t cairo_region_xor (cairo_region_t *dst, const cairo_region_t *other) { cairo_status_t status = CAIRO_STATUS_SUCCESS; pixman_region32_t tmp; if (dst->status) return dst->status; if (other->status) return _cairo_region_set_error (dst, other->status); pixman_region32_init (&tmp); /* XXX: get an xor function into pixman */ if (! pixman_region32_subtract (&tmp, CONST_CAST &other->rgn, &dst->rgn) || ! pixman_region32_subtract (&dst->rgn, &dst->rgn, CONST_CAST &other->rgn) || ! pixman_region32_union (&dst->rgn, &dst->rgn, &tmp)) status = _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY); pixman_region32_fini (&tmp); return status; }
static void repaint_region(struct weston_view *ev, struct weston_output *output, pixman_region32_t *region, pixman_region32_t *surf_region, pixman_op_t pixman_op) { struct pixman_renderer *pr = (struct pixman_renderer *) output->compositor->renderer; struct pixman_surface_state *ps = get_surface_state(ev->surface); struct pixman_output_state *po = get_output_state(output); pixman_region32_t final_region; float view_x, view_y; pixman_transform_t transform; pixman_fixed_t fw, fh; /* The final region to be painted is the intersection of * 'region' and 'surf_region'. However, 'region' is in the global * coordinates, and 'surf_region' is in the surface-local * coordinates */ pixman_region32_init(&final_region); if (surf_region) { pixman_region32_copy(&final_region, surf_region); /* Convert from surface to global coordinates */ if (!ev->transform.enabled) { pixman_region32_translate(&final_region, ev->geometry.x, ev->geometry.y); } else { weston_view_to_global_float(ev, 0, 0, &view_x, &view_y); pixman_region32_translate(&final_region, (int)view_x, (int)view_y); } /* We need to paint the intersection */ pixman_region32_intersect(&final_region, &final_region, region); } else { /* If there is no surface region, just use the global region */ pixman_region32_copy(&final_region, region); } /* Convert from global to output coord */ region_global_to_output(output, &final_region); /* And clip to it */ pixman_image_set_clip_region32 (po->shadow_image, &final_region); /* Set up the source transformation based on the surface position, the output position/transform/scale and the client specified buffer transform/scale */ pixman_transform_init_identity(&transform); pixman_transform_scale(&transform, NULL, pixman_double_to_fixed ((double)1.0/output->current_scale), pixman_double_to_fixed ((double)1.0/output->current_scale)); fw = pixman_int_to_fixed(output->width); fh = pixman_int_to_fixed(output->height); switch (output->transform) { default: case WL_OUTPUT_TRANSFORM_NORMAL: case WL_OUTPUT_TRANSFORM_FLIPPED: break; case WL_OUTPUT_TRANSFORM_90: case WL_OUTPUT_TRANSFORM_FLIPPED_90: pixman_transform_rotate(&transform, NULL, 0, -pixman_fixed_1); pixman_transform_translate(&transform, NULL, 0, fh); break; case WL_OUTPUT_TRANSFORM_180: case WL_OUTPUT_TRANSFORM_FLIPPED_180: pixman_transform_rotate(&transform, NULL, -pixman_fixed_1, 0); pixman_transform_translate(&transform, NULL, fw, fh); break; case WL_OUTPUT_TRANSFORM_270: case WL_OUTPUT_TRANSFORM_FLIPPED_270: pixman_transform_rotate(&transform, NULL, 0, pixman_fixed_1); pixman_transform_translate(&transform, NULL, fw, 0); break; } switch (output->transform) { case WL_OUTPUT_TRANSFORM_FLIPPED: case WL_OUTPUT_TRANSFORM_FLIPPED_90: case WL_OUTPUT_TRANSFORM_FLIPPED_180: case WL_OUTPUT_TRANSFORM_FLIPPED_270: pixman_transform_scale(&transform, NULL, pixman_int_to_fixed (-1), pixman_int_to_fixed (1)); pixman_transform_translate(&transform, NULL, fw, 0); break; } pixman_transform_translate(&transform, NULL, pixman_double_to_fixed (output->x), pixman_double_to_fixed (output->y)); if (ev->transform.enabled) { /* Pixman supports only 2D transform matrix, but Weston uses 3D, * so we're omitting Z coordinate here */ pixman_transform_t surface_transform = {{ { D2F(ev->transform.matrix.d[0]), D2F(ev->transform.matrix.d[4]), D2F(ev->transform.matrix.d[12]), }, { D2F(ev->transform.matrix.d[1]), D2F(ev->transform.matrix.d[5]), D2F(ev->transform.matrix.d[13]), }, { D2F(ev->transform.matrix.d[3]), D2F(ev->transform.matrix.d[7]), D2F(ev->transform.matrix.d[15]), } }}; pixman_transform_invert(&surface_transform, &surface_transform); pixman_transform_multiply (&transform, &surface_transform, &transform); } else { pixman_transform_translate(&transform, NULL, pixman_double_to_fixed ((double)-ev->geometry.x), pixman_double_to_fixed ((double)-ev->geometry.y)); } if (ev->surface->buffer_viewport.scaler_set) { double scaler_x, scaler_y, scaler_width, scaler_height; double ratio_x, ratio_y; scaler_x = wl_fixed_to_double(ev->surface->buffer_viewport.src_x); scaler_y = wl_fixed_to_double(ev->surface->buffer_viewport.src_y); scaler_width = wl_fixed_to_double(ev->surface->buffer_viewport.src_width); scaler_height = wl_fixed_to_double(ev->surface->buffer_viewport.src_height); ratio_x = scaler_width / ev->surface->buffer_viewport.dst_width; ratio_y = scaler_height / ev->surface->buffer_viewport.dst_height; pixman_transform_scale(&transform, NULL, pixman_double_to_fixed(ratio_x), pixman_double_to_fixed(ratio_y)); pixman_transform_translate(&transform, NULL, pixman_double_to_fixed(scaler_x), pixman_double_to_fixed(scaler_y)); } pixman_transform_scale(&transform, NULL, pixman_double_to_fixed(ev->surface->buffer_viewport.scale), pixman_double_to_fixed(ev->surface->buffer_viewport.scale)); fw = pixman_int_to_fixed(pixman_image_get_width(ps->image)); fh = pixman_int_to_fixed(pixman_image_get_height(ps->image)); switch (ev->surface->buffer_viewport.transform) { case WL_OUTPUT_TRANSFORM_FLIPPED: case WL_OUTPUT_TRANSFORM_FLIPPED_90: case WL_OUTPUT_TRANSFORM_FLIPPED_180: case WL_OUTPUT_TRANSFORM_FLIPPED_270: pixman_transform_scale(&transform, NULL, pixman_int_to_fixed (-1), pixman_int_to_fixed (1)); pixman_transform_translate(&transform, NULL, fw, 0); break; } switch (ev->surface->buffer_viewport.transform) { default: case WL_OUTPUT_TRANSFORM_NORMAL: case WL_OUTPUT_TRANSFORM_FLIPPED: break; case WL_OUTPUT_TRANSFORM_90: case WL_OUTPUT_TRANSFORM_FLIPPED_90: pixman_transform_rotate(&transform, NULL, 0, pixman_fixed_1); pixman_transform_translate(&transform, NULL, fh, 0); break; case WL_OUTPUT_TRANSFORM_180: case WL_OUTPUT_TRANSFORM_FLIPPED_180: pixman_transform_rotate(&transform, NULL, -pixman_fixed_1, 0); pixman_transform_translate(&transform, NULL, fw, fh); break; case WL_OUTPUT_TRANSFORM_270: case WL_OUTPUT_TRANSFORM_FLIPPED_270: pixman_transform_rotate(&transform, NULL, 0, -pixman_fixed_1); pixman_transform_translate(&transform, NULL, 0, fw); break; } pixman_image_set_transform(ps->image, &transform); if (ev->transform.enabled || output->current_scale != ev->surface->buffer_viewport.scale) pixman_image_set_filter(ps->image, PIXMAN_FILTER_BILINEAR, NULL, 0); else pixman_image_set_filter(ps->image, PIXMAN_FILTER_NEAREST, NULL, 0); if (ps->buffer_ref.buffer) wl_shm_buffer_begin_access(ps->buffer_ref.buffer->shm_buffer); pixman_image_composite32(pixman_op, ps->image, /* src */ NULL /* mask */, po->shadow_image, /* dest */ 0, 0, /* src_x, src_y */ 0, 0, /* mask_x, mask_y */ 0, 0, /* dest_x, dest_y */ pixman_image_get_width (po->shadow_image), /* width */ pixman_image_get_height (po->shadow_image) /* height */); if (ps->buffer_ref.buffer) wl_shm_buffer_end_access(ps->buffer_ref.buffer->shm_buffer); if (pr->repaint_debug) pixman_image_composite32(PIXMAN_OP_OVER, pr->debug_color, /* src */ NULL /* mask */, po->shadow_image, /* dest */ 0, 0, /* src_x, src_y */ 0, 0, /* mask_x, mask_y */ 0, 0, /* dest_x, dest_y */ pixman_image_get_width (po->shadow_image), /* width */ pixman_image_get_height (po->shadow_image) /* height */); pixman_image_set_clip_region32 (po->shadow_image, NULL); pixman_region32_fini(&final_region); }
Region::~Region() { pixman_region32_fini(&m_region); }
static void empty_region(pixman_region32_t *region) { pixman_region32_fini(region); pixman_region32_init(region); }
pixman_bool_t pixman_compute_composite_region32 (pixman_region32_t * pRegion, pixman_image_t * pSrc, pixman_image_t * pMask, pixman_image_t * pDst, int16_t xSrc, int16_t ySrc, int16_t xMask, int16_t yMask, int16_t xDst, int16_t yDst, uint16_t width, uint16_t height) { int v; pRegion->extents.x1 = xDst; v = xDst + width; pRegion->extents.x2 = BOUND(v); pRegion->extents.y1 = yDst; v = yDst + height; pRegion->extents.y2 = BOUND(v); pRegion->data = 0; /* Check for empty operation */ if (pRegion->extents.x1 >= pRegion->extents.x2 || pRegion->extents.y1 >= pRegion->extents.y2) { pixman_region32_init (pRegion); return FALSE; } /* clip against dst */ if (!miClipPictureReg (pRegion, &pDst->common.clip_region, 0, 0)) { pixman_region32_fini (pRegion); return FALSE; } if (pDst->common.alpha_map) { if (!miClipPictureReg (pRegion, &pDst->common.alpha_map->common.clip_region, -pDst->common.alpha_origin.x, -pDst->common.alpha_origin.y)) { pixman_region32_fini (pRegion); return FALSE; } } /* clip against src */ if (!miClipPictureSrc (pRegion, pSrc, xDst - xSrc, yDst - ySrc)) { pixman_region32_fini (pRegion); return FALSE; } if (pSrc->common.alpha_map) { if (!miClipPictureSrc (pRegion, (pixman_image_t *)pSrc->common.alpha_map, xDst - (xSrc + pSrc->common.alpha_origin.x), yDst - (ySrc + pSrc->common.alpha_origin.y))) { pixman_region32_fini (pRegion); return FALSE; } } /* clip against mask */ if (pMask) { if (!miClipPictureSrc (pRegion, pMask, xDst - xMask, yDst - yMask)) { pixman_region32_fini (pRegion); return FALSE; } if (pMask->common.alpha_map) { if (!miClipPictureSrc (pRegion, (pixman_image_t *)pMask->common.alpha_map, xDst - (xMask + pMask->common.alpha_origin.x), yDst - (yMask + pMask->common.alpha_origin.y))) { pixman_region32_fini (pRegion); return FALSE; } } } return TRUE; }
nsIntRegion nsRegion::ScaleToInsidePixels (float aScaleX, float aScaleY, nscoord aAppUnitsPerPixel) const { /* When scaling a rect, walk forward through the rect list up until the y value is greater * than the current rect's YMost() value. * * For each rect found, check if the rects have a touching edge (in unscaled coordinates), * and if one edge is entirely contained within the other. * * If it is, then the contained edge can be moved (in scaled pixels) to ensure that no * gap exists. * * Since this could be potentially expensive - O(n^2), we only attempt this algorithm * for the first rect. */ // make a copy of this region so that we can mutate it in place nsRegion region = *this; int n; pixman_box32_t *boxes = pixman_region32_rectangles(®ion.mImpl, &n); nsIntRegion intRegion; if (n) { nsRect first = BoxToRect(boxes[0]); nsIntRect firstDeviceRect = first.ScaleToInsidePixels(aScaleX, aScaleY, aAppUnitsPerPixel); for (int i=1; i<n; i++) { nsRect rect = nsRect(boxes[i].x1, boxes[i].y1, boxes[i].x2 - boxes[i].x1, boxes[i].y2 - boxes[i].y1); nsIntRect deviceRect = rect.ScaleToInsidePixels(aScaleX, aScaleY, aAppUnitsPerPixel); if (rect.y <= first.YMost()) { if (rect.XMost() == first.x && rect.YMost() <= first.YMost()) { // rect is touching on the left edge of the first rect and contained within // the length of its left edge deviceRect.SetRightEdge(firstDeviceRect.x); } else if (rect.x == first.XMost() && rect.YMost() <= first.YMost()) { // rect is touching on the right edge of the first rect and contained within // the length of its right edge deviceRect.SetLeftEdge(firstDeviceRect.XMost()); } else if (rect.y == first.YMost()) { // The bottom of the first rect is on the same line as the top of rect, but // they aren't necessarily contained. if (rect.x <= first.x && rect.XMost() >= first.XMost()) { // The top of rect contains the bottom of the first rect firstDeviceRect.SetBottomEdge(deviceRect.y); } else if (rect.x >= first.x && rect.XMost() <= first.XMost()) { // The bottom of the first contains the top of rect deviceRect.SetTopEdge(firstDeviceRect.YMost()); } } } boxes[i] = RectToBox(deviceRect); } boxes[0] = RectToBox(firstDeviceRect); pixman_region32_fini(&intRegion.mImpl.mImpl); // This will union all of the rectangles and runs in about O(n lg(n)) pixman_region32_init_rects(&intRegion.mImpl.mImpl, boxes, n); } return intRegion; }
int main () { pixman_region32_t r1; pixman_region32_t r2; pixman_region32_t r3; pixman_box32_t boxes[] = { { 10, 10, 20, 20 }, { 30, 30, 30, 40 }, { 50, 45, 60, 44 }, }; pixman_box32_t boxes2[] = { { 2, 6, 7, 6 }, { 4, 1, 6, 7 }, }; pixman_box32_t boxes3[] = { { 2, 6, 7, 6 }, { 4, 1, 6, 1 }, }; int i, j; pixman_box32_t *b; pixman_image_t *image, *fill; pixman_color_t white = { 0xffff, 0xffff, 0xffff, 0xffff }; /* This used to go into an infinite loop before pixman-region.c * was fixed to not use explict "short" variables */ pixman_region32_init_rect (&r1, 0, 0, 20, 64000); pixman_region32_init_rect (&r2, 0, 0, 20, 64000); pixman_region32_init_rect (&r3, 0, 0, 20, 64000); pixman_region32_subtract (&r1, &r2, &r3); /* This would produce a region containing an empty * rectangle in it. Such regions are considered malformed, * but using an empty rectangle for initialization should * work. */ pixman_region32_init_rects (&r1, boxes, 3); b = pixman_region32_rectangles (&r1, &i); assert (i == 1); while (i--) { assert (b[i].x1 < b[i].x2); assert (b[i].y1 < b[i].y2); } /* This would produce a rectangle containing the bounding box * of the two rectangles. The correct result is to eliminate * the broken rectangle. */ pixman_region32_init_rects (&r1, boxes2, 2); b = pixman_region32_rectangles (&r1, &i); assert (i == 1); assert (b[0].x1 == 4); assert (b[0].y1 == 1); assert (b[0].x2 == 6); assert (b[0].y2 == 7); /* This should produce an empty region */ pixman_region32_init_rects (&r1, boxes3, 2); b = pixman_region32_rectangles (&r1, &i); assert (i == 0); fill = pixman_image_create_solid_fill (&white); for (i = 0; i < 100; i++) { int image_size = 128; pixman_region32_init (&r1); /* Add some random rectangles */ for (j = 0; j < 64; j++) pixman_region32_union_rect (&r1, &r1, lcg_rand_n (image_size), lcg_rand_n (image_size), lcg_rand_n (25), lcg_rand_n (25)); /* Clip to image size */ pixman_region32_init_rect (&r2, 0, 0, image_size, image_size); pixman_region32_intersect (&r1, &r1, &r2); pixman_region32_fini (&r2); /* render region to a1 mask */ image = pixman_image_create_bits (PIXMAN_a1, image_size, image_size, NULL, 0); pixman_image_set_clip_region32 (image, &r1); pixman_image_composite32 (PIXMAN_OP_SRC, fill, NULL, image, 0, 0, 0, 0, 0, 0, image_size, image_size); pixman_region32_init_from_image (&r2, image); pixman_image_unref (image); assert (pixman_region32_equal (&r1, &r2)); pixman_region32_fini (&r1); pixman_region32_fini (&r2); } pixman_image_unref (fill); return 0; }
void _cairo_region_fini (cairo_region_t *region) { pixman_region32_fini (®ion->rgn); }