Ejemplo n.º 1
0
static void r300EmitElts(GLcontext * ctx, void *elts, unsigned long n_elts,
			 int elt_size)
{
	r300ContextPtr rmesa = R300_CONTEXT(ctx);
	struct r300_dma_region *rvb = &rmesa->state.elt_dma;
	void *out;

	assert(elt_size == 2 || elt_size == 4);

	if (r300IsGartMemory(rmesa, elts, n_elts * elt_size)) {
		rvb->address = rmesa->radeon.radeonScreen->gartTextures.map;
		rvb->start = ((char *)elts) - rvb->address;
		rvb->aos_offset =
		    rmesa->radeon.radeonScreen->gart_texture_offset +
		    rvb->start;
		return;
	} else if (r300IsGartMemory(rmesa, elts, 1)) {
		WARN_ONCE("Pointer not within GART memory!\n");
		_mesa_exit(-1);
	}

	r300AllocDmaRegion(rmesa, rvb, n_elts * elt_size, elt_size);
	rvb->aos_offset = GET_START(rvb);

	out = rvb->address + rvb->start;
	memcpy(out, elts, n_elts * elt_size);
}
Ejemplo n.º 2
0
static GLboolean
r300ValidateClientStorage(GLcontext * ctx, GLenum target,
			  GLint internalFormat,
			  GLint srcWidth, GLint srcHeight,
			  GLenum format, GLenum type, const void *pixels,
			  const struct gl_pixelstore_attrib *packing,
			  struct gl_texture_object *texObj,
			  struct gl_texture_image *texImage)
{
	r300ContextPtr rmesa = R300_CONTEXT(ctx);

	if (0)
		fprintf(stderr, "intformat %s format %s type %s\n",
			_mesa_lookup_enum_by_nr(internalFormat),
			_mesa_lookup_enum_by_nr(format),
			_mesa_lookup_enum_by_nr(type));

	if (!ctx->Unpack.ClientStorage)
		return 0;

	if (ctx->_ImageTransferState ||
	    texImage->IsCompressed || texObj->GenerateMipmap)
		return 0;

	/* This list is incomplete, may be different on ppc???
	 */
	switch (internalFormat) {
	case GL_RGBA:
		if (format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8_REV) {
			texImage->TexFormat = _dri_texformat_argb8888;
		} else
			return 0;
		break;

	case GL_RGB:
		if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) {
			texImage->TexFormat = _dri_texformat_rgb565;
		} else
			return 0;
		break;

	case GL_YCBCR_MESA:
		if (format == GL_YCBCR_MESA &&
		    type == GL_UNSIGNED_SHORT_8_8_REV_APPLE) {
			texImage->TexFormat = &_mesa_texformat_ycbcr_rev;
		} else if (format == GL_YCBCR_MESA &&
			   (type == GL_UNSIGNED_SHORT_8_8_APPLE ||
			    type == GL_UNSIGNED_BYTE)) {
			texImage->TexFormat = &_mesa_texformat_ycbcr;
		} else
			return 0;
		break;

	default:
		return 0;
	}

	/* Could deal with these packing issues, but currently don't:
	 */
	if (packing->SkipPixels ||
	    packing->SkipRows || packing->SwapBytes || packing->LsbFirst) {
		return 0;
	}

	{
		GLint srcRowStride = _mesa_image_row_stride(packing, srcWidth,
							    format, type);

		if (0)
			fprintf(stderr, "%s: srcRowStride %d/%x\n",
				__FUNCTION__, srcRowStride, srcRowStride);

		/* Could check this later in upload, pitch restrictions could be
		 * relaxed, but would need to store the image pitch somewhere,
		 * as packing details might change before image is uploaded:
		 */
		if (!r300IsGartMemory(rmesa, pixels, srcHeight * srcRowStride)
		    || (srcRowStride & 63))
			return 0;

		/* Have validated that _mesa_transfer_teximage would be a straight
		 * memcpy at this point.  NOTE: future calls to TexSubImage will
		 * overwrite the client data.  This is explicitly mentioned in the
		 * extension spec.
		 */
		texImage->Data = (void *)pixels;
		texImage->IsClientData = GL_TRUE;
		texImage->RowStride =
		    srcRowStride / texImage->TexFormat->TexelBytes;

		return 1;
	}
}