glamor: Simplify temporary picture uploading call stack.

glamor_upload_sub_pixmap_to_texture() only had the one caller, so we
can merge it in, fix its silly return value, and propagate a bunch of
constants.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Eric Anholt <eric@anholt.net>
This commit is contained in:
Eric Anholt 2016-02-01 13:58:04 -08:00 committed by Adam Jackson
parent 25ce263fd8
commit a96c6d4658
3 changed files with 37 additions and 76 deletions

View File

@ -797,11 +797,15 @@ glamor_put_bits(char *dst_bits, int dst_stride, char *src_bits,
} }
} }
static Bool /* Upload picture to texture. We may need to flip the y axis or
glamor_upload_sub_pixmap_to_texture(PixmapPtr pixmap, int x, int y, int w, * wire alpha to 1. So we may conditional create fbo for the picture.
int h, int stride, void *bits, int pbo, * */
PictFormatShort pict_format) Bool
glamor_upload_picture_to_texture(PicturePtr picture)
{ {
PixmapPtr pixmap = glamor_get_drawable_pixmap(picture->pDrawable);
void *bits = pixmap->devPrivate.ptr;
int stride = pixmap->devKind;
ScreenPtr screen = pixmap->drawable.pScreen; ScreenPtr screen = pixmap->drawable.pScreen;
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen); glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
GLenum format, type; GLenum format, type;
@ -810,7 +814,7 @@ glamor_upload_sub_pixmap_to_texture(PixmapPtr pixmap, int x, int y, int w,
Bool force_clip; Bool force_clip;
if (glamor_get_tex_format_type_from_pixmap(pixmap, if (glamor_get_tex_format_type_from_pixmap(pixmap,
pict_format, picture->format,
&format, &format,
&type, &type,
&no_alpha, &no_alpha,
@ -822,8 +826,7 @@ glamor_upload_sub_pixmap_to_texture(PixmapPtr pixmap, int x, int y, int w,
return FALSE; return FALSE;
pixmap_priv = glamor_get_pixmap_private(pixmap); pixmap_priv = glamor_get_pixmap_private(pixmap);
force_clip = glamor_priv->gl_flavor != GLAMOR_GL_DESKTOP force_clip = glamor_priv->gl_flavor != GLAMOR_GL_DESKTOP;
&& !glamor_check_fbo_size(glamor_priv, w, h);
if (glamor_pixmap_priv_is_large(pixmap_priv) || force_clip) { if (glamor_pixmap_priv_is_large(pixmap_priv) || force_clip) {
RegionRec region; RegionRec region;
@ -833,13 +836,13 @@ glamor_upload_sub_pixmap_to_texture(PixmapPtr pixmap, int x, int y, int w,
void *sub_bits; void *sub_bits;
int i, j; int i, j;
sub_bits = xallocarray(h, stride); sub_bits = xallocarray(pixmap->drawable.height, stride);
if (sub_bits == NULL) if (sub_bits == NULL)
return FALSE; return FALSE;
box.x1 = x; box.x1 = 0;
box.y1 = y; box.y1 = 0;
box.x2 = x + w; box.x2 = pixmap->drawable.width;
box.y2 = y + h; box.y2 = pixmap->drawable.height;
RegionInitBoxes(&region, &box, 1); RegionInitBoxes(&region, &box, 1);
if (!force_clip) if (!force_clip)
clipped_regions = clipped_regions =
@ -860,8 +863,6 @@ glamor_upload_sub_pixmap_to_texture(PixmapPtr pixmap, int x, int y, int w,
int temp_stride; int temp_stride;
void *temp_bits; void *temp_bits;
assert(pbo == 0);
glamor_set_pixmap_fbo_current(pixmap_priv, clipped_regions[i].block_idx); glamor_set_pixmap_fbo_current(pixmap_priv, clipped_regions[i].block_idx);
boxes = RegionRects(clipped_regions[i].region); boxes = RegionRects(clipped_regions[i].region);
@ -871,26 +872,26 @@ glamor_upload_sub_pixmap_to_texture(PixmapPtr pixmap, int x, int y, int w,
temp_stride = PixmapBytePad(boxes[j].x2 - boxes[j].x1, temp_stride = PixmapBytePad(boxes[j].x2 - boxes[j].x1,
pixmap->drawable.depth); pixmap->drawable.depth);
if (boxes[j].x1 == x && temp_stride == stride) { if (boxes[j].x1 == 0 && temp_stride == stride) {
temp_bits = (char *) bits + (boxes[j].y1 - y) * stride; temp_bits = (char *) bits + boxes[j].y1 * stride;
} }
else { else {
temp_bits = sub_bits; temp_bits = sub_bits;
glamor_put_bits(temp_bits, temp_stride, bits, stride, glamor_put_bits(temp_bits, temp_stride, bits, stride,
pixmap->drawable.bitsPerPixel, pixmap->drawable.bitsPerPixel,
boxes[j].x1 - x, boxes[j].y1 - y, boxes[j].x1, boxes[j].y1,
boxes[j].x2 - boxes[j].x1, boxes[j].x2 - boxes[j].x1,
boxes[j].y2 - boxes[j].y1); boxes[j].y2 - boxes[j].y1);
} }
DEBUGF("upload x %d y %d w %d h %d temp stride %d \n", DEBUGF("upload x %d y %d w %d h %d temp stride %d \n",
boxes[j].x1 - x, boxes[j].y1 - y, boxes[j].x1, boxes[j].y1,
boxes[j].x2 - boxes[j].x1, boxes[j].x2 - boxes[j].x1,
boxes[j].y2 - boxes[j].y1, temp_stride); boxes[j].y2 - boxes[j].y1, temp_stride);
if (_glamor_upload_bits_to_pixmap_texture if (_glamor_upload_bits_to_pixmap_texture
(pixmap, format, type, no_alpha, revert, swap_rb, (pixmap, format, type, no_alpha, revert, swap_rb,
boxes[j].x1, boxes[j].y1, boxes[j].x2 - boxes[j].x1, boxes[j].x1, boxes[j].y1, boxes[j].x2 - boxes[j].x1,
boxes[j].y2 - boxes[j].y1, temp_stride, temp_bits, boxes[j].y2 - boxes[j].y1, temp_stride, temp_bits,
pbo) == FALSE) { 0) == FALSE) {
RegionUninit(&region); RegionUninit(&region);
free(sub_bits); free(sub_bits);
assert(0); assert(0);
@ -907,28 +908,9 @@ glamor_upload_sub_pixmap_to_texture(PixmapPtr pixmap, int x, int y, int w,
else else
return _glamor_upload_bits_to_pixmap_texture(pixmap, format, type, return _glamor_upload_bits_to_pixmap_texture(pixmap, format, type,
no_alpha, revert, swap_rb, no_alpha, revert, swap_rb,
x, y, w, h, stride, bits, 0, 0,
pbo); pixmap->drawable.width,
} pixmap->drawable.height,
stride, bits,
/* Upload picture to texture. We may need to flip the y axis or 0);
* wire alpha to 1. So we may conditional create fbo for the picture.
* */
enum glamor_pixmap_status
glamor_upload_picture_to_texture(PicturePtr picture)
{
PixmapPtr pixmap;
assert(picture->pDrawable);
pixmap = glamor_get_drawable_pixmap(picture->pDrawable);
if (glamor_upload_sub_pixmap_to_texture(pixmap, 0, 0,
pixmap->drawable.width,
pixmap->drawable.height,
pixmap->devKind,
pixmap->devPrivate.ptr, 0,
picture->format))
return GLAMOR_UPLOAD_DONE;
else
return GLAMOR_UPLOAD_FAILED;
} }

View File

@ -514,22 +514,6 @@ glamor_pixmap_hcnt(glamor_pixmap_private *priv)
for (box_index = 0; box_index < glamor_pixmap_hcnt(priv) * \ for (box_index = 0; box_index < glamor_pixmap_hcnt(priv) * \
glamor_pixmap_wcnt(priv); box_index++) \ glamor_pixmap_wcnt(priv); box_index++) \
/**
* Pixmap upload status, used by glamor_render.c's support for
* temporarily uploading pixmaps to GL textures to get a Composite
* operation done.
*/
typedef enum glamor_pixmap_status {
/** initial status, don't need to do anything. */
GLAMOR_NONE,
/** marked as need to be uploaded to gl texture. */
GLAMOR_UPLOAD_PENDING,
/** the pixmap has been uploaded successfully. */
GLAMOR_UPLOAD_DONE,
/** fail to upload the pixmap. */
GLAMOR_UPLOAD_FAILED
} glamor_pixmap_status_t;
/* GC private structure. Currently holds only any computed dash pixmap */ /* GC private structure. Currently holds only any computed dash pixmap */
typedef struct { typedef struct {
@ -739,7 +723,7 @@ Bool glamor_composite_largepixmap_region(CARD8 op,
* Upload a picture to gl texture. Similar to the * Upload a picture to gl texture. Similar to the
* glamor_upload_pixmap_to_texture. Used in rendering. * glamor_upload_pixmap_to_texture. Used in rendering.
**/ **/
enum glamor_pixmap_status glamor_upload_picture_to_texture(PicturePtr picture); Bool glamor_upload_picture_to_texture(PicturePtr picture);
void glamor_add_traps(PicturePtr pPicture, void glamor_add_traps(PicturePtr pPicture,
INT16 x_off, INT16 y_off, int ntrap, xTrap *traps); INT16 x_off, INT16 y_off, int ntrap, xTrap *traps);

View File

@ -788,8 +788,8 @@ glamor_composite_choose_shader(CARD8 op,
{ {
ScreenPtr screen = dest->pDrawable->pScreen; ScreenPtr screen = dest->pDrawable->pScreen;
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen); glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
enum glamor_pixmap_status source_status = GLAMOR_NONE; Bool source_needs_upload = FALSE;
enum glamor_pixmap_status mask_status = GLAMOR_NONE; Bool mask_needs_upload = FALSE;
PictFormatShort saved_source_format = 0; PictFormatShort saved_source_format = 0;
struct shader_key key; struct shader_key key;
GLfloat source_solid_color[4]; GLfloat source_solid_color[4];
@ -900,7 +900,7 @@ glamor_composite_choose_shader(CARD8 op,
} }
if (source_pixmap_priv->gl_fbo == GLAMOR_FBO_UNATTACHED) { if (source_pixmap_priv->gl_fbo == GLAMOR_FBO_UNATTACHED) {
#ifdef GLAMOR_PIXMAP_DYNAMIC_UPLOAD #ifdef GLAMOR_PIXMAP_DYNAMIC_UPLOAD
source_status = GLAMOR_UPLOAD_PENDING; source_needs_upload = TRUE;
#else #else
glamor_fallback("no texture in source\n"); glamor_fallback("no texture in source\n");
goto fail; goto fail;
@ -916,7 +916,7 @@ glamor_composite_choose_shader(CARD8 op,
} }
if (mask_pixmap_priv->gl_fbo == GLAMOR_FBO_UNATTACHED) { if (mask_pixmap_priv->gl_fbo == GLAMOR_FBO_UNATTACHED) {
#ifdef GLAMOR_PIXMAP_DYNAMIC_UPLOAD #ifdef GLAMOR_PIXMAP_DYNAMIC_UPLOAD
mask_status = GLAMOR_UPLOAD_PENDING; mask_needs_upload = TRUE;
#else #else
glamor_fallback("no texture in mask\n"); glamor_fallback("no texture in mask\n");
goto fail; goto fail;
@ -925,8 +925,7 @@ glamor_composite_choose_shader(CARD8 op,
} }
#ifdef GLAMOR_PIXMAP_DYNAMIC_UPLOAD #ifdef GLAMOR_PIXMAP_DYNAMIC_UPLOAD
if (source_status == GLAMOR_UPLOAD_PENDING if (source_needs_upload && mask_needs_upload
&& mask_status == GLAMOR_UPLOAD_PENDING
&& source_pixmap == mask_pixmap) { && source_pixmap == mask_pixmap) {
if (source->format != mask->format) { if (source->format != mask->format) {
@ -962,20 +961,17 @@ glamor_composite_choose_shader(CARD8 op,
if (!PICT_FORMAT_A(mask->format) if (!PICT_FORMAT_A(mask->format)
&& PICT_FORMAT_A(saved_source_format)) && PICT_FORMAT_A(saved_source_format))
key.mask = SHADER_MASK_TEXTURE; key.mask = SHADER_MASK_TEXTURE;
mask_status = GLAMOR_NONE;
} }
source_status = glamor_upload_picture_to_texture(source); if (!glamor_upload_picture_to_texture(source)) {
if (source_status != GLAMOR_UPLOAD_DONE) {
glamor_fallback("Failed to upload source texture.\n"); glamor_fallback("Failed to upload source texture.\n");
goto fail; goto fail;
} }
mask_needs_upload = FALSE;
} }
else { else {
if (source_status == GLAMOR_UPLOAD_PENDING) { if (source_needs_upload) {
source_status = glamor_upload_picture_to_texture(source); if (!glamor_upload_picture_to_texture(source)) {
if (source_status != GLAMOR_UPLOAD_DONE) {
glamor_fallback("Failed to upload source texture.\n"); glamor_fallback("Failed to upload source texture.\n");
goto fail; goto fail;
} }
@ -986,9 +982,8 @@ glamor_composite_choose_shader(CARD8 op,
} }
} }
if (mask_status == GLAMOR_UPLOAD_PENDING) { if (mask_needs_upload) {
mask_status = glamor_upload_picture_to_texture(mask); if (!glamor_upload_picture_to_texture(mask)) {
if (mask_status != GLAMOR_UPLOAD_DONE) {
glamor_fallback("Failed to upload mask texture.\n"); glamor_fallback("Failed to upload mask texture.\n");
goto fail; goto fail;
} }