summaryrefslogtreecommitdiff
path: root/src/mesa/state_tracker/st_cb_drawpixels.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/state_tracker/st_cb_drawpixels.c')
-rw-r--r--src/mesa/state_tracker/st_cb_drawpixels.c307
1 files changed, 106 insertions, 201 deletions
diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c
index df41d5ce5b..c0e41dbeec 100644
--- a/src/mesa/state_tracker/st_cb_drawpixels.c
+++ b/src/mesa/state_tracker/st_cb_drawpixels.c
@@ -33,6 +33,7 @@
#include "main/imports.h"
#include "main/image.h"
#include "main/macros.h"
+#include "main/texformat.h"
#include "shader/program.h"
#include "shader/prog_parameter.h"
#include "shader/prog_print.h"
@@ -50,6 +51,7 @@
#include "st_draw.h"
#include "st_format.h"
#include "st_mesa_to_tgsi.h"
+#include "st_texture.h"
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/p_inlines.h"
@@ -440,65 +442,22 @@ _mesa_base_format(GLenum format)
}
-
-static struct pipe_mipmap_tree *
-alloc_mipmap_tree(struct st_context *st,
- GLsizei width, GLsizei height, uint pipeFormat)
-{
- const GLbitfield flags = PIPE_SURFACE_FLAG_TEXTURE;
- struct pipe_mipmap_tree *mt;
- GLuint cpp;
-
- mt = CALLOC_STRUCT(pipe_mipmap_tree);
- if (!mt)
- return NULL;
-
- cpp = st_sizeof_format(pipeFormat);
-
- /* allocate texture region/storage */
- mt->region = st->pipe->winsys->region_alloc(st->pipe->winsys,
- cpp, width, height, flags);
-
- mt->target = PIPE_TEXTURE_2D;
- mt->internal_format = GL_RGBA;
- mt->format = pipeFormat;
- mt->first_level = 0;
- mt->last_level = 0;
- mt->width0 = width;
- mt->height0 = height;
- mt->depth0 = 1;
- mt->cpp = cpp;
- mt->compressed = 0;
- mt->pitch = mt->region->pitch;
- mt->depth_pitch = 0;
- mt->total_height = height;
- mt->level[0].level_offset = 0;
- mt->level[0].width = width;
- mt->level[0].height = height;
- mt->level[0].depth = 1;
- mt->level[0].nr_images = 1;
- mt->level[0].image_offset = NULL;
- mt->refcount = 1;
-
- return mt;
-}
-
-
/**
- * Make mipmap tree containing an image for glDrawPixels image.
+ * Make texture containing an image for glDrawPixels image.
* If 'pixels' is NULL, leave the texture image data undefined.
*/
-static struct pipe_mipmap_tree *
-make_mipmap_tree(struct st_context *st,
- GLsizei width, GLsizei height, GLenum format, GLenum type,
- const struct gl_pixelstore_attrib *unpack,
- const GLvoid *pixels)
+static struct pipe_texture *
+make_texture(struct st_context *st,
+ GLsizei width, GLsizei height, GLenum format, GLenum type,
+ const struct gl_pixelstore_attrib *unpack,
+ const GLvoid *pixels)
{
GLcontext *ctx = st->ctx;
struct pipe_context *pipe = st->pipe;
const struct gl_texture_format *mformat;
- struct pipe_mipmap_tree *mt;
- GLuint pipeFormat, cpp;
+ struct pipe_texture *pt;
+ enum pipe_format pipeFormat;
+ GLuint cpp;
GLenum baseFormat;
baseFormat = _mesa_base_format(format);
@@ -510,31 +469,34 @@ make_mipmap_tree(struct st_context *st,
assert(pipeFormat);
cpp = st_sizeof_format(pipeFormat);
- mt = alloc_mipmap_tree(st, width, height, pipeFormat);
- if (!mt)
+ pt = st_texture_create(st, PIPE_TEXTURE_2D, pipeFormat, baseFormat, 0, 0,
+ width, height, 1, 0);
+ if (!pt)
return NULL;
if (unpack->BufferObj && unpack->BufferObj->Name) {
/*
- mt->region = buffer_object_region(unpack->BufferObj);
+ pt->region = buffer_object_region(unpack->BufferObj);
*/
printf("st_DrawPixels (sourcing from PBO not implemented yet)\n");
}
{
+ struct pipe_surface *surface;
static const GLuint dstImageOffsets = 0;
GLboolean success;
- GLuint pitch = mt->region->pitch;
GLubyte *dest;
const GLbitfield imageTransferStateSave = ctx->_ImageTransferState;
/* we'll do pixel transfer in a fragment shader */
ctx->_ImageTransferState = 0x0;
- /* map texture region */
- dest = pipe->region_map(pipe, mt->region);
+ surface = pipe->get_tex_surface(pipe, pt, 0, 0, 0);
- /* Put image into texture region.
+ /* map texture surface */
+ dest = pipe_surface_map(surface);
+
+ /* Put image into texture surface.
* Note that the image is actually going to be upside down in
* the texture. We deal with that with texcoords.
*/
@@ -543,7 +505,7 @@ make_mipmap_tree(struct st_context *st,
mformat, /* gl_texture_format */
dest, /* dest */
0, 0, 0, /* dstX/Y/Zoffset */
- pitch * cpp, /* dstRowStride, bytes */
+ surface->pitch * cpp, /* dstRowStride, bytes */
&dstImageOffsets, /* dstImageOffsets */
width, height, 1, /* size */
format, type, /* src format/type */
@@ -551,44 +513,15 @@ make_mipmap_tree(struct st_context *st,
unpack);
/* unmap */
- pipe->region_unmap(pipe, mt->region);
+ pipe_surface_unmap(surface);
+ pipe_surface_reference(&surface, NULL);
assert(success);
/* restore */
ctx->_ImageTransferState = imageTransferStateSave;
}
-#if 0
- mt->target = PIPE_TEXTURE_2D;
- mt->internal_format = GL_RGBA;
- mt->format = pipeFormat;
- mt->first_level = 0;
- mt->last_level = 0;
- mt->width0 = width;
- mt->height0 = height;
- mt->depth0 = 1;
- mt->cpp = cpp;
- mt->compressed = 0;
- mt->pitch = mt->region->pitch;
- mt->depth_pitch = 0;
- mt->total_height = height;
- mt->level[0].level_offset = 0;
- mt->level[0].width = width;
- mt->level[0].height = height;
- mt->level[0].depth = 1;
- mt->level[0].nr_images = 1;
- mt->level[0].image_offset = NULL;
- mt->refcount = 1;
-#endif
- return mt;
-}
-
-
-static void
-free_mipmap_tree(struct pipe_context *pipe, struct pipe_mipmap_tree *mt)
-{
- pipe->winsys->region_release(pipe->winsys, &mt->region);
- free(mt);
+ return pt;
}
@@ -694,7 +627,7 @@ static void
draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
GLsizei width, GLsizei height,
GLfloat zoomX, GLfloat zoomY,
- struct pipe_mipmap_tree *mt,
+ struct pipe_texture *pt,
struct st_vertex_program *stvp,
struct st_fragment_program *stfp,
const GLfloat *color,
@@ -762,9 +695,9 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
pipe->set_viewport_state(pipe, &vp);
}
- /* mipmap tree state: */
+ /* texture state: */
{
- pipe->set_texture_state(pipe, unit, mt);
+ pipe->set_texture_state(pipe, unit, pt);
}
/* Compute window coords (y=0=bottom) with pixel zoom.
@@ -797,47 +730,47 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
* XXX probably move this to a re-usable place.
*/
static GLboolean
-compatible_formats(GLenum format, GLenum type, GLuint pipeFormat)
+compatible_formats(GLenum format, GLenum type, enum pipe_format pipeFormat)
{
static const GLuint one = 1;
GLubyte littleEndian = *((GLubyte *) &one);
- if (pipeFormat == PIPE_FORMAT_U_R8_G8_B8_A8 &&
+ if (pipeFormat == PIPE_FORMAT_R8G8B8A8_UNORM &&
format == GL_RGBA &&
type == GL_UNSIGNED_BYTE &&
!littleEndian) {
return GL_TRUE;
}
- else if (pipeFormat == PIPE_FORMAT_U_R8_G8_B8_A8 &&
+ else if (pipeFormat == PIPE_FORMAT_R8G8B8A8_UNORM &&
format == GL_ABGR_EXT &&
type == GL_UNSIGNED_BYTE &&
littleEndian) {
return GL_TRUE;
}
- else if (pipeFormat == PIPE_FORMAT_U_A8_R8_G8_B8 &&
+ else if (pipeFormat == PIPE_FORMAT_A8R8G8B8_UNORM &&
format == GL_BGRA &&
type == GL_UNSIGNED_BYTE &&
littleEndian) {
return GL_TRUE;
}
- else if (pipeFormat == PIPE_FORMAT_U_R5_G6_B5 &&
+ else if (pipeFormat == PIPE_FORMAT_R5G6B5_UNORM &&
format == GL_RGB &&
type == GL_UNSIGNED_SHORT_5_6_5) {
/* endian don't care */
return GL_TRUE;
}
- else if (pipeFormat == PIPE_FORMAT_U_R5_G6_B5 &&
+ else if (pipeFormat == PIPE_FORMAT_R5G6B5_UNORM &&
format == GL_BGR &&
type == GL_UNSIGNED_SHORT_5_6_5_REV) {
/* endian don't care */
return GL_TRUE;
}
- else if (pipeFormat == PIPE_FORMAT_U_S8 &&
+ else if (pipeFormat == PIPE_FORMAT_S8_UNORM &&
format == GL_STENCIL_INDEX &&
type == GL_UNSIGNED_BYTE) {
return GL_TRUE;
}
- else if (pipeFormat == PIPE_FORMAT_U_Z32 &&
+ else if (pipeFormat == PIPE_FORMAT_Z32_UNORM &&
format == GL_DEPTH_COMPONENT &&
type == GL_UNSIGNED_INT) {
return GL_TRUE;
@@ -919,7 +852,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
pipe->flush(pipe, 0);
/* map the stencil buffer */
- stmap = pipe->region_map(pipe, ps->region);
+ stmap = pipe_surface_map(ps);
/* if width > MAX_WIDTH, have to process image in chunks */
skipPixels = 0;
@@ -952,13 +885,13 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
switch (ps->format) {
case PIPE_FORMAT_U_S8:
{
- ubyte *dest = stmap + spanY * ps->region->pitch + spanX;
+ ubyte *dest = stmap + spanY * ps->pitch + spanX;
memcpy(dest, values, spanWidth);
}
break;
- case PIPE_FORMAT_S8_Z24:
+ case PIPE_FORMAT_S8Z24_UNORM:
{
- uint *dest = (uint *) stmap + spanY * ps->region->pitch + spanX;
+ uint *dest = (uint *) stmap + spanY * ps->pitch + spanX;
GLint k;
for (k = 0; k < spanWidth; k++) {
uint p = dest[k];
@@ -976,7 +909,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
}
/* unmap the stencil buffer */
- pipe->region_unmap(pipe, ps->region);
+ pipe_surface_unmap(ps);
}
@@ -1026,14 +959,13 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
any_pixel_transfer_ops(st) ||
!compatible_formats(format, type, ps->format)) {
/* textured quad */
- struct pipe_mipmap_tree *mt
- = make_mipmap_tree(ctx->st, width, height, format, type,
- unpack, pixels);
- if (mt) {
+ struct pipe_texture *pt
+ = make_texture(ctx->st, width, height, format, type, unpack, pixels);
+ if (pt) {
draw_textured_quad(ctx, x, y, ctx->Current.RasterPos[2],
width, height, ctx->Pixel.ZoomX, ctx->Pixel.ZoomY,
- mt, stvp, stfp, color, GL_FALSE);
- free_mipmap_tree(st->pipe, mt);
+ pt, stvp, stfp, color, GL_FALSE);
+ st->pipe->texture_release(st->pipe, &pt);
}
}
else {
@@ -1047,26 +979,29 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
/**
* Create a texture which represents a bitmap image.
*/
-static struct pipe_mipmap_tree *
+static struct pipe_texture *
make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height,
const struct gl_pixelstore_attrib *unpack,
const GLubyte *bitmap)
{
struct pipe_context *pipe = ctx->st->pipe;
- const uint flags = PIPE_SURFACE_FLAG_TEXTURE;
- uint format = 0, cpp, comp, pitch;
+ struct pipe_surface *surface;
+ uint format = 0, cpp, comp;
+ GLenum internal_format;
ubyte *dest;
- struct pipe_mipmap_tree *mt;
+ struct pipe_texture *pt;
int row, col;
/* find a texture format we know */
if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_I8 )) {
format = PIPE_FORMAT_U_I8;
+ internal_format = GL_INTENSITY8;
cpp = 1;
comp = 0;
}
- else if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8_R8_G8_B8 )) {
- format = PIPE_FORMAT_U_A8_R8_G8_B8;
+ else if (pipe->is_format_supported( pipe, PIPE_FORMAT_A8R8G8B8_UNORM )) {
+ format = PIPE_FORMAT_A8R8G8B8_UNORM;
+ internal_format = GL_RGBA8;
cpp = 4;
comp = 3; /* alpha channel */ /*XXX little-endian dependency */
}
@@ -1076,33 +1011,26 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height,
}
/**
- * Create a mipmap tree.
+ * Create a texture.
*/
- mt = CALLOC_STRUCT(pipe_mipmap_tree);
- if (!mt)
+ pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, format, internal_format,
+ 0, 0, width, height, 1, 0);
+ if (!pt)
return NULL;
if (unpack->BufferObj && unpack->BufferObj->Name) {
/*
- mt->region = buffer_object_region(unpack->BufferObj);
+ pt->region = buffer_object_region(unpack->BufferObj);
*/
printf("st_Bitmap (sourcing from PBO not implemented yet)\n");
}
+ surface = pipe->get_tex_surface(pipe, pt, 0, 0, 0);
- /* allocate texture region/storage */
- mt->region = pipe->winsys->region_alloc(pipe->winsys,
- cpp, width, height, flags);
- pitch = mt->region->pitch;
+ /* map texture surface */
+ dest = pipe_surface_map(surface);
- /* map texture region */
- dest = pipe->region_map(pipe, mt->region);
- if (!dest) {
- printf("st_Bitmap region_map() failed!?!");
- return NULL;
- }
-
- /* Put image into texture region.
+ /* Put image into texture surface.
* Note that the image is actually going to be upside down in
* the texture. We deal with that with texcoords.
*/
@@ -1110,7 +1038,7 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height,
for (row = 0; row < height; row++) {
const GLubyte *src = (const GLubyte *) _mesa_image_address2d(unpack,
bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, row, 0);
- ubyte *destRow = dest + row * pitch * cpp;
+ ubyte *destRow = dest + row * surface->pitch * cpp;
if (unpack->LsbFirst) {
/* Lsb first */
@@ -1159,31 +1087,13 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height,
} /* row */
- /* unmap */
- pipe->region_unmap(pipe, mt->region);
-
- mt->target = PIPE_TEXTURE_2D;
- mt->internal_format = GL_RGBA;
- mt->format = format;
- mt->first_level = 0;
- mt->last_level = 0;
- mt->width0 = width;
- mt->height0 = height;
- mt->depth0 = 1;
- mt->cpp = cpp;
- mt->compressed = 0;
- mt->pitch = mt->region->pitch;
- mt->depth_pitch = 0;
- mt->total_height = height;
- mt->level[0].level_offset = 0;
- mt->level[0].width = width;
- mt->level[0].height = height;
- mt->level[0].depth = 1;
- mt->level[0].nr_images = 1;
- mt->level[0].image_offset = NULL;
- mt->refcount = 1;
-
- return mt;
+ /* Release surface */
+ pipe_surface_unmap(surface);
+ pipe_surface_reference(&surface, NULL);
+
+ pt->format = format;
+
+ return pt;
}
@@ -1195,21 +1105,21 @@ st_Bitmap(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
struct st_fragment_program *stfp;
struct st_vertex_program *stvp;
struct st_context *st = ctx->st;
- struct pipe_mipmap_tree *mt;
+ struct pipe_texture *pt;
stvp = make_vertex_shader(ctx->st, GL_TRUE);
stfp = combined_bitmap_fragment_program(ctx);
st_validate_state(st);
- mt = make_bitmap_texture(ctx, width, height, unpack, bitmap);
- if (mt) {
+ pt = make_bitmap_texture(ctx, width, height, unpack, bitmap);
+ if (pt) {
draw_textured_quad(ctx, x, y, ctx->Current.RasterPos[2],
width, height, 1.0, 1.0,
- mt, stvp, stfp,
+ pt, stvp, stfp,
ctx->Current.RasterColor, GL_FALSE);
- free_mipmap_tree(st->pipe, mt);
+ st->pipe->texture_release(st->pipe, &pt);
}
}
@@ -1219,8 +1129,6 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
GLsizei width, GLsizei height,
GLint dstx, GLint dsty)
{
- struct st_context *st = ctx->st;
- struct pipe_context *pipe = st->pipe;
struct st_renderbuffer *rbRead = st_renderbuffer(ctx->ReadBuffer->_StencilBuffer);
struct st_renderbuffer *rbDraw = st_renderbuffer(ctx->DrawBuffer->_StencilBuffer);
struct pipe_surface *psRead = rbRead->surface;
@@ -1236,8 +1144,8 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
}
/* map the stencil buffers */
- readMap = pipe->region_map(pipe, psRead->region);
- drawMap = pipe->region_map(pipe, psDraw->region);
+ readMap = pipe_surface_map(psRead);
+ drawMap = pipe_surface_map(psDraw);
/* this will do stencil pixel transfer ops */
st_read_stencil_pixels(ctx, srcx, srcy, width, height, GL_UNSIGNED_BYTE,
@@ -1256,11 +1164,11 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
y = ctx->DrawBuffer->Height - y - 1;
}
- dst = drawMap + (y * psDraw->region->pitch + dstx) * psDraw->region->cpp;
+ dst = drawMap + (y * psDraw->pitch + dstx) * psDraw->cpp;
src = buffer + i * width;
switch (psDraw->format) {
- case PIPE_FORMAT_S8_Z24:
+ case PIPE_FORMAT_S8Z24_UNORM:
{
uint *dst4 = (uint *) dst;
int j;
@@ -1281,8 +1189,8 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
free(buffer);
/* unmap the stencil buffers */
- pipe->region_unmap(pipe, psRead->region);
- pipe->region_unmap(pipe, psDraw->region);
+ pipe_surface_unmap(psRead);
+ pipe_surface_unmap(psDraw);
}
@@ -1297,7 +1205,8 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
struct st_vertex_program *stvp;
struct st_fragment_program *stfp;
struct pipe_surface *psRead;
- struct pipe_mipmap_tree *mt;
+ struct pipe_surface *psTex;
+ struct pipe_texture *pt;
GLfloat *color;
uint format;
@@ -1328,56 +1237,52 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
psRead = rbRead->surface;
format = psRead->format;
- mt = alloc_mipmap_tree(ctx->st, width, height, format);
- if (!mt)
+ pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, format,
+ rbRead->Base.InternalFormat, 0, 0, width, height, 1, 0);
+ if (!pt)
return;
+ psTex = pipe->get_tex_surface(pipe, pt, 0, 0, 0);
+
if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
srcy = ctx->DrawBuffer->Height - srcy - height;
}
/* For some drivers (like Xlib) it's not possible to treat the
- * front/back color buffers as regions (they're XImages and Pixmaps).
- * So, this var tells us if we can use region_copy here...
+ * front/back color buffers as surfaces (they're XImages and Pixmaps).
+ * So, this var tells us if we can use surface_copy here...
*/
- if (st->haveFramebufferRegions) {
- /* copy source framebuffer region into mipmap/texture */
- pipe->region_copy(pipe,
- mt->region, /* dest */
- 0, /* dest_offset */
- 0, 0, /* destx/y */
- psRead->region,
- 0, /* src_offset */
- srcx, srcy, width, height);
+ if (st->haveFramebufferSurfaces) {
+ /* copy source framebuffer surface into mipmap/texture */
+ pipe->surface_copy(pipe,
+ psTex, /* dest */
+ 0, 0, /* destx/y */
+ psRead,
+ srcx, srcy, width, height);
}
else {
/* alternate path using get/put_tile() */
- struct pipe_surface *psTex;
GLfloat *buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
- psTex = pipe->get_tex_surface(pipe, mt, 0, 0, 0);
-
- (void) pipe->region_map(pipe, psRead->region);
- (void) pipe->region_map(pipe, psTex->region);
+ (void) pipe_surface_map(psRead);
+ (void) pipe_surface_map(psTex);
pipe->get_tile_rgba(pipe, psRead, srcx, srcy, width, height, buf);
pipe->put_tile_rgba(pipe, psTex, 0, 0, width, height, buf);
- pipe->region_unmap(pipe, psRead->region);
- pipe->region_unmap(pipe, psTex->region);
-
- pipe_surface_reference(&psTex, NULL);
+ pipe_surface_unmap(psRead);
+ pipe_surface_unmap(psTex);
free(buf);
}
-
/* draw textured quad */
draw_textured_quad(ctx, dstx, dsty, ctx->Current.RasterPos[2],
width, height, ctx->Pixel.ZoomX, ctx->Pixel.ZoomY,
- mt, stvp, stfp, color, GL_TRUE);
+ pt, stvp, stfp, color, GL_TRUE);
- free_mipmap_tree(st->pipe, mt);
+ pipe_surface_reference(&psTex, NULL);
+ st->pipe->texture_release(st->pipe, &pt);
}