diff options
author | Zhigang Gong <zhigang.gong@linux.intel.com> | 2012-04-25 11:56:43 +0800 |
---|---|---|
committer | Zhigang Gong <zhigang.gong@linux.intel.com> | 2012-04-27 15:53:37 +0800 |
commit | bc7bfc7d94a51b6fe2953c42c117d1c5258423ca (patch) | |
tree | a211e869abdab92440e55154829e77b44d9f5500 | |
parent | aa64c82102ed094ca1b1662d4a93b2359584b9ec (diff) |
Fixed one potential texture size mismatch problem.
There are two cases which we may use a wrong texture size.
1. A pixmap is modified by the client side after it created
it. Then the pixmap's width may mismatch the original fbo/tex's
size. Thus we need to check this condition when preparing
upload the pixmap.
2. We provide two API to download/upload sub region of a
textured pixmap. The caller may pass in a larger width then
the original pixmap's size, this may happen at putimage
and setspans. We need to validate the width and height
when do the downloading/uploading.
Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
-rw-r--r-- | src/glamor_pixmap.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/glamor_pixmap.c b/src/glamor_pixmap.c index c2b196f..6f66fb4 100644 --- a/src/glamor_pixmap.c +++ b/src/glamor_pixmap.c @@ -559,7 +559,14 @@ glamor_pixmap_upload_prepare(PixmapPtr pixmap, GLenum format, int no_alpha, int pixmap_priv = glamor_get_pixmap_private(pixmap); glamor_priv = glamor_get_screen_private(pixmap->drawable.pScreen); - if (pixmap_priv && pixmap_priv->fbo && pixmap_priv->fbo->fb) + if (pixmap_priv->fbo + && (pixmap_priv->fbo->width < pixmap->drawable.width + || pixmap_priv->fbo->height < pixmap->drawable.height)) { + fbo = glamor_pixmap_detach_fbo(pixmap_priv); + glamor_destroy_fbo(fbo); + } + + if (pixmap_priv->fbo && pixmap_priv->fbo->fb) return 0; if (!(no_alpha @@ -1085,6 +1092,9 @@ glamor_get_sub_pixmap(PixmapPtr pixmap, int x, int y, int w, int h, glamor_acces int pbo; int flag; + assert(x >= 0 && y >= 0); + w = (x + w) > pixmap->drawable.width ? (pixmap->drawable.width - x) : w; + h = (y + h) > pixmap->drawable.height ? (pixmap->drawable.height - y) : h; if (access == GLAMOR_ACCESS_WO) { sub_pixmap = glamor_create_pixmap(pixmap->drawable.pScreen, w, h, pixmap->drawable.depth, GLAMOR_CREATE_PIXMAP_CPU); @@ -1167,6 +1177,10 @@ glamor_put_sub_pixmap(PixmapPtr sub_pixmap, PixmapPtr pixmap, int x, int y, int bits = sub_pixmap->devPrivate.ptr; pbo = 0; } + + assert(x >= 0 && y >= 0); + w = (w > sub_pixmap->drawable.width) ? sub_pixmap->drawable.width : w; + h = (h > sub_pixmap->drawable.height) ? sub_pixmap->drawable.height : h; glamor_upload_sub_pixmap_to_texture(pixmap, x, y, w, h, sub_pixmap->devKind, bits, pbo); } glamor_destroy_pixmap(sub_pixmap); |