Commit c94da112 authored by Eric Anholt's avatar Eric Anholt Committed by Adam Jackson

glamor: Plumb the pixmap through fbo creation instead of a "format"

For GLES, we're going to need a lot more logic for picking the
iformat/format/type of texture setup, so we'll want the pixmap's depth
and is_cbcr flag.
Signed-off-by: Eric Anholt's avatarEric Anholt <eric@anholt.net>
parent 34485be2
...@@ -106,7 +106,6 @@ glamor_set_pixmap_texture(PixmapPtr pixmap, unsigned int tex) ...@@ -106,7 +106,6 @@ glamor_set_pixmap_texture(PixmapPtr pixmap, unsigned int tex)
glamor_pixmap_private *pixmap_priv; glamor_pixmap_private *pixmap_priv;
glamor_screen_private *glamor_priv; glamor_screen_private *glamor_priv;
glamor_pixmap_fbo *fbo; glamor_pixmap_fbo *fbo;
GLenum format;
glamor_priv = glamor_get_screen_private(screen); glamor_priv = glamor_get_screen_private(screen);
pixmap_priv = glamor_get_pixmap_private(pixmap); pixmap_priv = glamor_get_pixmap_private(pixmap);
...@@ -116,9 +115,9 @@ glamor_set_pixmap_texture(PixmapPtr pixmap, unsigned int tex) ...@@ -116,9 +115,9 @@ glamor_set_pixmap_texture(PixmapPtr pixmap, unsigned int tex)
glamor_destroy_fbo(glamor_priv, fbo); glamor_destroy_fbo(glamor_priv, fbo);
} }
format = gl_iformat_for_pixmap(pixmap); fbo = glamor_create_fbo_from_tex(glamor_priv, pixmap,
fbo = glamor_create_fbo_from_tex(glamor_priv, pixmap->drawable.width, pixmap->drawable.width,
pixmap->drawable.height, format, tex, 0); pixmap->drawable.height, tex, 0);
if (fbo == NULL) { if (fbo == NULL) {
ErrorF("XXX fail to create fbo.\n"); ErrorF("XXX fail to create fbo.\n");
...@@ -189,7 +188,6 @@ glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth, ...@@ -189,7 +188,6 @@ glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth,
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen); glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
glamor_pixmap_fbo *fbo = NULL; glamor_pixmap_fbo *fbo = NULL;
int pitch; int pitch;
GLenum format;
if (w > 32767 || h > 32767) if (w > 32767 || h > 32767)
return NullPixmap; return NullPixmap;
...@@ -208,8 +206,6 @@ glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth, ...@@ -208,8 +206,6 @@ glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth,
pixmap_priv->is_cbcr = (usage == GLAMOR_CREATE_FORMAT_CBCR); pixmap_priv->is_cbcr = (usage == GLAMOR_CREATE_FORMAT_CBCR);
format = gl_iformat_for_pixmap(pixmap);
pitch = (((w * pixmap->drawable.bitsPerPixel + 7) / 8) + 3) & ~3; pitch = (((w * pixmap->drawable.bitsPerPixel + 7) / 8) + 3) & ~3;
screen->ModifyPixmapHeader(pixmap, w, h, 0, 0, pitch, NULL); screen->ModifyPixmapHeader(pixmap, w, h, 0, 0, pitch, NULL);
...@@ -223,12 +219,12 @@ glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth, ...@@ -223,12 +219,12 @@ glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth,
glamor_check_fbo_size(glamor_priv, w, h)) glamor_check_fbo_size(glamor_priv, w, h))
{ {
glamor_init_pixmap_private_small(pixmap, pixmap_priv); glamor_init_pixmap_private_small(pixmap, pixmap_priv);
fbo = glamor_create_fbo(glamor_priv, w, h, format, usage); fbo = glamor_create_fbo(glamor_priv, pixmap, w, h, usage);
} else { } else {
int tile_size = glamor_priv->max_fbo_size; int tile_size = glamor_priv->max_fbo_size;
DEBUGF("Create LARGE pixmap %p width %d height %d, tile size %d\n", DEBUGF("Create LARGE pixmap %p width %d height %d, tile size %d\n",
pixmap, w, h, tile_size); pixmap, w, h, tile_size);
fbo = glamor_create_fbo_array(glamor_priv, w, h, format, usage, fbo = glamor_create_fbo_array(glamor_priv, pixmap, usage,
tile_size, tile_size, pixmap_priv); tile_size, tile_size, pixmap_priv);
} }
...@@ -842,8 +838,7 @@ _glamor_fds_from_pixmap(ScreenPtr screen, PixmapPtr pixmap, int *fds, ...@@ -842,8 +838,7 @@ _glamor_fds_from_pixmap(ScreenPtr screen, PixmapPtr pixmap, int *fds,
switch (pixmap_priv->type) { switch (pixmap_priv->type) {
case GLAMOR_TEXTURE_DRM: case GLAMOR_TEXTURE_DRM:
case GLAMOR_TEXTURE_ONLY: case GLAMOR_TEXTURE_ONLY:
if (!glamor_pixmap_ensure_fbo(pixmap, pixmap->drawable.depth == 30 ? if (!glamor_pixmap_ensure_fbo(pixmap, 0))
GL_RGB10_A2 : GL_RGBA, 0))
return 0; return 0;
if (modifier) { if (modifier) {
...@@ -919,8 +914,7 @@ glamor_name_from_pixmap(PixmapPtr pixmap, CARD16 *stride, CARD32 *size) ...@@ -919,8 +914,7 @@ glamor_name_from_pixmap(PixmapPtr pixmap, CARD16 *stride, CARD32 *size)
switch (pixmap_priv->type) { switch (pixmap_priv->type) {
case GLAMOR_TEXTURE_DRM: case GLAMOR_TEXTURE_DRM:
case GLAMOR_TEXTURE_ONLY: case GLAMOR_TEXTURE_ONLY:
if (!glamor_pixmap_ensure_fbo(pixmap, pixmap->drawable.depth == 30 ? if (!glamor_pixmap_ensure_fbo(pixmap, 0))
GL_RGB10_A2 : GL_RGBA, 0))
return -1; return -1;
return glamor_egl_fd_name_from_pixmap(pixmap->drawable.pScreen, return glamor_egl_fd_name_from_pixmap(pixmap->drawable.pScreen,
pixmap, stride, size); pixmap, stride, size);
......
...@@ -95,8 +95,9 @@ glamor_pixmap_ensure_fb(glamor_screen_private *glamor_priv, ...@@ -95,8 +95,9 @@ glamor_pixmap_ensure_fb(glamor_screen_private *glamor_priv,
glamor_pixmap_fbo * glamor_pixmap_fbo *
glamor_create_fbo_from_tex(glamor_screen_private *glamor_priv, glamor_create_fbo_from_tex(glamor_screen_private *glamor_priv,
int w, int h, Bool is_red, GLint tex, int flag) PixmapPtr pixmap, int w, int h, GLint tex, int flag)
{ {
GLenum format = gl_iformat_for_pixmap(pixmap);
glamor_pixmap_fbo *fbo; glamor_pixmap_fbo *fbo;
fbo = calloc(1, sizeof(*fbo)); fbo = calloc(1, sizeof(*fbo));
...@@ -106,7 +107,7 @@ glamor_create_fbo_from_tex(glamor_screen_private *glamor_priv, ...@@ -106,7 +107,7 @@ glamor_create_fbo_from_tex(glamor_screen_private *glamor_priv,
fbo->tex = tex; fbo->tex = tex;
fbo->width = w; fbo->width = w;
fbo->height = h; fbo->height = h;
fbo->is_red = is_red; fbo->is_red = format == GL_RED;
if (flag != GLAMOR_CREATE_FBO_NO_FBO) { if (flag != GLAMOR_CREATE_FBO_NO_FBO) {
if (glamor_pixmap_ensure_fb(glamor_priv, fbo) != 0) { if (glamor_pixmap_ensure_fb(glamor_priv, fbo) != 0) {
...@@ -120,13 +121,15 @@ glamor_create_fbo_from_tex(glamor_screen_private *glamor_priv, ...@@ -120,13 +121,15 @@ glamor_create_fbo_from_tex(glamor_screen_private *glamor_priv,
static int static int
_glamor_create_tex(glamor_screen_private *glamor_priv, _glamor_create_tex(glamor_screen_private *glamor_priv,
int w, int h, GLenum format) PixmapPtr pixmap, int w, int h)
{ {
GLenum iformat = gl_iformat_for_pixmap(pixmap);
GLenum format = iformat;
unsigned int tex; unsigned int tex;
GLenum iformat = format;
if (format == GL_RGB10_A2) if (format == GL_RGB10_A2)
format = GL_RGBA; format = GL_RGBA;
glamor_make_current(glamor_priv); glamor_make_current(glamor_priv);
glGenTextures(1, &tex); glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex); glBindTexture(GL_TEXTURE_2D, tex);
...@@ -156,14 +159,14 @@ _glamor_create_tex(glamor_screen_private *glamor_priv, ...@@ -156,14 +159,14 @@ _glamor_create_tex(glamor_screen_private *glamor_priv,
glamor_pixmap_fbo * glamor_pixmap_fbo *
glamor_create_fbo(glamor_screen_private *glamor_priv, glamor_create_fbo(glamor_screen_private *glamor_priv,
int w, int h, GLenum format, int flag) PixmapPtr pixmap, int w, int h, int flag)
{ {
GLint tex = _glamor_create_tex(glamor_priv, w, h, format); GLint tex = _glamor_create_tex(glamor_priv, pixmap, w, h);
if (!tex) /* Texture creation failed due to GL_OUT_OF_MEMORY */ if (!tex) /* Texture creation failed due to GL_OUT_OF_MEMORY */
return NULL; return NULL;
return glamor_create_fbo_from_tex(glamor_priv, w, h, format == GL_RED, return glamor_create_fbo_from_tex(glamor_priv, pixmap, w, h,
tex, flag); tex, flag);
} }
...@@ -173,10 +176,12 @@ glamor_create_fbo(glamor_screen_private *glamor_priv, ...@@ -173,10 +176,12 @@ glamor_create_fbo(glamor_screen_private *glamor_priv,
*/ */
glamor_pixmap_fbo * glamor_pixmap_fbo *
glamor_create_fbo_array(glamor_screen_private *glamor_priv, glamor_create_fbo_array(glamor_screen_private *glamor_priv,
int w, int h, GLenum format, int flag, PixmapPtr pixmap, int flag,
int block_w, int block_h, int block_w, int block_h,
glamor_pixmap_private *priv) glamor_pixmap_private *priv)
{ {
int w = pixmap->drawable.width;
int h = pixmap->drawable.height;
int block_wcnt; int block_wcnt;
int block_hcnt; int block_hcnt;
glamor_pixmap_fbo **fbo_array; glamor_pixmap_fbo **fbo_array;
...@@ -216,8 +221,8 @@ glamor_create_fbo_array(glamor_screen_private *glamor_priv, ...@@ -216,8 +221,8 @@ glamor_create_fbo_array(glamor_screen_private *glamor_priv,
box_array[i * block_wcnt + j].x2 - box_array[i * block_wcnt + box_array[i * block_wcnt + j].x2 - box_array[i * block_wcnt +
j].x1; j].x1;
fbo_array[i * block_wcnt + j] = glamor_create_fbo(glamor_priv, fbo_array[i * block_wcnt + j] = glamor_create_fbo(glamor_priv,
pixmap,
fbo_w, fbo_h, fbo_w, fbo_h,
format,
GLAMOR_CREATE_PIXMAP_FIXUP); GLAMOR_CREATE_PIXMAP_FIXUP);
if (fbo_array[i * block_wcnt + j] == NULL) if (fbo_array[i * block_wcnt + j] == NULL)
goto cleanup; goto cleanup;
...@@ -303,7 +308,7 @@ glamor_pixmap_destroy_fbo(PixmapPtr pixmap) ...@@ -303,7 +308,7 @@ glamor_pixmap_destroy_fbo(PixmapPtr pixmap)
} }
Bool Bool
glamor_pixmap_ensure_fbo(PixmapPtr pixmap, GLenum format, int flag) glamor_pixmap_ensure_fbo(PixmapPtr pixmap, int flag)
{ {
glamor_screen_private *glamor_priv; glamor_screen_private *glamor_priv;
glamor_pixmap_private *pixmap_priv; glamor_pixmap_private *pixmap_priv;
...@@ -313,8 +318,8 @@ glamor_pixmap_ensure_fbo(PixmapPtr pixmap, GLenum format, int flag) ...@@ -313,8 +318,8 @@ glamor_pixmap_ensure_fbo(PixmapPtr pixmap, GLenum format, int flag)
pixmap_priv = glamor_get_pixmap_private(pixmap); pixmap_priv = glamor_get_pixmap_private(pixmap);
if (pixmap_priv->fbo == NULL) { if (pixmap_priv->fbo == NULL) {
fbo = glamor_create_fbo(glamor_priv, pixmap->drawable.width, fbo = glamor_create_fbo(glamor_priv, pixmap, pixmap->drawable.width,
pixmap->drawable.height, format, flag); pixmap->drawable.height, flag);
if (fbo == NULL) if (fbo == NULL)
return FALSE; return FALSE;
...@@ -324,8 +329,8 @@ glamor_pixmap_ensure_fbo(PixmapPtr pixmap, GLenum format, int flag) ...@@ -324,8 +329,8 @@ glamor_pixmap_ensure_fbo(PixmapPtr pixmap, GLenum format, int flag)
/* We do have a fbo, but it may lack of fb or tex. */ /* We do have a fbo, but it may lack of fb or tex. */
if (!pixmap_priv->fbo->tex) if (!pixmap_priv->fbo->tex)
pixmap_priv->fbo->tex = pixmap_priv->fbo->tex =
_glamor_create_tex(glamor_priv, pixmap->drawable.width, _glamor_create_tex(glamor_priv, pixmap, pixmap->drawable.width,
pixmap->drawable.height, format); pixmap->drawable.height);
if (flag != GLAMOR_CREATE_FBO_NO_FBO && pixmap_priv->fbo->fb == 0) if (flag != GLAMOR_CREATE_FBO_NO_FBO && pixmap_priv->fbo->fb == 0)
if (glamor_pixmap_ensure_fb(glamor_priv, pixmap_priv->fbo) != 0) if (glamor_pixmap_ensure_fb(glamor_priv, pixmap_priv->fbo) != 0)
......
...@@ -340,7 +340,7 @@ glamor_upload_picture_to_texture(PicturePtr picture) ...@@ -340,7 +340,7 @@ glamor_upload_picture_to_texture(PicturePtr picture)
else else
iformat = format; iformat = format;
if (!glamor_pixmap_ensure_fbo(pixmap, iformat, GLAMOR_CREATE_FBO_NO_FBO)) { if (!glamor_pixmap_ensure_fbo(pixmap, GLAMOR_CREATE_FBO_NO_FBO)) {
ret = FALSE; ret = FALSE;
goto fail; goto fail;
} }
......
...@@ -525,11 +525,11 @@ glamor_pixmap_fbo *glamor_pixmap_detach_fbo(glamor_pixmap_private * ...@@ -525,11 +525,11 @@ glamor_pixmap_fbo *glamor_pixmap_detach_fbo(glamor_pixmap_private *
pixmap_priv); pixmap_priv);
void glamor_pixmap_attach_fbo(PixmapPtr pixmap, glamor_pixmap_fbo *fbo); void glamor_pixmap_attach_fbo(PixmapPtr pixmap, glamor_pixmap_fbo *fbo);
glamor_pixmap_fbo *glamor_create_fbo_from_tex(glamor_screen_private * glamor_pixmap_fbo *glamor_create_fbo_from_tex(glamor_screen_private *
glamor_priv, int w, int h, glamor_priv, PixmapPtr pixmap,
Bool is_red, GLint tex, int w, int h, GLint tex,
int flag); int flag);
glamor_pixmap_fbo *glamor_create_fbo(glamor_screen_private *glamor_priv, int w, glamor_pixmap_fbo *glamor_create_fbo(glamor_screen_private *glamor_priv,
int h, GLenum format, int flag); PixmapPtr pixmap, int w, int h, int flag);
void glamor_destroy_fbo(glamor_screen_private *glamor_priv, void glamor_destroy_fbo(glamor_screen_private *glamor_priv,
glamor_pixmap_fbo *fbo); glamor_pixmap_fbo *fbo);
void glamor_pixmap_destroy_fbo(PixmapPtr pixmap); void glamor_pixmap_destroy_fbo(PixmapPtr pixmap);
...@@ -556,7 +556,7 @@ void glamor_bind_texture(glamor_screen_private *glamor_priv, ...@@ -556,7 +556,7 @@ void glamor_bind_texture(glamor_screen_private *glamor_priv,
Bool destination_red); Bool destination_red);
glamor_pixmap_fbo *glamor_create_fbo_array(glamor_screen_private *glamor_priv, glamor_pixmap_fbo *glamor_create_fbo_array(glamor_screen_private *glamor_priv,
int w, int h, GLenum format, PixmapPtr pixmap,
int flag, int block_w, int block_h, int flag, int block_w, int block_h,
glamor_pixmap_private *); glamor_pixmap_private *);
...@@ -666,7 +666,7 @@ glamor_put_vbo_space(ScreenPtr screen); ...@@ -666,7 +666,7 @@ glamor_put_vbo_space(ScreenPtr screen);
* the fbo has valid texture and attach to a valid fb. * the fbo has valid texture and attach to a valid fb.
* If the fbo already has a valid glfbo then do nothing. * If the fbo already has a valid glfbo then do nothing.
*/ */
Bool glamor_pixmap_ensure_fbo(PixmapPtr pixmap, GLenum format, int flag); Bool glamor_pixmap_ensure_fbo(PixmapPtr pixmap, int flag);
glamor_pixmap_clipped_regions * glamor_pixmap_clipped_regions *
glamor_compute_clipped_regions(PixmapPtr pixmap, glamor_compute_clipped_regions(PixmapPtr pixmap,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment