intel_pixel_bitmap.c revision 45b37c4b12bb328e804a2b58c90e0099240879d3
19e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt/************************************************************************** 29e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * 39e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. 49e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * All Rights Reserved. 59e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * 69e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * Permission is hereby granted, free of charge, to any person obtaining a 79e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * copy of this software and associated documentation files (the 89e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * "Software"), to deal in the Software without restriction, including 99e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * without limitation the rights to use, copy, modify, merge, publish, 109e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * distribute, sub license, and/or sell copies of the Software, and to 119e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * permit persons to whom the Software is furnished to do so, subject to 129e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * the following conditions: 139e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * 149e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * The above copyright notice and this permission notice (including the 159e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * next paragraph) shall be included in all copies or substantial portionsalloc 169e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * of the Software. 179e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * 189e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 199e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 209e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 219e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 229e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 239e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 249e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 259e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * 269e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt **************************************************************************/ 279e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 28ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/glheader.h" 29ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/enums.h" 30ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/image.h" 31ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/colormac.h" 32ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/mtypes.h" 33ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/macros.h" 34ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/bufferobj.h" 35b9752a2bd615d136369af63ed3d45cc10adf21e7Eric Anholt#include "main/state.h" 36e1a92175542c6645c23cc78f2a4fcd36dd0235e6Eric Anholt#include "main/texobj.h" 37dfc7b7212f57080d18c4d1122435c4c4575694c7Vinson Lee#include "main/context.h" 389e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt#include "swrast/swrast.h" 39ef1e1261df02203da4c7ebf708b0edf1b9cd16c2Vinson Lee#include "drivers/common/meta.h" 409e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 419e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt#include "intel_screen.h" 429e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt#include "intel_context.h" 439e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt#include "intel_batchbuffer.h" 449e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt#include "intel_blit.h" 459e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt#include "intel_regions.h" 46c99fa92ff84e927c82e1231d96921fda9a2b0852Kristian Høgsberg#include "intel_buffers.h" 47c99fa92ff84e927c82e1231d96921fda9a2b0852Kristian Høgsberg#include "intel_pixel.h" 48f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie#include "intel_reg.h" 499e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 509e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 519e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt#define FILE_DEBUG_FLAG DEBUG_PIXEL 529e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 539e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 549e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt/* Unlike the other intel_pixel_* functions, the expectation here is 559e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * that the incoming data is not in a PBO. With the XY_TEXT blit 569e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * method, there's no benefit haveing it in a PBO, but we could 579e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * implement a path based on XY_MONO_SRC_COPY_BLIT which might benefit 589e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * PBO bitmaps. I think they are probably pretty rare though - I 599e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * wonder if Xgl uses them? 609e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt */ 619e68e191ac9d32f2f93e840a66127e724b442756Eric Anholtstatic const GLubyte *map_pbo( GLcontext *ctx, 629e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt GLsizei width, GLsizei height, 639e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt const struct gl_pixelstore_attrib *unpack, 649e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt const GLubyte *bitmap ) 659e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt{ 669e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt GLubyte *buf; 679e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 689e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt if (!_mesa_validate_pbo_access(2, unpack, width, height, 1, 699e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt GL_COLOR_INDEX, GL_BITMAP, 709e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt (GLvoid *) bitmap)) { 719e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt _mesa_error(ctx, GL_INVALID_OPERATION,"glBitmap(invalid PBO access)"); 729e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt return NULL; 739e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt } 749e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 759e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, 769e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt GL_READ_ONLY_ARB, 779e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt unpack->BufferObj); 789e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt if (!buf) { 799e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt _mesa_error(ctx, GL_INVALID_OPERATION, "glBitmap(PBO is mapped)"); 809e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt return NULL; 819e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt } 829e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 839e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt return ADD_POINTERS(buf, bitmap); 849e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt} 859e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 8629e22059a927a6279d035cdb149b053f8a3e0bf4Brian Paulstatic GLboolean test_bit( const GLubyte *src, GLuint bit ) 879e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt{ 889e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt return (src[bit/8] & (1<<(bit % 8))) ? 1 : 0; 899e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt} 909e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 9129e22059a927a6279d035cdb149b053f8a3e0bf4Brian Paulstatic void set_bit( GLubyte *dest, GLuint bit ) 929e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt{ 939e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt dest[bit/8] |= 1 << (bit % 8); 949e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt} 959e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 969e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt/* Extract a rectangle's worth of data from the bitmap. Called 9741f4d82ba8e2497d9fe27f55cb1b8707862fed46Eric Anholt * per chunk of HW-sized bitmap. 989e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt */ 999e68e191ac9d32f2f93e840a66127e724b442756Eric Anholtstatic GLuint get_bitmap_rect(GLsizei width, GLsizei height, 1009e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt const struct gl_pixelstore_attrib *unpack, 1019e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt const GLubyte *bitmap, 1029e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt GLuint x, GLuint y, 1039e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt GLuint w, GLuint h, 1049e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt GLubyte *dest, 1059e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt GLuint row_align, 1069e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt GLboolean invert) 1079e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt{ 1089e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt GLuint src_offset = (x + unpack->SkipPixels) & 0x7; 1099e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt GLuint mask = unpack->LsbFirst ? 0 : 7; 1109e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt GLuint bit = 0; 1119e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt GLint row, col; 1129e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt GLint first, last; 1139e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt GLint incr; 1149e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt GLuint count = 0; 1159e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 1169e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt if (INTEL_DEBUG & DEBUG_PIXEL) 117298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg printf("%s %d,%d %dx%d bitmap %dx%d skip %d src_offset %d mask %d\n", 1189e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt __FUNCTION__, x,y,w,h,width,height,unpack->SkipPixels, src_offset, mask); 1199e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 1209e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt if (invert) { 1219e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt first = h-1; 1229e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt last = 0; 1239e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt incr = -1; 1249e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt } 1259e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt else { 1269e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt first = 0; 1279e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt last = h-1; 1289e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt incr = 1; 1299e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt } 1309e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 1319e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt /* Require that dest be pre-zero'd. 1329e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt */ 1339e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt for (row = first; row != (last+incr); row += incr) { 1349e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt const GLubyte *rowsrc = _mesa_image_address2d(unpack, bitmap, 1359e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt width, height, 1369e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt GL_COLOR_INDEX, GL_BITMAP, 1379e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt y + row, x); 1389e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 1399e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt for (col = 0; col < w; col++, bit++) { 1409e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt if (test_bit(rowsrc, (col + src_offset) ^ mask)) { 1419e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt set_bit(dest, bit ^ 7); 1429e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt count++; 1439e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt } 1449e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt } 1459e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 1469e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt if (row_align) 1479e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt bit = ALIGN(bit, row_align); 1489e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt } 1499e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 1509e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt return count; 1519e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt} 1529e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 1531db63713046efd49071aae448105df8a80e1e83dEric Anholt/** 1541db63713046efd49071aae448105df8a80e1e83dEric Anholt * Returns the low Y value of the vertical range given, flipped according to 1551db63713046efd49071aae448105df8a80e1e83dEric Anholt * whether the framebuffer is or not. 1561db63713046efd49071aae448105df8a80e1e83dEric Anholt */ 157c67bb15d4e3da430d511444bd7d159ccb0c84b73Vinson Leestatic INLINE int 1581db63713046efd49071aae448105df8a80e1e83dEric Anholty_flip(struct gl_framebuffer *fb, int y, int height) 1591db63713046efd49071aae448105df8a80e1e83dEric Anholt{ 1601db63713046efd49071aae448105df8a80e1e83dEric Anholt if (fb->Name != 0) 1611db63713046efd49071aae448105df8a80e1e83dEric Anholt return y; 1621db63713046efd49071aae448105df8a80e1e83dEric Anholt else 1631db63713046efd49071aae448105df8a80e1e83dEric Anholt return fb->Height - y - height; 1641db63713046efd49071aae448105df8a80e1e83dEric Anholt} 1659e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 1669e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt/* 1679e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * Render a bitmap. 1689e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt */ 1699e68e191ac9d32f2f93e840a66127e724b442756Eric Anholtstatic GLboolean 1709e68e191ac9d32f2f93e840a66127e724b442756Eric Anholtdo_blit_bitmap( GLcontext *ctx, 1719e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt GLint dstx, GLint dsty, 1729e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt GLsizei width, GLsizei height, 1739e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt const struct gl_pixelstore_attrib *unpack, 1749e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt const GLubyte *bitmap ) 1759e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt{ 1769e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt struct intel_context *intel = intel_context(ctx); 1779e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt struct intel_region *dst = intel_drawbuf_region(intel); 178cb433d91c6e198b7c77f747f1a38803532bc9be9Eric Anholt struct gl_framebuffer *fb = ctx->DrawBuffer; 1799e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt GLfloat tmpColor[4]; 1805982d397990fd2ae4c729977cf8d22da5ef29987Xiang, Haihao GLubyte ubcolor[4]; 1818f81a6468fdbc7320800ea497791e3e1b8f782caEric Anholt GLuint color; 182e67350da34c6009edff50c160df27493cb363e1bEric Anholt GLsizei bitmap_width = width; 183e67350da34c6009edff50c160df27493cb363e1bEric Anholt GLsizei bitmap_height = height; 184348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt GLint px, py; 185348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt GLuint stipple[32]; 186348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt GLint orig_dstx = dstx; 187348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt GLint orig_dsty = dsty; 1889e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 189b9752a2bd615d136369af63ed3d45cc10adf21e7Eric Anholt /* Update draw buffer bounds */ 190b9752a2bd615d136369af63ed3d45cc10adf21e7Eric Anholt _mesa_update_state(ctx); 191b9752a2bd615d136369af63ed3d45cc10adf21e7Eric Anholt 1923a5463d158eff483a992c9792d771fb80db9aed0Brian Paul if (ctx->Depth.Test) { 1933a5463d158eff483a992c9792d771fb80db9aed0Brian Paul /* The blit path produces incorrect results when depth testing is on. 1943a5463d158eff483a992c9792d771fb80db9aed0Brian Paul * It seems the blit Z coord is always 1.0 (the far plane) so fragments 1953a5463d158eff483a992c9792d771fb80db9aed0Brian Paul * will likely be obscured by other, closer geometry. 1963a5463d158eff483a992c9792d771fb80db9aed0Brian Paul */ 1973a5463d158eff483a992c9792d771fb80db9aed0Brian Paul return GL_FALSE; 1983a5463d158eff483a992c9792d771fb80db9aed0Brian Paul } 1993a5463d158eff483a992c9792d771fb80db9aed0Brian Paul 2009e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt if (!dst) 2019e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt return GL_FALSE; 2029e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 203abdf2e14bc174ecd510b580756efa42f43ca4419Brian Paul if (_mesa_is_bufferobj(unpack->BufferObj)) { 2049e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt bitmap = map_pbo(ctx, width, height, unpack, bitmap); 2059e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt if (bitmap == NULL) 2069e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt return GL_TRUE; /* even though this is an error, we're done */ 2079e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt } 2089e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 2099e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt COPY_4V(tmpColor, ctx->Current.RasterColor); 2109e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 2119e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt if (NEED_SECONDARY_COLOR(ctx)) { 2129e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt ADD_3V(tmpColor, tmpColor, ctx->Current.RasterSecondaryColor); 2139e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt } 2149e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 2155982d397990fd2ae4c729977cf8d22da5ef29987Xiang, Haihao UNCLAMPED_FLOAT_TO_UBYTE(ubcolor[0], tmpColor[0]); 2165982d397990fd2ae4c729977cf8d22da5ef29987Xiang, Haihao UNCLAMPED_FLOAT_TO_UBYTE(ubcolor[1], tmpColor[1]); 2175982d397990fd2ae4c729977cf8d22da5ef29987Xiang, Haihao UNCLAMPED_FLOAT_TO_UBYTE(ubcolor[2], tmpColor[2]); 2185982d397990fd2ae4c729977cf8d22da5ef29987Xiang, Haihao UNCLAMPED_FLOAT_TO_UBYTE(ubcolor[3], tmpColor[3]); 2195982d397990fd2ae4c729977cf8d22da5ef29987Xiang, Haihao 2208f81a6468fdbc7320800ea497791e3e1b8f782caEric Anholt if (dst->cpp == 2) 221ee64347979b4e22976910cb97869887f7de4241cEric Anholt color = PACK_COLOR_565(ubcolor[0], ubcolor[1], ubcolor[2]); 2228f81a6468fdbc7320800ea497791e3e1b8f782caEric Anholt else 223ee64347979b4e22976910cb97869887f7de4241cEric Anholt color = PACK_COLOR_8888(ubcolor[3], ubcolor[0], ubcolor[1], ubcolor[2]); 2249e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 22569e10084cd3ac9b814b311913138882a32f9f2eaEric Anholt if (!intel_check_blit_fragment_ops(ctx, tmpColor[3] == 1.0F)) 2269e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt return GL_FALSE; 2279e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 228d449627829e1a4a3250a1a723af2f4e3cd5fd194Kristian Høgsberg intel_prepare_render(intel); 229d449627829e1a4a3250a1a723af2f4e3cd5fd194Kristian Høgsberg 230348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt /* Clip to buffer bounds and scissor. */ 231348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt if (!_mesa_clip_to_region(fb->_Xmin, fb->_Ymin, 232348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt fb->_Xmax, fb->_Ymax, 233348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt &dstx, &dsty, &width, &height)) 234348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt goto out; 235348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt 236348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt dsty = y_flip(fb, dsty, height); 2379e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 2389e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt#define DY 32 2399e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt#define DX 32 2409e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 241348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt /* Chop it all into chunks that can be digested by hardware: */ 242348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt for (py = 0; py < height; py += DY) { 243348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt for (px = 0; px < width; px += DX) { 244348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt int h = MIN2(DY, height - py); 245348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt int w = MIN2(DX, width - px); 246348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt GLuint sz = ALIGN(ALIGN(w,8) * h, 64)/8; 247348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt GLenum logic_op = ctx->Color.ColorLogicOpEnabled ? 248348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt ctx->Color.LogicOp : GL_COPY; 249348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt 250348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt assert(sz <= sizeof(stipple)); 251348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt memset(stipple, 0, sz); 252348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt 253348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt /* May need to adjust this when padding has been introduced in 254348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt * sz above: 255348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt * 256348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt * Have to translate destination coordinates back into source 257348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt * coordinates. 2589e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt */ 259348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt if (get_bitmap_rect(bitmap_width, bitmap_height, unpack, 260348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt bitmap, 261348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt -orig_dstx + (dstx + px), 262348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt -orig_dsty + y_flip(fb, dsty + py, h), 263348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt w, h, 264348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt (GLubyte *)stipple, 265348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt 8, 266348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt fb->Name == 0 ? GL_TRUE : GL_FALSE) == 0) 267348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt continue; 268348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt 269348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt if (!intelEmitImmediateColorExpandBlit(intel, 270348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt dst->cpp, 271348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt (GLubyte *)stipple, 272348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt sz, 273348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt color, 274348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt dst->pitch, 275348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt dst->buffer, 276348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt 0, 277348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt dst->tiling, 278348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt dstx + px, 279348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt dsty + py, 280348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt w, h, 281348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt logic_op)) { 282348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt return GL_FALSE; 283348fadc5df83c22b237c59f1aed26573ab9f7506Eric Anholt } 2849e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt } 2859e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt } 286f75843a517bd188639e6866db2a7b04de3524e16Dave Airlieout: 2879e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 288cb433d91c6e198b7c77f747f1a38803532bc9be9Eric Anholt if (INTEL_DEBUG & DEBUG_SYNC) 289cb433d91c6e198b7c77f747f1a38803532bc9be9Eric Anholt intel_batchbuffer_flush(intel->batch); 2909e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 291abdf2e14bc174ecd510b580756efa42f43ca4419Brian Paul if (_mesa_is_bufferobj(unpack->BufferObj)) { 2929e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt /* done with PBO so unmap it now */ 2939e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, 2949e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt unpack->BufferObj); 2959e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt } 2969e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 297a7e4a311e971005f7b23572ff3ca93f6d3c17edfEric Anholt intel_check_front_buffer_rendering(intel); 298a7e4a311e971005f7b23572ff3ca93f6d3c17edfEric Anholt 2999e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt return GL_TRUE; 3009e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt} 3019e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 3029e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt/* There are a large number of possible ways to implement bitmap on 3039e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * this hardware, most of them have some sort of drawback. Here are a 3049e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * few that spring to mind: 3059e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * 3069e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * Blit: 3079e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * - XY_MONO_SRC_BLT_CMD 3089e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * - use XY_SETUP_CLIP_BLT for cliprect clipping. 3099e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * - XY_TEXT_BLT 3109e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * - XY_TEXT_IMMEDIATE_BLT 3119e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * - blit per cliprect, subject to maximum immediate data size. 3129e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * - XY_COLOR_BLT 3139e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * - per pixel or run of pixels 3149e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * - XY_PIXEL_BLT 3159e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * - good for sparse bitmaps 3169e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * 3179e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * 3D engine: 3189e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * - Point per pixel 3199e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * - Translate bitmap to an alpha texture and render as a quad 3209e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt * - Chop bitmap up into 32x32 squares and render w/polygon stipple. 3219e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt */ 3229e68e191ac9d32f2f93e840a66127e724b442756Eric Anholtvoid 3239e68e191ac9d32f2f93e840a66127e724b442756Eric AnholtintelBitmap(GLcontext * ctx, 3249e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt GLint x, GLint y, 3259e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt GLsizei width, GLsizei height, 3269e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt const struct gl_pixelstore_attrib *unpack, 3279e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt const GLubyte * pixels) 3289e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt{ 32945b37c4b12bb328e804a2b58c90e0099240879d3Zhenyu Wang struct intel_context *intel = intel_context(ctx); 33045b37c4b12bb328e804a2b58c90e0099240879d3Zhenyu Wang 3319e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt if (do_blit_bitmap(ctx, x, y, width, height, 3329e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt unpack, pixels)) 3339e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt return; 3349e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt 33545b37c4b12bb328e804a2b58c90e0099240879d3Zhenyu Wang /* FIXME */ 33645b37c4b12bb328e804a2b58c90e0099240879d3Zhenyu Wang if (intel->gen == 6) 33745b37c4b12bb328e804a2b58c90e0099240879d3Zhenyu Wang return _swrast_Bitmap(ctx, x, y, width, height, unpack, pixels); 33845b37c4b12bb328e804a2b58c90e0099240879d3Zhenyu Wang 339fae18559461e62af623be77787ecba4c7013a8b4Eric Anholt _mesa_meta_Bitmap(ctx, x, y, width, height, unpack, pixels); 3409e68e191ac9d32f2f93e840a66127e724b442756Eric Anholt} 341