static void _cairo_qt_surface_set_clip_region (cairo_qt_surface_t *qs, const cairo_region_t *clip_region) { _cairo_surface_clipper_reset (&qs->clipper); if (clip_region == NULL) { // How the clip path is reset depends on whether we own p or not if (qs->pixmap || qs->image) { // we own p qs->p->setClipping (false); } else { qs->p->restore (); qs->p->save (); } } else { QRegion qr; int num_rects = cairo_region_num_rectangles (clip_region); for (int i = 0; i < num_rects; ++i) { cairo_rectangle_int_t rect; cairo_region_get_rectangle (clip_region, i, &rect); QRect r(rect.x, rect.y, rect.width, rect.height); qr = qr.unite(r); } qs->p->setClipRegion (qr, Qt::IntersectClip); } }
void _clutter_stage_wayland_repaint_region (ClutterStageWayland *stage_wayland, ClutterStage *stage) { ClutterGeometry geom; cairo_rectangle_int_t rect; int i, count; count = cairo_region_num_rectangles (stage_wayland->repaint_region); for (i = 0; i < count; i++) { cairo_region_get_rectangle (stage_wayland->repaint_region, i, &rect); cogl_clip_push_window_rectangle (rect.x - 1, rect.y - 1, rect.width + 2, rect.height + 2); geom.x = rect.x; geom.y = rect.y; geom.width = rect.width; geom.height = rect.height; /* FIXME: We should pass geom in as second arg, but some actors * cull themselves a little to much. Disable for now.*/ _clutter_stage_do_paint (stage, NULL); cogl_clip_pop (); } }
void gimp_display_shell_expose_region (GimpDisplayShell *shell, cairo_region_t *region) { GdkRegion *gdk_region; gint n_rectangles; gint i; g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); g_return_if_fail (region != NULL); if (! gtk_widget_get_realized (shell->canvas)) return; gdk_region = gdk_region_new (); n_rectangles = cairo_region_num_rectangles (region); for (i = 0; i < n_rectangles; i++) { cairo_rectangle_int_t rectangle; cairo_region_get_rectangle (region, i, &rectangle); gdk_region_union_with_rect (gdk_region, (GdkRectangle *) &rectangle); } gdk_window_invalidate_region (gtk_widget_get_window (shell->canvas), gdk_region, TRUE); gdk_region_destroy (gdk_region); }
// cairo_public int // cairo_region_num_rectangles (const cairo_region_t *region); static int l_cairo_region_num_rectangles (lua_State* L) { const cairo_region_t *region = get_cairo_region_t (L, 1); int v = cairo_region_num_rectangles (region); lua_pushinteger(L, v); return 1; }
cairo_region_t * meta_region_scale_double (cairo_region_t *region, double scale, MetaRoundingStrategy rounding_strategy) { int n_rects, i; cairo_rectangle_int_t *rects; cairo_region_t *scaled_region; g_return_val_if_fail (scale > 0.0, NULL); if (scale == 1.0) return cairo_region_copy (region); n_rects = cairo_region_num_rectangles (region); rects = g_malloc (sizeof(cairo_rectangle_int_t) * n_rects); for (i = 0; i < n_rects; i++) { cairo_region_get_rectangle (region, i, &rects[i]); meta_rectangle_scale_double (&rects[i], scale, rounding_strategy, &rects[i]); } scaled_region = cairo_region_create_rectangles (rects, n_rects); g_free (rects); return scaled_region; }
void meta_surface_actor_set_frozen (MetaSurfaceActor *self, gboolean frozen) { MetaSurfaceActorPrivate *priv = self->priv; priv->frozen = frozen; if (!frozen && priv->pending_damage) { int i, n_rects = cairo_region_num_rectangles (priv->pending_damage); cairo_rectangle_int_t rect; /* Since we ignore damage events while a window is frozen for certain effects * we need to apply the tracked damage now. */ for (i = 0; i < n_rects; i++) { cairo_region_get_rectangle (priv->pending_damage, i, &rect); meta_surface_actor_process_damage (self, rect.x, rect.y, rect.width, rect.height); } g_clear_pointer (&priv->pending_damage, cairo_region_destroy); } }
static void _cairo_gl_flush_glyphs (cairo_gl_context_t *ctx, cairo_gl_glyphs_setup_t *setup) { int i; if (setup->vb != NULL) { glUnmapBufferARB (GL_ARRAY_BUFFER_ARB); setup->vb = NULL; if (setup->num_prims != 0) { if (setup->clip) { int num_rectangles = cairo_region_num_rectangles (setup->clip); glEnable (GL_SCISSOR_TEST); for (i = 0; i < num_rectangles; i++) { cairo_rectangle_int_t rect; cairo_region_get_rectangle (setup->clip, i, &rect); glScissor (rect.x, _cairo_gl_y_flip (setup->dst, rect.y), rect.x + rect.width, _cairo_gl_y_flip (setup->dst, rect.y + rect.height)); glDrawArrays (GL_QUADS, 0, 4 * setup->num_prims); } glDisable (GL_SCISSOR_TEST); } else { glDrawArrays (GL_QUADS, 0, 4 * setup->num_prims); } setup->num_prims = 0; } } }
void _cairo_gl_composite_flush (cairo_gl_context_t *ctx) { unsigned int count; int i; if (_cairo_gl_context_is_flushed (ctx)) return; count = ctx->vb_offset / ctx->vertex_size; _cairo_gl_composite_unmap_vertex_buffer (ctx); if ( _cairo_array_num_elements (&ctx->tristrip_indices) > 0) { _cairo_gl_composite_draw_tristrip (ctx); } else if (ctx->clip_region) { int i, num_rectangles = cairo_region_num_rectangles (ctx->clip_region); for (i = 0; i < num_rectangles; i++) { cairo_rectangle_int_t rect; cairo_region_get_rectangle (ctx->clip_region, i, &rect); glScissor (rect.x, rect.y, rect.width, rect.height); _cairo_gl_composite_draw (ctx, count); } } else { _cairo_gl_composite_draw (ctx, count); } for (i = 0; i < ARRAY_LENGTH (&ctx->glyph_cache); i++) _cairo_gl_glyph_cache_unlock (&ctx->glyph_cache[i]); }
void _gdk_x11_region_get_xrectangles (const cairo_region_t *region, gint x_offset, gint y_offset, gint scale, XRectangle **rects, gint *n_rects) { XRectangle *rectangles; cairo_rectangle_int_t box; gint i, n; n = cairo_region_num_rectangles (region); rectangles = g_new (XRectangle, n); for (i = 0; i < n; i++) { cairo_region_get_rectangle (region, i, &box); rectangles[i].x = CLAMP ((box.x + x_offset) * scale, G_MINSHORT, G_MAXSHORT); rectangles[i].y = CLAMP ((box.y + y_offset) * scale, G_MINSHORT, G_MAXSHORT); rectangles[i].width = CLAMP (box.width * scale, G_MINSHORT, G_MAXSHORT); rectangles[i].height = CLAMP (box.height * scale, G_MINSHORT, G_MAXSHORT); } *n_rects = n; *rects = rectangles; }
static void blank_region_in_pixbuf (GdkPixbuf *pixbuf, cairo_region_t *region) { int n_rects; int i; int width, height; cairo_rectangle_int_t pixbuf_rect; n_rects = cairo_region_num_rectangles (region); width = gdk_pixbuf_get_width (pixbuf); height = gdk_pixbuf_get_height (pixbuf); pixbuf_rect.x = 0; pixbuf_rect.y = 0; pixbuf_rect.width = width; pixbuf_rect.height = height; for (i = 0; i < n_rects; i++) { cairo_rectangle_int_t rect, dest; cairo_region_get_rectangle (region, i, &rect); if (gdk_rectangle_intersect (&rect, &pixbuf_rect, &dest)) blank_rectangle_in_pixbuf (pixbuf, &dest); } }
static int _extract_dirty_event(void) { int i, n; mume_event_t event; mume_rect_t rect; const cairo_region_t *rgn; if (!mume_urgnmgr_pop_urgn(_mume_gstate->urgnmgr)) return 0; rgn = mume_urgnmgr_last_rgn(_mume_gstate->urgnmgr); n = cairo_region_num_rectangles(rgn); event.expose.type = MUME_EVENT_EXPOSE; event.expose.window = (void*)mume_urgnmgr_last_win( _mume_gstate->urgnmgr); for (i = 0; i < n; ++i) { cairo_region_get_rectangle(rgn, i, &rect); event.expose.x = rect.x; event.expose.y = rect.y; event.expose.width = rect.width; event.expose.height = rect.height; event.expose.count = n - i - 1; memcpy(mume_list_data(mume_list_push_back( _mume_gstate->event_list, sizeof(mume_event_t))), &event, sizeof(mume_event_t)); } return 1; }
static cairo_region_t * expand_region (cairo_region_t *region, int x_amount, int y_amount, gboolean flip) { MetaRegionBuilder builder; int n; int i; meta_region_builder_init (&builder); n = cairo_region_num_rectangles (region); for (i = 0; i < n; i++) { cairo_rectangle_int_t rect; cairo_region_get_rectangle (region, i, &rect); add_expanded_rect (&builder, rect.x, rect.y, rect.width, rect.height, x_amount, y_amount, flip); } return meta_region_builder_finish (&builder); }
static gboolean get_selection_bounds (EvView *view, EvViewSelection *selection, gint *start_offset, gint *end_offset) { cairo_rectangle_int_t rect; gint start, end; if (!selection->covered_region || cairo_region_is_empty (selection->covered_region)) return FALSE; cairo_region_get_rectangle (selection->covered_region, 0, &rect); start = _ev_view_get_caret_cursor_offset_at_doc_point (view, selection->page, rect.x / view->scale, (rect.y + (rect.height / 2)) / view->scale); if (start == -1) return FALSE; cairo_region_get_rectangle (selection->covered_region, cairo_region_num_rectangles (selection->covered_region) - 1, &rect); end = _ev_view_get_caret_cursor_offset_at_doc_point (view, selection->page, (rect.x + rect.width) / view->scale, (rect.y + (rect.height / 2)) / view->scale); if (end == -1) return FALSE; *start_offset = start; *end_offset = end; return TRUE; }
static cairo_surface_t * ensure_image_surface (cairo_surface_t *surface, const cairo_region_t *region) { cairo_rectangle_int_t extents; cairo_surface_t *image; cairo_t *cr; int i, num_rects; if (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_IMAGE) return surface; cairo_region_get_extents (region, &extents); image = cairo_image_surface_create (CAIRO_FORMAT_RGB24, extents.width, extents.height); cairo_surface_set_device_offset (image, -extents.x, -extents.y); cr = cairo_create (image); cairo_set_source_surface (cr, surface, 0, 0); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); num_rects = cairo_region_num_rectangles (region); for (i = 0; i < num_rects; i++) { cairo_rectangle_int_t rect; cairo_region_get_rectangle (region, i, &rect); cairo_rectangle (cr, rect.x, rect.y, rect.width, rect.height); } cairo_fill (cr); cairo_destroy (cr); cairo_surface_destroy (surface); return image; }
cairo_region_t * meta_region_transform (cairo_region_t *region, MetaMonitorTransform transform, int width, int height) { int n_rects, i; cairo_rectangle_int_t *rects; cairo_region_t *transformed_region; if (transform == META_MONITOR_TRANSFORM_NORMAL) return cairo_region_copy (region); n_rects = cairo_region_num_rectangles (region); rects = g_new0 (cairo_rectangle_int_t, n_rects); for (i = 0; i < n_rects; i++) { cairo_region_get_rectangle (region, i, &rects[i]); meta_rectangle_transform (&rects[i], transform, width, height, &rects[i]); } transformed_region = cairo_region_create_rectangles (rects, n_rects); g_free (rects); return transformed_region; }
cairo_region_t * meta_region_scale (cairo_region_t *region, int scale) { int n_rects, i; cairo_rectangle_int_t *rects; cairo_region_t *scaled_region; if (scale == 1) return cairo_region_copy (region); n_rects = cairo_region_num_rectangles (region); rects = g_malloc (sizeof(cairo_rectangle_int_t) * n_rects); for (i = 0; i < n_rects; i++) { cairo_region_get_rectangle (region, i, &rects[i]); rects[i].x *= scale; rects[i].y *= scale; rects[i].width *= scale; rects[i].height *= scale; } scaled_region = cairo_region_create_rectangles (rects, n_rects); g_free (rects); return scaled_region; }
static void mech_surface_wayland_shm_push_update (MechSurface *surface, const cairo_region_t *region) { MechSurfaceWaylandSHM *shm_surface = (MechSurfaceWaylandSHM *) surface; MechSurfaceWaylandSHMPriv *priv = shm_surface->_priv; struct wl_surface *wl_surface; cairo_rectangle_int_t rect; BufferData *buffer; gint i; g_object_get (surface, "wl-surface", &wl_surface, NULL); buffer = priv->buffers[priv->cur_buffer]; if (wl_surface) { for (i = 0; i < cairo_region_num_rectangles (region); i++) { cairo_region_get_rectangle (region, i, &rect); wl_surface_damage (wl_surface, rect.x, rect.y, rect.width, rect.height); } wl_surface_attach (wl_surface, buffer->wl_buffer, priv->tx, priv->ty); priv->tx = priv->ty = 0; /* The current buffer is now acquired by the compositor */ buffer->released = FALSE; } MECH_SURFACE_CLASS (mech_surface_wayland_shm_parent_class)->push_update (surface, region); }
static void meta_surface_actor_pick (ClutterActor *actor, const ClutterColor *color) { MetaSurfaceActor *self = META_SURFACE_ACTOR (actor); MetaSurfaceActorPrivate *priv = meta_surface_actor_get_instance_private (self); ClutterActorIter iter; ClutterActor *child; if (!clutter_actor_should_pick_paint (actor)) return; /* If there is no region then use the regular pick */ if (priv->input_region == NULL) CLUTTER_ACTOR_CLASS (meta_surface_actor_parent_class)->pick (actor, color); else { int n_rects; float *rectangles; int i; CoglPipeline *pipeline; CoglContext *ctx; CoglFramebuffer *fb; CoglColor cogl_color; n_rects = cairo_region_num_rectangles (priv->input_region); rectangles = g_alloca (sizeof (float) * 4 * n_rects); for (i = 0; i < n_rects; i++) { cairo_rectangle_int_t rect; int pos = i * 4; cairo_region_get_rectangle (priv->input_region, i, &rect); rectangles[pos + 0] = rect.x; rectangles[pos + 1] = rect.y; rectangles[pos + 2] = rect.x + rect.width; rectangles[pos + 3] = rect.y + rect.height; } ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ()); fb = cogl_get_draw_framebuffer (); cogl_color_init_from_4ub (&cogl_color, color->red, color->green, color->blue, color->alpha); pipeline = cogl_pipeline_new (ctx); cogl_pipeline_set_color (pipeline, &cogl_color); cogl_framebuffer_draw_rectangles (fb, pipeline, rectangles, n_rects); cogl_object_unref (pipeline); } clutter_actor_iter_init (&iter, actor); while (clutter_actor_iter_next (&iter, &child)) clutter_actor_paint (child); }
void mume_cairo_region_to_path(cairo_t *cr, const cairo_region_t *rgn) { mume_rect_t r; int i = cairo_region_num_rectangles(rgn); while (i-- > 0) { cairo_region_get_rectangle(rgn, i, &r); cairo_rectangle(cr, r.x, r.y, r.width, r.height); } }
gboolean byzanz_serialize (GOutputStream * stream, guint64 msecs, cairo_surface_t * surface, const cairo_region_t * region, GCancellable * cancellable, GError ** error) { guint i, stride; cairo_rectangle_int_t rect, extents; guchar *data; guint32 n; int y, n_rects; g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream), FALSE); g_return_val_if_fail ((surface == NULL) == (region == NULL), FALSE); g_return_val_if_fail (region == NULL || !cairo_region_is_empty (region), FALSE); if (!g_output_stream_write_all (stream, &msecs, sizeof (guint64), NULL, cancellable, error)) return FALSE; if (surface == 0) { n = 0; return g_output_stream_write_all (stream, &n, sizeof (guint32), NULL, cancellable, error); } n = n_rects = cairo_region_num_rectangles (region); if (!g_output_stream_write_all (stream, &n, sizeof (guint32), NULL, cancellable, error)) return FALSE; for (i = 0; i < n; i++) { gint32 ints[4]; cairo_region_get_rectangle (region, i, &rect); ints[0] = rect.x, ints[1] = rect.y, ints[2] = rect.width, ints[3] = rect.height; g_assert (sizeof (ints) == 16); if (!g_output_stream_write_all (stream, ints, sizeof (ints), NULL, cancellable, error)) return FALSE; } stride = cairo_image_surface_get_stride (surface); cairo_region_get_extents (region, &extents); for (i = 0; i < n; i++) { cairo_region_get_rectangle (region, i, &rect); data = cairo_image_surface_get_data (surface) + stride * (rect.y - extents.y) + sizeof (guint32) * (rect.x - extents.x); for (y = 0; y < rect.height; y++) { if (!g_output_stream_write_all (G_OUTPUT_STREAM (stream), data, rect.width * sizeof (guint32), NULL, cancellable, error)) return FALSE; data += stride; } } return TRUE; }
void mume_dump_region(const cairo_region_t *rgn) { int i, num; mume_rect_t rect; num = cairo_region_num_rectangles(rgn); for (i = 0; i < num; ++i) { cairo_region_get_rectangle(rgn, i, &rect); mume_debug(("%d, %d, %d, %d\n", rect.x, rect.y, rect.width, rect.height)); } }
static cairo_surface_t * byzanz_recorder_create_snapshot (ByzanzRecorder *recorder, const cairo_region_t *invalid) { cairo_rectangle_int_t extents; cairo_surface_t *surface; cairo_t *cr; GSequenceIter *iter; int i, num_rects; cairo_region_get_extents (invalid, &extents); cr = gdk_cairo_create (recorder->window); surface = cairo_surface_create_similar (cairo_get_target (cr), CAIRO_CONTENT_COLOR, extents.width, extents.height); cairo_destroy (cr); cairo_surface_set_device_offset (surface, -extents.x, -extents.y); cr = cairo_create (surface); num_rects = cairo_region_num_rectangles (invalid); for (i = 0; i < num_rects; i++) { cairo_rectangle_int_t rect; cairo_region_get_rectangle (invalid, i, &rect); cairo_rectangle (cr, rect.x, rect.y, rect.width, rect.height); } cairo_clip (cr); for (iter = g_sequence_get_begin_iter (recorder->layers); !g_sequence_iter_is_end (iter); iter = g_sequence_iter_next (iter)) { ByzanzLayer *layer = g_sequence_get (iter); ByzanzLayerClass *klass = BYZANZ_LAYER_GET_CLASS (layer); cairo_save (cr); klass->render (layer, cr); if (cairo_status (cr)) g_critical ("error capturing image: %s", cairo_status_to_string (cairo_status (cr))); cairo_restore (cr); } cairo_destroy (cr); surface = ensure_image_surface (surface, invalid); /* adjust device offset here - the layers work in GdkScreen coordinates, the rest * of the code works in coordinates realtive to the passed in area. */ cairo_surface_set_device_offset (surface, recorder->area.x - extents.x, recorder->area.y - extents.y); return surface; }
mume_rect_t mume_cairo_region_extents(const cairo_region_t *rgn) { mume_rect_t r0, r1; int i = cairo_region_num_rectangles(rgn); r0 = mume_rect_empty; while (i-- > 0) { cairo_region_get_rectangle(rgn, i, &r1); r0 = mume_rect_union(r0, r1); } return r0; }
static void blur_rows (cairo_region_t *convolve_region, int x_offset, int y_offset, guchar *buffer, int buffer_width, int buffer_height, int d) { int i, j; int n_rectangles; guchar *tmp_buffer; tmp_buffer = g_malloc (buffer_width); n_rectangles = cairo_region_num_rectangles (convolve_region); for (i = 0; i < n_rectangles; i++) { cairo_rectangle_int_t rect; cairo_region_get_rectangle (convolve_region, i, &rect); for (j = y_offset + rect.y; j < y_offset + rect.y + rect.height; j++) { guchar *row = buffer + j * buffer_width; int x0 = x_offset + rect.x; int x1 = x0 + rect.width; /* We want to produce a symmetric blur that spreads a pixel * equally far to the left and right. If d is odd that happens * naturally, but for d even, we approximate by using a blur * on either side and then a centered blur of size d + 1. * (techique also from the SVG specification) */ if (d % 2 == 1) { blur_xspan (row, tmp_buffer, buffer_width, x0, x1, d, 0); blur_xspan (row, tmp_buffer, buffer_width, x0, x1, d, 0); blur_xspan (row, tmp_buffer, buffer_width, x0, x1, d, 0); } else { blur_xspan (row, tmp_buffer, buffer_width, x0, x1, d, 1); blur_xspan (row, tmp_buffer, buffer_width, x0, x1, d, -1); blur_xspan (row, tmp_buffer, buffer_width, x0, x1, d + 1, 0); } } } g_free (tmp_buffer); }
JOY_GNUC_HOT static void submit(JoyScreen *self) { struct Private *priv = GET_PRIVATE(self); // update cursor if (priv->cursor && priv->moved) { GFX3D_Cursor_Position_Set(priv->cursor, priv->x - priv->x_hot, priv->y - priv->y_hot); } // clear exposed areas of the frame buffer cairo_region_intersect(priv->expose, priv->area); for (gint i = 0; i < cairo_region_num_rectangles(priv->expose); ++i) { cairo_rectangle_int_t rect; cairo_region_get_rectangle(priv->expose, i, &rect); GFX3D_Display_ClearAlpha2D(priv->display, NULL, (gpointer)&rect, 0., 0., 0., 0.); g_array_append_val(priv->rects, rect); } if (priv->rects->len) { cairo_region_subtract(priv->expose, priv->expose); #if !CAIRO_HAS_GFX3D_SURFACE GFX3D_Display_Cache_Flush(priv->display); #endif // !CAIRO_HAS_GFX3D_SURFACE GFX3D_NATIVE_Display display = GFX3D_Display_Get_NATIVE_Display(priv->display); GFX3D_NATIVE_Surface surface = GFX3D_Display_FrameBuffer_Get_NATIVE_Surface( priv->display); // copy windows to the frame buffer for (GList *node = g_queue_peek_head_link(priv->windows); node; node = node->next) { JoyBubble *window = node->data; joy_gfx3d_window_submit(window, display, surface, priv->area); } // flip the display GFX3D_Display_Show_Partial(priv->display, (gpointer)priv->rects->data, priv->rects->len, 1); g_array_set_size(priv->rects, 0); } else { if (priv->moved && priv->cursor) { GFX3D_Display_Show_Ch_Reload(priv->cursor); } } priv->moved = FALSE; }
void wxRegionIterator::CreateRects( const wxRegion& region ) { wxDELETEA(m_rects); m_numRects = 0; #ifdef __WXGTK3__ cairo_region_t* cairoRegion = region.GetRegion(); if (cairoRegion == NULL) return; m_numRects = cairo_region_num_rectangles(cairoRegion); if (m_numRects) { m_rects = new wxRect[m_numRects]; for (int i = 0; i < m_numRects; i++) { GdkRectangle gr; cairo_region_get_rectangle(cairoRegion, i, &gr); wxRect &wr = m_rects[i]; wr.x = gr.x; wr.y = gr.y; wr.width = gr.width; wr.height = gr.height; } } #else GdkRegion *gdkregion = region.GetRegion(); if (!gdkregion) return; GdkRectangle* gdkrects; gdk_region_get_rectangles(gdkregion, &gdkrects, &m_numRects); if (m_numRects) { m_rects = new wxRect[m_numRects]; for (int i = 0; i < m_numRects; ++i) { GdkRectangle &gr = gdkrects[i]; wxRect &wr = m_rects[i]; wr.x = gr.x; wr.y = gr.y; wr.width = gr.width; wr.height = gr.height; } } g_free( gdkrects ); #endif }
static void meta_background_actor_paint (ClutterActor *actor) { MetaBackgroundActor *self = META_BACKGROUND_ACTOR (actor); MetaBackgroundActorPrivate *priv = self->priv; guint8 opacity = clutter_actor_get_paint_opacity (actor); guint8 color_component; int width, height; meta_screen_get_size (priv->background->screen, &width, &height); color_component = (int)(0.5 + opacity * priv->dim_factor); cogl_material_set_color4ub (priv->material, color_component, color_component, color_component, opacity); cogl_set_source (priv->material); if (priv->visible_region) { int n_rectangles = cairo_region_num_rectangles (priv->visible_region); int i; for (i = 0; i < n_rectangles; i++) { cairo_rectangle_int_t rect; cairo_region_get_rectangle (priv->visible_region, i, &rect); cogl_rectangle_with_texture_coords (rect.x, rect.y, rect.x + rect.width, rect.y + rect.height, rect.x / priv->background->texture_width, rect.y / priv->background->texture_height, (rect.x + rect.width) / priv->background->texture_width, (rect.y + rect.height) / priv->background->texture_height); } } else { cogl_rectangle_with_texture_coords (0.0f, 0.0f, width, height, 0.0f, 0.0f, width / priv->background->texture_width, height / priv->background->texture_height); } }
cairo_region_t * meta_region_crop_and_scale (cairo_region_t *region, ClutterRect *src_rect, int dst_width, int dst_height) { int n_rects, i; cairo_rectangle_int_t *rects; cairo_region_t *viewport_region; if (src_rect->size.width == dst_width && src_rect->size.height == dst_height && roundf (src_rect->origin.x) == src_rect->origin.x && roundf (src_rect->origin.y) == src_rect->origin.y) { viewport_region = cairo_region_copy (region); if (src_rect->origin.x != 0 || src_rect->origin.y != 0) { cairo_region_translate (viewport_region, (int) src_rect->origin.x, (int) src_rect->origin.y); } return viewport_region; } n_rects = cairo_region_num_rectangles (region); rects = g_new0 (cairo_rectangle_int_t, n_rects); for (i = 0; i < n_rects; i++) { cairo_region_get_rectangle (region, i, &rects[i]); meta_rectangle_crop_and_scale (&rects[i], src_rect, dst_width, dst_height, &rects[i]); } viewport_region = cairo_region_create_rectangles (rects, n_rects); g_free (rects); return viewport_region; }
static JSBool num_rectangles_func(JSContext *context, unsigned argc, jsval *vp) { PRELUDE; int n_rects; jsval retval; if (!gjs_parse_call_args(context, "num_rectangles", "", argv)) return JS_FALSE; n_rects = cairo_region_num_rectangles(this_region); retval = INT_TO_JSVAL(n_rects); argv.rval().set(retval); RETURN_STATUS; }
static gboolean process_shm_buffer_damage (MetaWaylandBuffer *buffer, CoglTexture *texture, cairo_region_t *region, GError **error) { struct wl_shm_buffer *shm_buffer; int i, n_rectangles; gboolean set_texture_failed = FALSE; n_rectangles = cairo_region_num_rectangles (region); shm_buffer = wl_shm_buffer_get (buffer->resource); wl_shm_buffer_begin_access (shm_buffer); for (i = 0; i < n_rectangles; i++) { const uint8_t *data = wl_shm_buffer_get_data (shm_buffer); int32_t stride = wl_shm_buffer_get_stride (shm_buffer); CoglPixelFormat format; int bpp; cairo_rectangle_int_t rect; shm_buffer_get_cogl_pixel_format (shm_buffer, &format, NULL); bpp = _cogl_pixel_format_get_bytes_per_pixel (format); cairo_region_get_rectangle (region, i, &rect); if (!_cogl_texture_set_region (texture, rect.width, rect.height, format, stride, data + rect.x * bpp + rect.y * stride, rect.x, rect.y, 0, error)) { set_texture_failed = TRUE; break; } } wl_shm_buffer_end_access (shm_buffer); return !set_texture_failed; }