/** * meta_background_actor_set_visible_region: * @self: a #MetaBackgroundActor * @visible_region: (allow-none): the area of the actor (in allocate-relative * coordinates) that is visible. * * Sets the area of the background that is unobscured by overlapping windows. * This is used to optimize and only paint the visible portions. */ void meta_background_actor_set_visible_region (MetaBackgroundActor *self, cairo_region_t *visible_region) { MetaBackgroundActorPrivate *priv; g_return_if_fail (META_IS_BACKGROUND_ACTOR (self)); priv = self->priv; if (priv->visible_region) { cairo_region_destroy (priv->visible_region); priv->visible_region = NULL; } if (visible_region) { cairo_rectangle_int_t screen_rect = { 0 }; meta_screen_get_size (priv->background->screen, &screen_rect.width, &screen_rect.height); /* Doing the intersection here is probably unnecessary - MetaWindowGroup * should never compute a visible area that's larger than the root screen! * but it's not that expensive and adds some extra robustness. */ priv->visible_region = cairo_region_create_rectangle (&screen_rect); cairo_region_intersect (priv->visible_region, visible_region); } }
static cairo_region_t * byzanz_layer_cursor_snapshot (ByzanzLayer *layer) { ByzanzLayerCursor *clayer = BYZANZ_LAYER_CURSOR (layer); cairo_region_t *region, *area; int x, y; GdkDevice *device; GdkDeviceManager *device_manager; GdkDisplay *display; GdkWindow *window; window = layer->recorder->window; display = gdk_window_get_display (window); device_manager = gdk_display_get_device_manager (display); device = gdk_device_manager_get_client_pointer (device_manager); gdk_window_get_device_position (window, device, &x, &y, NULL); if (x == clayer->cursor_x && y == clayer->cursor_y && clayer->cursor_next == clayer->cursor) return NULL; region = cairo_region_create (); byzanz_recorder_invalidate_cursor (region, clayer->cursor, clayer->cursor_x, clayer->cursor_y); byzanz_recorder_invalidate_cursor (region, clayer->cursor_next, x, y); area = cairo_region_create_rectangle (&layer->recorder->area); cairo_region_intersect (region, area); cairo_region_destroy (area); clayer->cursor = clayer->cursor_next; clayer->cursor_x = x; clayer->cursor_y = y; byzanz_layer_cursor_setup_poll (clayer); return region; }
/** * meta_background_actor_get_clip_region: * @self: a #MetaBackgroundActor * * Return value (transfer full): a #cairo_region_t that represents the part of * the background not obscured by other #MetaBackgroundActor or * #MetaWindowActor objects. */ cairo_region_t * meta_background_actor_get_clip_region (MetaBackgroundActor *self) { MetaBackgroundActorPrivate *priv = self->priv; ClutterActorBox content_box; cairo_rectangle_int_t content_area = { 0 }; cairo_region_t *clip_region; g_return_val_if_fail (META_IS_BACKGROUND_ACTOR (self), NULL); if (!priv->clip_region) return NULL; clutter_actor_get_content_box (CLUTTER_ACTOR (self), &content_box); content_area.x = content_box.x1; content_area.y = content_box.y1; content_area.width = content_box.x2 - content_box.x1; content_area.height = content_box.y2 - content_box.y1; clip_region = cairo_region_create_rectangle (&content_area); cairo_region_intersect (clip_region, priv->clip_region); return clip_region; }
// cairo_public cairo_status_t // cairo_region_intersect (cairo_region_t *dst, const cairo_region_t *other); static int l_cairo_region_intersect (lua_State* L) { cairo_region_t *dst = get_cairo_region_t (L, 1); const cairo_region_t *other = get_cairo_region_t (L, 2); cairo_status_t v = cairo_region_intersect (dst, other); lua_pushinteger(L, v); return 1; }
static cairo_int_status_t _cairo_clip_path_to_region (cairo_clip_path_t *clip_path) { cairo_int_status_t status; cairo_region_t *prev = NULL; if (clip_path->flags & (CAIRO_CLIP_PATH_HAS_REGION | CAIRO_CLIP_PATH_REGION_IS_UNSUPPORTED)) { return clip_path->flags & CAIRO_CLIP_PATH_REGION_IS_UNSUPPORTED ? CAIRO_INT_STATUS_UNSUPPORTED : CAIRO_STATUS_SUCCESS; } if (! clip_path->path.maybe_fill_region) return _cairo_clip_path_to_region_geometric (clip_path); /* first retrieve the region for our antecedents */ if (clip_path->prev != NULL) { status = _cairo_clip_path_to_region (clip_path->prev); if (status) { if (status == CAIRO_INT_STATUS_UNSUPPORTED) return _cairo_clip_path_to_region_geometric (clip_path); return status; } prev = clip_path->prev->region; } /* now extract the region for ourselves */ clip_path->region = _cairo_path_fixed_fill_rectilinear_to_region (&clip_path->path, clip_path->fill_rule, &clip_path->extents); assert (clip_path->region != NULL); status = clip_path->region->status; if (unlikely (status)) return status; if (prev != NULL) { status = cairo_region_intersect (clip_path->region, prev); if (unlikely (status)) return status; } clip_path->flags |= CAIRO_CLIP_PATH_HAS_REGION; return CAIRO_STATUS_SUCCESS; }
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; }
bool wxRegion::DoIntersect( const wxRegion& region ) { if (region.m_refData == NULL || m_refData == NULL) return false; AllocExclusive(); #ifdef __WXGTK3__ cairo_region_intersect(M_REGIONDATA->m_region, M_REGIONDATA_OF(region)->m_region); #else gdk_region_intersect( M_REGIONDATA->m_region, region.GetRegion() ); #endif return true; }
/** * meta_make_border_region: * @region: a #cairo_region_t * @x_amount: distance from the border to extend horizontally * @y_amount: distance from the border to extend vertically * @flip: if true, the result is computed with x and y interchanged * * Computes the "border region" of a given region, which is roughly * speaking the set of points near the boundary of the region. If we * define the operation of growing a region as computing the set of * points within a given manhattan distance of the region, then the * border is 'grow(region) intersect grow(inverse(region))'. * * If we create an image by filling the region with a solid color, * the border is the region affected by blurring the region. * * Return value: a new region which is the border of the given region */ cairo_region_t * meta_make_border_region (cairo_region_t *region, int x_amount, int y_amount, gboolean flip) { cairo_region_t *border_region; cairo_region_t *inverse_region; border_region = expand_region (region, x_amount, y_amount, flip); inverse_region = expand_region_inverse (region, x_amount, y_amount, flip); cairo_region_intersect (border_region, inverse_region); cairo_region_destroy (inverse_region); return border_region; }
JOY_GNUC_HOT void joy_gfx3d_window_submit(JoyBubble *self, GFX3D_NATIVE_Display display, GFX3D_NATIVE_Surface fb, cairo_region_t *area) { g_return_if_fail(JOY_IS_GFX3D_WINDOW(self)); g_return_if_fail(display); g_return_if_fail(fb); struct Private *priv = GET_PRIVATE(self); if (G_UNLIKELY(!priv->image)) { return; } gint x = joy_bubble_get_x(self); gint y = joy_bubble_get_y(self); cairo_region_intersect(priv->expose, priv->area); cairo_region_intersect(priv->expose, area); if (cairo_region_is_empty(priv->expose)) { return; } GFX3D_NATIVE_Surface surface = GFX3D_Image_Get_NATIVE_Surface(priv->image); gint n = cairo_region_num_rectangles(priv->expose); gdouble alpha = joy_bubble_get_alpha(self); if (1. == alpha) { GFX3D_NATIVE_Blit_Blend_Generic_Parms_t parameters = { { GFX3D_NATIVE_BLIT_BLEND_CONST_eOne, GFX3D_NATIVE_BLIT_BLEND_CONST_eSourceColor, 0, GFX3D_NATIVE_BLIT_BLEND_CONST_eDestinationColor, GFX3D_NATIVE_BLIT_BLEND_CONST_eInverseSourceAlpha, 0, GFX3D_NATIVE_BLIT_BLEND_CONST_eZero }, { GFX3D_NATIVE_BLIT_BLEND_CONST_eOne, GFX3D_NATIVE_BLIT_BLEND_CONST_eSourceAlpha, 0, GFX3D_NATIVE_BLIT_BLEND_CONST_eDestinationAlpha, GFX3D_NATIVE_BLIT_BLEND_CONST_eInverseSourceAlpha, 0, GFX3D_NATIVE_BLIT_BLEND_CONST_eZero, }, 0, 0, 0, GFX3D_NATIVE_BLIT_FilterCoeffs_eNone, GFX3D_NATIVE_BLIT_FilterCoeffs_eNone, 0, 0 }; for (gint i = 0; i < n; ++i) { cairo_rectangle_int_t rect; cairo_region_get_rectangle(priv->expose, i, &rect); GFX3D_NATIVE_Rect dst = { rect.x + x, rect.y + y, rect.width, rect.height }; GFX3D_NATIVE_Blit_Blend_Generic(display, fb, &dst, surface, (gpointer)&rect, fb, &dst, ¶meters); } } else { GFX3D_NATIVE_Blit_Blend_Generic_Parms_t parameters = { { GFX3D_NATIVE_BLIT_BLEND_CONST_eConstantAlpha, GFX3D_NATIVE_BLIT_BLEND_CONST_eSourceColor, 0, GFX3D_NATIVE_BLIT_BLEND_CONST_eDestinationColor, GFX3D_NATIVE_BLIT_BLEND_CONST_eInverseSourceAlpha, 0, GFX3D_NATIVE_BLIT_BLEND_CONST_eZero }, { GFX3D_NATIVE_BLIT_BLEND_CONST_eOne, GFX3D_NATIVE_BLIT_BLEND_CONST_eSourceAlpha, 0, GFX3D_NATIVE_BLIT_BLEND_CONST_eDestinationAlpha, GFX3D_NATIVE_BLIT_BLEND_CONST_eInverseSourceAlpha, 0, GFX3D_NATIVE_BLIT_BLEND_CONST_eZero, }, (gint)(0xff * alpha) << 24, 0, 0, GFX3D_NATIVE_BLIT_FilterCoeffs_eNone, GFX3D_NATIVE_BLIT_FilterCoeffs_eNone, 0, 0 }; for (gint i = 0; i < n; ++i) { cairo_rectangle_int_t rect; cairo_region_get_rectangle(priv->expose, i, &rect); GFX3D_NATIVE_Rect dst = { rect.x + x, rect.y + y, rect.width, rect.height }; GFX3D_NATIVE_Blit_Blend_Generic(display, fb, &dst, surface, (gpointer)&rect, fb, &dst, ¶meters); } } cairo_region_subtract(priv->expose, priv->expose); }
/** * meta_shadow_paint: * @window_x: x position of the region to paint a shadow for * @window_y: y position of the region to paint a shadow for * @window_width: actual width of the region to paint a shadow for * @window_height: actual height of the region to paint a shadow for * @clip: (allow-none): if non-%NULL specifies the visible portion * of the shadow. * @clip_strictly: if %TRUE, drawing will be clipped strictly * to @clip, otherwise, it will be only used to optimize * drawing. * * Paints the shadow at the given position, for the specified actual * size of the region. (Since a #MetaShadow can be shared between * different sizes with the same extracted #MetaWindowShape the * size needs to be passed in here.) */ void meta_shadow_paint (MetaShadow *shadow, int window_x, int window_y, int window_width, int window_height, guint8 opacity, cairo_region_t *clip, gboolean clip_strictly) { float texture_width = cogl_texture_get_width (shadow->texture); float texture_height = cogl_texture_get_height (shadow->texture); int i, j; float src_x[4]; float src_y[4]; int dest_x[4]; int dest_y[4]; int n_x, n_y; cogl_material_set_color4ub (shadow->material, opacity, opacity, opacity, opacity); cogl_set_source (shadow->material); if (shadow->scale_width) { n_x = 3; src_x[0] = 0.0; src_x[1] = (shadow->inner_border_left + shadow->outer_border_left) / texture_width; src_x[2] = (texture_width - (shadow->inner_border_right + shadow->outer_border_right)) / texture_width; src_x[3] = 1.0; dest_x[0] = window_x - shadow->outer_border_left; dest_x[1] = window_x + shadow->inner_border_left; dest_x[2] = window_x + window_width - shadow->inner_border_right; dest_x[3] = window_x + window_width + shadow->outer_border_right; } else { n_x = 1; src_x[0] = 0.0; src_x[1] = 1.0; dest_x[0] = window_x - shadow->outer_border_left; dest_x[1] = window_x + window_width + shadow->outer_border_right; } if (shadow->scale_height) { n_y = 3; src_y[0] = 0.0; src_y[1] = (shadow->inner_border_top + shadow->outer_border_top) / texture_height; src_y[2] = (texture_height - (shadow->inner_border_bottom + shadow->outer_border_bottom)) / texture_height; src_y[3] = 1.0; dest_y[0] = window_y - shadow->outer_border_top; dest_y[1] = window_y + shadow->inner_border_top; dest_y[2] = window_y + window_height - shadow->inner_border_bottom; dest_y[3] = window_y + window_height + shadow->outer_border_bottom; } else { n_y = 1; src_y[0] = 0.0; src_y[1] = 1.0; dest_y[0] = window_y - shadow->outer_border_top; dest_y[1] = window_y + window_height + shadow->outer_border_bottom; } for (j = 0; j < n_y; j++) { cairo_rectangle_int_t dest_rect; dest_rect.y = dest_y[j]; dest_rect.height = dest_y[j + 1] - dest_y[j]; if (dest_rect.height == 0) continue; for (i = 0; i < n_x; i++) { cairo_region_overlap_t overlap; dest_rect.x = dest_x[i]; dest_rect.width = dest_x[i + 1] - dest_x[i]; if (dest_rect.width == 0) continue; if (clip) overlap = cairo_region_contains_rectangle (clip, &dest_rect); else overlap = CAIRO_REGION_OVERLAP_IN; /* There's quite a bit of overhead from allocating a new * region in order to find an exact intersection and * generating more geometry - we make the assumption that * unless we have to clip strictly it will be cheaper to * just draw the entire rectangle. */ if (overlap == CAIRO_REGION_OVERLAP_IN || (overlap == CAIRO_REGION_OVERLAP_PART && !clip_strictly)) { cogl_rectangle_with_texture_coords (dest_x[i], dest_y[j], dest_x[i + 1], dest_y[j + 1], src_x[i], src_y[j], src_x[i + 1], src_y[j + 1]); } else if (overlap == CAIRO_REGION_OVERLAP_PART) { cairo_region_t *intersection; int n_rectangles, k; intersection = cairo_region_create_rectangle (&dest_rect); cairo_region_intersect (intersection, clip); n_rectangles = cairo_region_num_rectangles (intersection); for (k = 0; k < n_rectangles; k++) { cairo_rectangle_int_t rect; float src_x1, src_x2, src_y1, src_y2; cairo_region_get_rectangle (intersection, k, &rect); /* Separately linear interpolate X and Y coordinates in the source * based on the destination X and Y coordinates */ src_x1 = (src_x[i] * (dest_rect.x + dest_rect.width - rect.x) + src_x[i + 1] * (rect.x - dest_rect.x)) / dest_rect.width; src_x2 = (src_x[i] * (dest_rect.x + dest_rect.width - (rect.x + rect.width)) + src_x[i + 1] * (rect.x + rect.width - dest_rect.x)) / dest_rect.width; src_y1 = (src_y[j] * (dest_rect.y + dest_rect.height - rect.y) + src_y[j + 1] * (rect.y - dest_rect.y)) / dest_rect.height; src_y2 = (src_y[j] * (dest_rect.y + dest_rect.height - (rect.y + rect.height)) + src_y[j + 1] * (rect.y + rect.height - dest_rect.y)) / dest_rect.height; cogl_rectangle_with_texture_coords (rect.x, rect.y, rect.x + rect.width, rect.y + rect.height, src_x1, src_y1, src_x2, src_y2); } cairo_region_destroy (intersection); } } } }
/** * gdk_cairo_draw_from_gl: * @cr: a cairo context * @window: The window we're rendering for (not necessarily into) * @source: The GL ID of the source buffer * @source_type: The type of the @source * @buffer_scale: The scale-factor that the @source buffer is allocated for * @x: The source x position in @source to start copying from in GL coordinates * @y: The source y position in @source to start copying from in GL coordinates * @width: The width of the region to draw * @height: The height of the region to draw * * This is the main way to draw GL content in GTK+. It takes a render buffer ID * (@source_type == #GL_RENDERBUFFER) or a texture id (@source_type == #GL_TEXTURE) * and draws it onto @cr with an OVER operation, respecting the current clip. * The top left corner of the rectangle specified by @x, @y, @width and @height * will be drawn at the current (0,0) position of the cairo_t. * * This will work for *all* cairo_t, as long as @window is realized, but the * fallback implementation that reads back the pixels from the buffer may be * used in the general case. In the case of direct drawing to a window with * no special effects applied to @cr it will however use a more efficient * approach. * * For #GL_RENDERBUFFER the code will always fall back to software for buffers * with alpha components, so make sure you use #GL_TEXTURE if using alpha. * * Calling this may change the current GL context. * * Since: 3.16 */ void gdk_cairo_draw_from_gl (cairo_t *cr, GdkWindow *window, int source, int source_type, int buffer_scale, int x, int y, int width, int height) { GdkGLContext *paint_context; cairo_surface_t *image; cairo_matrix_t matrix; int dx, dy, window_scale; gboolean trivial_transform; cairo_surface_t *group_target; GdkWindow *direct_window, *impl_window; guint framebuffer; int alpha_size = 0; cairo_region_t *clip_region; GdkGLContextPaintData *paint_data; impl_window = window->impl_window; window_scale = gdk_window_get_scale_factor (impl_window); paint_context = gdk_window_get_paint_gl_context (window, NULL); if (paint_context == NULL) { g_warning ("gdk_cairo_draw_gl_render_buffer failed - no paint context"); return; } clip_region = gdk_cairo_region_from_clip (cr); gdk_gl_context_make_current (paint_context); paint_data = gdk_gl_context_get_paint_data (paint_context); if (paint_data->tmp_framebuffer == 0) glGenFramebuffersEXT (1, &paint_data->tmp_framebuffer); if (source_type == GL_RENDERBUFFER) { glBindRenderbuffer (GL_RENDERBUFFER, source); glGetRenderbufferParameteriv (GL_RENDERBUFFER, GL_RENDERBUFFER_ALPHA_SIZE, &alpha_size); } else if (source_type == GL_TEXTURE) { glBindTexture (GL_TEXTURE_2D, source); glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_ALPHA_SIZE, &alpha_size); } else { g_warning ("Unsupported gl source type %d\n", source_type); return; } group_target = cairo_get_group_target (cr); direct_window = cairo_surface_get_user_data (group_target, &direct_key); cairo_get_matrix (cr, &matrix); dx = matrix.x0; dy = matrix.y0; /* Trivial == integer-only translation */ trivial_transform = (double)dx == matrix.x0 && (double)dy == matrix.y0 && matrix.xx == 1.0 && matrix.xy == 0.0 && matrix.yx == 0.0 && matrix.yy == 1.0; /* For direct paint of non-alpha renderbuffer, we can just do a bitblit */ if ((_gdk_gl_flags & GDK_GL_SOFTWARE_DRAW_GL) == 0 && source_type == GL_RENDERBUFFER && alpha_size == 0 && direct_window != NULL && direct_window->current_paint.use_gl && trivial_transform && clip_region != NULL) { int unscaled_window_height; int i; /* Create a framebuffer with the source renderbuffer and make it the current target for reads */ framebuffer = paint_data->tmp_framebuffer; glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, framebuffer); glFramebufferRenderbufferEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, source); glBindFramebufferEXT (GL_DRAW_FRAMEBUFFER_EXT, 0); /* Translate to impl coords */ cairo_region_translate (clip_region, dx, dy); glEnable (GL_SCISSOR_TEST); gdk_window_get_unscaled_size (impl_window, NULL, &unscaled_window_height); glDrawBuffer (GL_BACK); #define FLIP_Y(_y) (unscaled_window_height - (_y)) for (i = 0; i < cairo_region_num_rectangles (clip_region); i++) { cairo_rectangle_int_t clip_rect, dest; cairo_region_get_rectangle (clip_region, i, &clip_rect); clip_rect.x *= window_scale; clip_rect.y *= window_scale; clip_rect.width *= window_scale; clip_rect.height *= window_scale; glScissor (clip_rect.x, FLIP_Y (clip_rect.y + clip_rect.height), clip_rect.width, clip_rect.height); dest.x = dx * window_scale; dest.y = dy * window_scale; dest.width = width * window_scale / buffer_scale; dest.height = height * window_scale / buffer_scale; if (gdk_rectangle_intersect (&clip_rect, &dest, &dest)) { int clipped_src_x = x + (dest.x - dx * window_scale); int clipped_src_y = y + (height - dest.height - (dest.y - dy * window_scale)); glBlitFramebufferEXT(clipped_src_x, clipped_src_y, (clipped_src_x + dest.width), (clipped_src_y + dest.height), dest.x, FLIP_Y(dest.y + dest.height), dest.x + dest.width, FLIP_Y(dest.y), GL_COLOR_BUFFER_BIT, GL_NEAREST); if (impl_window->current_paint.flushed_region) { cairo_rectangle_int_t flushed_rect; flushed_rect.x = dest.x / window_scale; flushed_rect.y = dest.y / window_scale; flushed_rect.width = (dest.x + dest.width + window_scale - 1) / window_scale - flushed_rect.x; flushed_rect.height = (dest.y + dest.height + window_scale - 1) / window_scale - flushed_rect.y; cairo_region_union_rectangle (impl_window->current_paint.flushed_region, &flushed_rect); cairo_region_subtract_rectangle (impl_window->current_paint.need_blend_region, &flushed_rect); } } } glDisable (GL_SCISSOR_TEST); glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0); #undef FLIP_Y } /* For direct paint of alpha or non-alpha textures we can use texturing */ else if ((_gdk_gl_flags & GDK_GL_SOFTWARE_DRAW_GL) == 0 && source_type == GL_TEXTURE && direct_window != NULL && direct_window->current_paint.use_gl && trivial_transform && clip_region != NULL) { int unscaled_window_height; GLint texture_width; GLint texture_height; int i, n_rects, n_quads; GdkTexturedQuad *quads; cairo_rectangle_int_t clip_rect; /* Translate to impl coords */ cairo_region_translate (clip_region, dx, dy); if (alpha_size != 0) { cairo_region_t *opaque_region, *blend_region; opaque_region = cairo_region_copy (clip_region); cairo_region_subtract (opaque_region, impl_window->current_paint.flushed_region); cairo_region_subtract (opaque_region, impl_window->current_paint.need_blend_region); if (!cairo_region_is_empty (opaque_region)) gdk_gl_texture_from_surface (impl_window->current_paint.surface, opaque_region); blend_region = cairo_region_copy (clip_region); cairo_region_intersect (blend_region, impl_window->current_paint.need_blend_region); glEnable (GL_BLEND); if (!cairo_region_is_empty (blend_region)) gdk_gl_texture_from_surface (impl_window->current_paint.surface, blend_region); cairo_region_destroy (opaque_region); cairo_region_destroy (blend_region); } glBindTexture (GL_TEXTURE_2D, source); glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &texture_width); glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &texture_height); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glEnable (GL_SCISSOR_TEST); gdk_window_get_unscaled_size (impl_window, NULL, &unscaled_window_height); #define FLIP_Y(_y) (unscaled_window_height - (_y)) cairo_region_get_extents (clip_region, &clip_rect); glScissor (clip_rect.x * window_scale, FLIP_Y ((clip_rect.y + clip_rect.height) * window_scale), clip_rect.width * window_scale, clip_rect.height * window_scale); n_quads = 0; n_rects = cairo_region_num_rectangles (clip_region); quads = g_new (GdkTexturedQuad, n_rects); for (i = 0; i < n_rects; i++) { cairo_rectangle_int_t dest; cairo_region_get_rectangle (clip_region, i, &clip_rect); clip_rect.x *= window_scale; clip_rect.y *= window_scale; clip_rect.width *= window_scale; clip_rect.height *= window_scale; dest.x = dx * window_scale; dest.y = dy * window_scale; dest.width = width * window_scale / buffer_scale; dest.height = height * window_scale / buffer_scale; if (gdk_rectangle_intersect (&clip_rect, &dest, &dest)) { int clipped_src_x = x + (dest.x - dx * window_scale); int clipped_src_y = y + (height - dest.height - (dest.y - dy * window_scale)); GdkTexturedQuad quad = { dest.x, FLIP_Y(dest.y), dest.x + dest.width, FLIP_Y(dest.y + dest.height), clipped_src_x / (float)texture_width, (clipped_src_y + dest.height) / (float)texture_height, (clipped_src_x + dest.width) / (float)texture_width, clipped_src_y / (float)texture_height, }; quads[n_quads++] = quad; if (impl_window->current_paint.flushed_region) { cairo_rectangle_int_t flushed_rect; flushed_rect.x = dest.x / window_scale; flushed_rect.y = dest.y / window_scale; flushed_rect.width = (dest.x + dest.width + window_scale - 1) / window_scale - flushed_rect.x; flushed_rect.height = (dest.y + dest.height + window_scale - 1) / window_scale - flushed_rect.y; cairo_region_union_rectangle (impl_window->current_paint.flushed_region, &flushed_rect); cairo_region_subtract_rectangle (impl_window->current_paint.need_blend_region, &flushed_rect); } } } if (n_quads > 0) gdk_gl_texture_quads (paint_context, GL_TEXTURE_2D, n_quads, quads); g_free (quads); if (alpha_size != 0) glDisable (GL_BLEND); #undef FLIP_Y } else { /* Software fallback */ /* TODO: avoid reading back non-required data due to dest clip */ image = cairo_surface_create_similar_image (cairo_get_target (cr), (alpha_size == 0) ? CAIRO_FORMAT_RGB24 : CAIRO_FORMAT_ARGB32, width, height); cairo_surface_set_device_scale (image, buffer_scale, buffer_scale); framebuffer = paint_data->tmp_framebuffer; glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, framebuffer); if (source_type == GL_RENDERBUFFER) { /* Create a framebuffer with the source renderbuffer and make it the current target for reads */ glFramebufferRenderbufferEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, source); } else { glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, source, 0); } glPixelStorei (GL_PACK_ALIGNMENT, 4); glPixelStorei (GL_PACK_ROW_LENGTH, cairo_image_surface_get_stride (image) / 4); glReadPixels (x, y, width, height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, cairo_image_surface_get_data (image)); glPixelStorei (GL_PACK_ROW_LENGTH, 0); glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0); cairo_surface_mark_dirty (image); /* Invert due to opengl having different origin */ cairo_scale (cr, 1, -1); cairo_translate (cr, 0, -height / buffer_scale); cairo_set_source_surface (cr, image, 0, 0); cairo_set_operator (cr, CAIRO_OPERATOR_OVER); cairo_paint (cr); cairo_surface_destroy (image); } if (clip_region) cairo_region_destroy (clip_region); }
void Region::Intersect (Region *region) { status = cairo_region_intersect (cairo_region, region->cairo_region); }