glamor: Fix screen_x/screen_y handling for compositing.
It's not an offset from pixmap coords to composited pixmap coords, it's an offset from screen-relative window drawable coords to composited pixmap coords.
This commit is contained in:
		
							parent
							
								
									5360b1e8bb
								
							
						
					
					
						commit
						be82a06242
					
				|  | @ -41,9 +41,8 @@ glamor_copy_n_to_n_copypixels(DrawablePtr src, | |||
| 			      int dx, | ||||
| 			      int dy) | ||||
| { | ||||
|     PixmapPtr src_pixmap = glamor_get_drawable_pixmap(src); | ||||
|     PixmapPtr dst_pixmap = glamor_get_drawable_pixmap(dst); | ||||
|     int i; | ||||
|     int x_off, y_off, i; | ||||
| 
 | ||||
|     if (src != dst) { | ||||
| 	glamor_fallback("glamor_copy_n_to_n_copypixels(): src != dest\n"); | ||||
|  | @ -74,12 +73,14 @@ glamor_copy_n_to_n_copypixels(DrawablePtr src, | |||
|     glMatrixMode(GL_PROJECTION); | ||||
|     glLoadIdentity(); | ||||
| 
 | ||||
|     glamor_get_drawable_deltas(dst, dst_pixmap, &x_off, &y_off); | ||||
| 
 | ||||
|     for (i = 0; i < nbox; i++) { | ||||
| 	int flip_y1 = dst_pixmap->drawable.height - 1 - box[i].y2; | ||||
| 	glRasterPos2i(box[i].x1 - dst_pixmap->screen_x, | ||||
| 		      flip_y1 - dst_pixmap->screen_x); | ||||
| 	glCopyPixels(box[i].x1 + dx - src_pixmap->screen_x, | ||||
| 		     flip_y1 - dy - src_pixmap->screen_y, | ||||
| 	int flip_y1 = dst_pixmap->drawable.height - 1 - box[i].y2 + y_off; | ||||
| 	glRasterPos2i(box[i].x1 + x_off, | ||||
| 		      flip_y1); | ||||
| 	glCopyPixels(box[i].x1 + dx + x_off, | ||||
| 		     flip_y1 - dy, | ||||
| 		     box[i].x2 - box[i].x1, | ||||
| 		     box[i].y2 - box[i].y1, | ||||
| 		     GL_COLOR); | ||||
|  | @ -104,6 +105,7 @@ glamor_copy_n_to_n_textured(DrawablePtr src, | |||
|     int i; | ||||
|     float vertices[4][2], texcoords[4][2]; | ||||
|     glamor_pixmap_private *src_pixmap_priv; | ||||
|     int src_x_off, src_y_off, dst_x_off, dst_y_off; | ||||
| 
 | ||||
|     src_pixmap_priv = glamor_get_pixmap_private(src_pixmap); | ||||
| 
 | ||||
|  | @ -126,6 +128,11 @@ glamor_copy_n_to_n_textured(DrawablePtr src, | |||
| 	    goto fail; | ||||
|     } | ||||
| 
 | ||||
|     glamor_get_drawable_deltas(dst, dst_pixmap, &dst_x_off, &dst_y_off); | ||||
|     glamor_get_drawable_deltas(src, src_pixmap, &src_x_off, &src_y_off); | ||||
|     dx += src_x_off; | ||||
|     dy += src_y_off; | ||||
| 
 | ||||
|     glActiveTexture(GL_TEXTURE0); | ||||
|     glBindTexture(GL_TEXTURE_2D, src_pixmap_priv->tex); | ||||
|     glEnable(GL_TEXTURE_2D); | ||||
|  | @ -143,14 +150,14 @@ glamor_copy_n_to_n_textured(DrawablePtr src, | |||
|     glUseProgramObjectARB(glamor_priv->finish_access_prog); | ||||
| 
 | ||||
|     for (i = 0; i < nbox; i++) { | ||||
| 	vertices[0][0] = v_from_x_coord_x(dst_pixmap, box[i].x1); | ||||
| 	vertices[0][1] = v_from_x_coord_y(dst_pixmap, box[i].y1); | ||||
| 	vertices[1][0] = v_from_x_coord_x(dst_pixmap, box[i].x2); | ||||
| 	vertices[1][1] = v_from_x_coord_y(dst_pixmap, box[i].y1); | ||||
| 	vertices[2][0] = v_from_x_coord_x(dst_pixmap, box[i].x2); | ||||
| 	vertices[2][1] = v_from_x_coord_y(dst_pixmap, box[i].y2); | ||||
| 	vertices[3][0] = v_from_x_coord_x(dst_pixmap, box[i].x1); | ||||
| 	vertices[3][1] = v_from_x_coord_y(dst_pixmap, box[i].y2); | ||||
| 	vertices[0][0] = v_from_x_coord_x(dst_pixmap, box[i].x1 + dst_x_off); | ||||
| 	vertices[0][1] = v_from_x_coord_y(dst_pixmap, box[i].y1 + dst_y_off); | ||||
| 	vertices[1][0] = v_from_x_coord_x(dst_pixmap, box[i].x2 + dst_x_off); | ||||
| 	vertices[1][1] = v_from_x_coord_y(dst_pixmap, box[i].y1 + dst_y_off); | ||||
| 	vertices[2][0] = v_from_x_coord_x(dst_pixmap, box[i].x2 + dst_x_off); | ||||
| 	vertices[2][1] = v_from_x_coord_y(dst_pixmap, box[i].y2 + dst_y_off); | ||||
| 	vertices[3][0] = v_from_x_coord_x(dst_pixmap, box[i].x1 + dst_x_off); | ||||
| 	vertices[3][1] = v_from_x_coord_y(dst_pixmap, box[i].y2 + dst_y_off); | ||||
| 
 | ||||
| 	texcoords[0][0] = t_from_x_coord_x(src_pixmap, box[i].x1 + dx); | ||||
| 	texcoords[0][1] = t_from_x_coord_y(src_pixmap, box[i].y1 + dy); | ||||
|  |  | |||
|  | @ -52,6 +52,27 @@ glamor_get_drawable_location(const DrawablePtr drawable) | |||
| 	return 'f'; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  * Sets the offsets to add to coordinates to make them address the same bits in | ||||
|  * the backing drawable. These coordinates are nonzero only for redirected | ||||
|  * windows. | ||||
|  */ | ||||
| void | ||||
| glamor_get_drawable_deltas(DrawablePtr drawable, PixmapPtr pixmap, | ||||
| 			   int *x, int *y) | ||||
| { | ||||
| #ifdef COMPOSITE | ||||
|     if (drawable->type == DRAWABLE_WINDOW) { | ||||
| 	*x = -pixmap->screen_x; | ||||
| 	*y = -pixmap->screen_y; | ||||
| 	return; | ||||
|     } | ||||
| #endif | ||||
| 
 | ||||
|     *x = 0; | ||||
|     *y = 0; | ||||
| } | ||||
| 
 | ||||
| Bool | ||||
| glamor_set_destination_pixmap(PixmapPtr pixmap) | ||||
| { | ||||
|  |  | |||
|  | @ -41,12 +41,15 @@ glamor_fill(DrawablePtr drawable, | |||
| 	    int height) | ||||
| { | ||||
|     PixmapPtr dst_pixmap = glamor_get_drawable_pixmap(drawable); | ||||
|     int x_off, y_off; | ||||
| 
 | ||||
|     glamor_get_drawable_deltas(drawable, dst_pixmap, &x_off, &y_off); | ||||
| 
 | ||||
|     switch (gc->fillStyle) { | ||||
|     case FillSolid: | ||||
| 	glamor_solid(dst_pixmap, | ||||
| 		     x - dst_pixmap->screen_x, | ||||
| 		     y - dst_pixmap->screen_y, | ||||
| 		     x + x_off, | ||||
| 		     y + y_off, | ||||
| 		     width, | ||||
| 		     height, | ||||
| 		     gc->alu, | ||||
|  | @ -57,28 +60,28 @@ glamor_fill(DrawablePtr drawable, | |||
|     case FillOpaqueStippled: | ||||
| 	glamor_stipple(dst_pixmap, | ||||
| 		       gc->stipple, | ||||
| 		       x - dst_pixmap->screen_x, | ||||
| 		       y - dst_pixmap->screen_y, | ||||
| 		       x+ x_off, | ||||
| 		       y + y_off, | ||||
| 		       width, | ||||
| 		       height, | ||||
| 		       gc->alu, | ||||
| 		       gc->planemask, | ||||
| 		       gc->fgPixel, | ||||
| 		       gc->bgPixel, | ||||
| 		       gc->patOrg.x - dst_pixmap->screen_x, | ||||
| 		       gc->patOrg.y - dst_pixmap->screen_y); | ||||
| 		       gc->patOrg.x + x_off, | ||||
| 		       gc->patOrg.y + y_off); | ||||
| 	break; | ||||
|     case FillTiled: | ||||
| 	glamor_tile(dst_pixmap, | ||||
| 		    gc->tile.pixmap, | ||||
| 		    x - dst_pixmap->screen_x, | ||||
| 		    y - dst_pixmap->screen_y, | ||||
| 		    x + x_off, | ||||
| 		    y + y_off, | ||||
| 		    width, | ||||
| 		    height, | ||||
| 		    gc->alu, | ||||
| 		    gc->planemask, | ||||
| 		    gc->patOrg.x - dst_pixmap->screen_y, | ||||
| 		    gc->patOrg.y - dst_pixmap->screen_y); | ||||
| 		    gc->patOrg.x, | ||||
| 		    gc->patOrg.y); | ||||
| 	break; | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -55,6 +55,7 @@ glamor_get_spans(DrawablePtr drawable, | |||
|     GLenum format, type; | ||||
|     int i, j; | ||||
|     uint8_t *temp_dst = NULL, *readpixels_dst = (uint8_t *)dst; | ||||
|     int x_off, y_off; | ||||
| 
 | ||||
|     goto fail; | ||||
| 
 | ||||
|  | @ -86,9 +87,11 @@ glamor_get_spans(DrawablePtr drawable, | |||
|     if (!glamor_set_destination_pixmap(pixmap)) | ||||
| 	goto fail; | ||||
| 
 | ||||
|     glamor_get_drawable_deltas(drawable, pixmap, &x_off, &y_off); | ||||
| 
 | ||||
|     for (i = 0; i < count; i++) { | ||||
| 	glReadPixels(points[i].x - pixmap->screen_x, | ||||
| 		     points[i].y - pixmap->screen_y, | ||||
| 	glReadPixels(points[i].x + x_off, | ||||
| 		     points[i].y + y_off, | ||||
| 		     widths[i], | ||||
| 		     1, | ||||
| 		     format, type, | ||||
|  |  | |||
|  | @ -200,25 +200,25 @@ glamor_fallback(char *format, ...) | |||
| static inline float | ||||
| v_from_x_coord_x(PixmapPtr pixmap, int x) | ||||
| { | ||||
|     return (float)(x - pixmap->screen_x) / pixmap->drawable.width * 2.0 - 1.0; | ||||
|     return (float)x / pixmap->drawable.width * 2.0 - 1.0; | ||||
| } | ||||
| 
 | ||||
| static inline float | ||||
| v_from_x_coord_y(PixmapPtr pixmap, int y) | ||||
| { | ||||
|     return (float)(y - pixmap->screen_y) / pixmap->drawable.height * -2.0 + 1.0; | ||||
|     return (float)y / pixmap->drawable.height * -2.0 + 1.0; | ||||
| } | ||||
| 
 | ||||
| static inline float | ||||
| t_from_x_coord_x(PixmapPtr pixmap, int x) | ||||
| { | ||||
|     return (float)(x - pixmap->screen_x) / pixmap->drawable.width; | ||||
|     return (float)x / pixmap->drawable.width; | ||||
| } | ||||
| 
 | ||||
| static inline float | ||||
| t_from_x_coord_y(PixmapPtr pixmap, int y) | ||||
| { | ||||
|     return 1.0 - (float)(y - pixmap->screen_y) / pixmap->drawable.height; | ||||
|     return 1.0 - (float)y / pixmap->drawable.height; | ||||
| } | ||||
| 
 | ||||
| /* glamor.c */ | ||||
|  | @ -254,6 +254,8 @@ Bool glamor_prepare_access_gc(GCPtr gc); | |||
| void glamor_finish_access_gc(GCPtr gc); | ||||
| void glamor_init_finish_access_shaders(ScreenPtr screen); | ||||
| const Bool glamor_get_drawable_location(const DrawablePtr drawable); | ||||
| void glamor_get_drawable_deltas(DrawablePtr drawable, PixmapPtr pixmap, | ||||
| 				int *x, int *y); | ||||
| Bool glamor_create_gc(GCPtr gc); | ||||
| void glamor_stipple(PixmapPtr pixmap, PixmapPtr stipple, | ||||
| 		    int x, int y, int width, int height, | ||||
|  |  | |||
|  | @ -244,6 +244,7 @@ glamor_put_image(DrawablePtr drawable, GCPtr gc, int depth, int x, int y, | |||
|     int nbox; | ||||
|     int bpp = drawable->bitsPerPixel; | ||||
|     int src_stride = PixmapBytePad(w, drawable->depth); | ||||
|     int x_off, y_off; | ||||
| 
 | ||||
|     goto fail; | ||||
| 
 | ||||
|  | @ -297,6 +298,8 @@ glamor_put_image(DrawablePtr drawable, GCPtr gc, int depth, int x, int y, | |||
|     x += drawable->x; | ||||
|     y += drawable->y; | ||||
| 
 | ||||
|     glamor_get_drawable_deltas(drawable, pixmap, &x_off, &y_off); | ||||
| 
 | ||||
|     glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | ||||
|     glPixelStorei(GL_UNPACK_ROW_LENGTH, src_stride * 8 / bpp); | ||||
|     if (bpp == 1) | ||||
|  | @ -325,7 +328,7 @@ glamor_put_image(DrawablePtr drawable, GCPtr gc, int depth, int x, int y, | |||
| 	    continue; | ||||
| 
 | ||||
| 	src = bits + (y1 - y) * src_stride + (x1 - x) * (bpp / 8); | ||||
| 	glRasterPos2i(x1 - pixmap->screen_x, y1 - pixmap->screen_y); | ||||
| 	glRasterPos2i(x1 + x_off, y1 + y_off); | ||||
| 	glDrawPixels(x2 - x1, | ||||
| 		     y2 - y1, | ||||
| 		     format, type, | ||||
|  |  | |||
|  | @ -533,6 +533,7 @@ glamor_composite_with_shader(CARD8 op, | |||
|     float vertices[4][2], source_texcoords[4][2], mask_texcoords[4][2]; | ||||
|     int i; | ||||
|     BoxPtr box; | ||||
|     int dst_x_off, dst_y_off; | ||||
| 
 | ||||
|     memset(&key, 0, sizeof(key)); | ||||
|     if (!source->pDrawable) { | ||||
|  | @ -673,16 +674,33 @@ glamor_composite_with_shader(CARD8 op, | |||
| 	glEnableClientState(GL_TEXTURE_COORD_ARRAY); | ||||
|     } | ||||
| 
 | ||||
|     glamor_get_drawable_deltas(dest->pDrawable, dest_pixmap, | ||||
| 			       &dst_x_off, &dst_y_off); | ||||
|     if (source_pixmap) { | ||||
| 	int dx, dy; | ||||
| 
 | ||||
| 	glamor_get_drawable_deltas(source->pDrawable, source_pixmap, &dx, &dy); | ||||
| 	x_source += dx; | ||||
| 	y_source += dy; | ||||
|     } | ||||
|     if (mask_pixmap) { | ||||
| 	int dx, dy; | ||||
| 
 | ||||
| 	glamor_get_drawable_deltas(mask->pDrawable, mask_pixmap, &dx, &dy); | ||||
| 	x_mask += dx; | ||||
| 	y_mask += dy; | ||||
|     } | ||||
| 
 | ||||
|     box = REGION_RECTS(®ion); | ||||
|     for (i = 0; i < REGION_NUM_RECTS(®ion); i++) { | ||||
| 	vertices[0][0] = v_from_x_coord_x(dest_pixmap, box[i].x1); | ||||
| 	vertices[0][1] = v_from_x_coord_y(dest_pixmap, box[i].y1); | ||||
| 	vertices[1][0] = v_from_x_coord_x(dest_pixmap, box[i].x2); | ||||
| 	vertices[1][1] = v_from_x_coord_y(dest_pixmap, box[i].y1); | ||||
| 	vertices[2][0] = v_from_x_coord_x(dest_pixmap, box[i].x2); | ||||
| 	vertices[2][1] = v_from_x_coord_y(dest_pixmap, box[i].y2); | ||||
| 	vertices[3][0] = v_from_x_coord_x(dest_pixmap, box[i].x1); | ||||
| 	vertices[3][1] = v_from_x_coord_y(dest_pixmap, box[i].y2); | ||||
| 	vertices[0][0] = v_from_x_coord_x(dest_pixmap, box[i].x1 + dst_x_off); | ||||
| 	vertices[0][1] = v_from_x_coord_y(dest_pixmap, box[i].y1 + dst_y_off); | ||||
| 	vertices[1][0] = v_from_x_coord_x(dest_pixmap, box[i].x2 + dst_x_off); | ||||
| 	vertices[1][1] = v_from_x_coord_y(dest_pixmap, box[i].y1 + dst_y_off); | ||||
| 	vertices[2][0] = v_from_x_coord_x(dest_pixmap, box[i].x2 + dst_x_off); | ||||
| 	vertices[2][1] = v_from_x_coord_y(dest_pixmap, box[i].y2 + dst_y_off); | ||||
| 	vertices[3][0] = v_from_x_coord_x(dest_pixmap, box[i].x1 + dst_x_off); | ||||
| 	vertices[3][1] = v_from_x_coord_y(dest_pixmap, box[i].y2 + dst_y_off); | ||||
| 
 | ||||
| 	if (key.source != SHADER_SOURCE_SOLID) { | ||||
| 	    int tx1 = box[i].x1 + x_source - x_dest; | ||||
|  |  | |||
|  | @ -42,6 +42,7 @@ glamor_set_spans(DrawablePtr drawable, GCPtr gc, char *src, | |||
|     int wmax = 0; | ||||
|     RegionPtr clip = fbGetCompositeClip(gc); | ||||
|     BoxRec *pbox; | ||||
|     int x_off, y_off; | ||||
| 
 | ||||
|     goto fail; | ||||
| 
 | ||||
|  | @ -82,6 +83,9 @@ glamor_set_spans(DrawablePtr drawable, GCPtr gc, char *src, | |||
|     glamor_set_alu(gc->alu); | ||||
|     if (!glamor_set_planemask(dest_pixmap, gc->planemask)) | ||||
| 	goto fail; | ||||
| 
 | ||||
|     glamor_get_drawable_deltas(drawable, dest_pixmap, &x_off, &y_off); | ||||
| 
 | ||||
|     for (i = 0; i < n; i++) { | ||||
| 	if (temp_src) { | ||||
| 	    for (j = 0; j < widths[i]; j++) { | ||||
|  | @ -98,12 +102,12 @@ glamor_set_spans(DrawablePtr drawable, GCPtr gc, char *src, | |||
| 	    if (pbox->y1 > points[i].y) | ||||
| 		break; | ||||
| 	    glScissor(pbox->x1, | ||||
| 		      points[i].y - dest_pixmap->screen_y, | ||||
| 		      points[i].y + y_off, | ||||
| 		      pbox->x2 - pbox->x1, | ||||
| 		      1); | ||||
| 	    glEnable(GL_SCISSOR_TEST); | ||||
| 	    glRasterPos2i(points[i].x - dest_pixmap->screen_x, | ||||
| 			  points[i].y - dest_pixmap->screen_y); | ||||
| 	    glRasterPos2i(points[i].x + x_off, | ||||
| 			  points[i].y + y_off); | ||||
| 	    glDrawPixels(widths[i], | ||||
| 			 1, | ||||
| 			 format, type, | ||||
|  |  | |||
|  | @ -92,10 +92,10 @@ glamor_tile(PixmapPtr pixmap, PixmapPtr tile, | |||
|     int x2 = x + width; | ||||
|     int y1 = y; | ||||
|     int y2 = y + height; | ||||
|     int tile_x1 = tile_x - tile->screen_x; | ||||
|     int tile_x2 = tile_x - tile->screen_x + width; | ||||
|     int tile_y1 = tile_y - tile->screen_y; | ||||
|     int tile_y2 = tile_y - tile->screen_y + height; | ||||
|     int tile_x1 = tile_x; | ||||
|     int tile_x2 = tile_x + width; | ||||
|     int tile_y1 = tile_y; | ||||
|     int tile_y2 = tile_y + height; | ||||
|     glamor_pixmap_private *tile_priv = glamor_get_pixmap_private(tile); | ||||
| 
 | ||||
|     if (glamor_priv->tile_prog == 0) { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue