mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-06 19:40:10 +01:00
gallium/util: Move the util_copy/fill_rect into u_surface.
u_rect.h said these should move to a different file, and u_surface seems a better home. Leave #include "util/u_surface.h" to avoid having to touch thousand of files. Reviewed-by: Brian Paul <brianp@vmware.com>
This commit is contained in:
parent
d296326e06
commit
4da4e8ee2a
5 changed files with 140 additions and 187 deletions
|
|
@ -124,7 +124,6 @@ C_SOURCES := \
|
|||
util/u_math.c \
|
||||
util/u_mm.c \
|
||||
util/u_pstipple.c \
|
||||
util/u_rect.c \
|
||||
util/u_ringbuffer.c \
|
||||
util/u_sampler.c \
|
||||
util/u_simple_shaders.c \
|
||||
|
|
|
|||
|
|
@ -1,158 +0,0 @@
|
|||
/**************************************************************************
|
||||
*
|
||||
* Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sub license, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the
|
||||
* next paragraph) shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
|
||||
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
/**
|
||||
* Rectangle-related helper functions.
|
||||
*/
|
||||
|
||||
|
||||
#include "util/u_format.h"
|
||||
#include "util/u_rect.h"
|
||||
#include "util/u_pack_color.h"
|
||||
|
||||
|
||||
/**
|
||||
* Copy 2D rect from one place to another.
|
||||
* Position and sizes are in pixels.
|
||||
* src_stride may be negative to do vertical flip of pixels from source.
|
||||
*/
|
||||
void
|
||||
util_copy_rect(ubyte * dst,
|
||||
enum pipe_format format,
|
||||
unsigned dst_stride,
|
||||
unsigned dst_x,
|
||||
unsigned dst_y,
|
||||
unsigned width,
|
||||
unsigned height,
|
||||
const ubyte * src,
|
||||
int src_stride,
|
||||
unsigned src_x,
|
||||
unsigned src_y)
|
||||
{
|
||||
unsigned i;
|
||||
int src_stride_pos = src_stride < 0 ? -src_stride : src_stride;
|
||||
int blocksize = util_format_get_blocksize(format);
|
||||
int blockwidth = util_format_get_blockwidth(format);
|
||||
int blockheight = util_format_get_blockheight(format);
|
||||
|
||||
assert(blocksize > 0);
|
||||
assert(blockwidth > 0);
|
||||
assert(blockheight > 0);
|
||||
|
||||
dst_x /= blockwidth;
|
||||
dst_y /= blockheight;
|
||||
width = (width + blockwidth - 1)/blockwidth;
|
||||
height = (height + blockheight - 1)/blockheight;
|
||||
src_x /= blockwidth;
|
||||
src_y /= blockheight;
|
||||
|
||||
dst += dst_x * blocksize;
|
||||
src += src_x * blocksize;
|
||||
dst += dst_y * dst_stride;
|
||||
src += src_y * src_stride_pos;
|
||||
width *= blocksize;
|
||||
|
||||
if (width == dst_stride && width == src_stride)
|
||||
memcpy(dst, src, height * width);
|
||||
else {
|
||||
for (i = 0; i < height; i++) {
|
||||
memcpy(dst, src, width);
|
||||
dst += dst_stride;
|
||||
src += src_stride;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
util_fill_rect(ubyte * dst,
|
||||
enum pipe_format format,
|
||||
unsigned dst_stride,
|
||||
unsigned dst_x,
|
||||
unsigned dst_y,
|
||||
unsigned width,
|
||||
unsigned height,
|
||||
union util_color *uc)
|
||||
{
|
||||
const struct util_format_description *desc = util_format_description(format);
|
||||
unsigned i, j;
|
||||
unsigned width_size;
|
||||
int blocksize = desc->block.bits / 8;
|
||||
int blockwidth = desc->block.width;
|
||||
int blockheight = desc->block.height;
|
||||
|
||||
assert(blocksize > 0);
|
||||
assert(blockwidth > 0);
|
||||
assert(blockheight > 0);
|
||||
|
||||
dst_x /= blockwidth;
|
||||
dst_y /= blockheight;
|
||||
width = (width + blockwidth - 1)/blockwidth;
|
||||
height = (height + blockheight - 1)/blockheight;
|
||||
|
||||
dst += dst_x * blocksize;
|
||||
dst += dst_y * dst_stride;
|
||||
width_size = width * blocksize;
|
||||
|
||||
switch (blocksize) {
|
||||
case 1:
|
||||
if(dst_stride == width_size)
|
||||
memset(dst, uc->ub, height * width_size);
|
||||
else {
|
||||
for (i = 0; i < height; i++) {
|
||||
memset(dst, uc->ub, width_size);
|
||||
dst += dst_stride;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
for (i = 0; i < height; i++) {
|
||||
uint16_t *row = (uint16_t *)dst;
|
||||
for (j = 0; j < width; j++)
|
||||
*row++ = uc->us;
|
||||
dst += dst_stride;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
for (i = 0; i < height; i++) {
|
||||
uint32_t *row = (uint32_t *)dst;
|
||||
for (j = 0; j < width; j++)
|
||||
*row++ = uc->ui;
|
||||
dst += dst_stride;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
for (i = 0; i < height; i++) {
|
||||
ubyte *row = dst;
|
||||
for (j = 0; j < width; j++) {
|
||||
memcpy(row, uc, blocksize);
|
||||
row += blocksize;
|
||||
}
|
||||
dst += dst_stride;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -83,36 +83,10 @@ u_rect_possible_intersection(const struct u_rect *a,
|
|||
}
|
||||
#endif
|
||||
|
||||
#include "pipe/p_format.h"
|
||||
#include "util/u_pack_color.h"
|
||||
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* Pipe copy/fill rect helpers.
|
||||
/* Include pipe copy/fill rect helpers declarations for backwards compatibility
|
||||
*/
|
||||
#include "util/u_surface.h"
|
||||
|
||||
/* These really should move to a different file:
|
||||
*/
|
||||
#include "pipe/p_format.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void
|
||||
util_copy_rect(ubyte * dst, enum pipe_format format,
|
||||
unsigned dst_stride, unsigned dst_x, unsigned dst_y,
|
||||
unsigned width, unsigned height, const ubyte * src,
|
||||
int src_stride, unsigned src_x, unsigned src_y);
|
||||
|
||||
extern void
|
||||
util_fill_rect(ubyte * dst, enum pipe_format format,
|
||||
unsigned dst_stride, unsigned dst_x, unsigned dst_y,
|
||||
unsigned width, unsigned height, union util_color *uc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* U_RECT_H */
|
||||
|
|
|
|||
|
|
@ -115,6 +115,130 @@ util_create_rgba_texture(struct pipe_context *pipe,
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy 2D rect from one place to another.
|
||||
* Position and sizes are in pixels.
|
||||
* src_stride may be negative to do vertical flip of pixels from source.
|
||||
*/
|
||||
void
|
||||
util_copy_rect(ubyte * dst,
|
||||
enum pipe_format format,
|
||||
unsigned dst_stride,
|
||||
unsigned dst_x,
|
||||
unsigned dst_y,
|
||||
unsigned width,
|
||||
unsigned height,
|
||||
const ubyte * src,
|
||||
int src_stride,
|
||||
unsigned src_x,
|
||||
unsigned src_y)
|
||||
{
|
||||
unsigned i;
|
||||
int src_stride_pos = src_stride < 0 ? -src_stride : src_stride;
|
||||
int blocksize = util_format_get_blocksize(format);
|
||||
int blockwidth = util_format_get_blockwidth(format);
|
||||
int blockheight = util_format_get_blockheight(format);
|
||||
|
||||
assert(blocksize > 0);
|
||||
assert(blockwidth > 0);
|
||||
assert(blockheight > 0);
|
||||
|
||||
dst_x /= blockwidth;
|
||||
dst_y /= blockheight;
|
||||
width = (width + blockwidth - 1)/blockwidth;
|
||||
height = (height + blockheight - 1)/blockheight;
|
||||
src_x /= blockwidth;
|
||||
src_y /= blockheight;
|
||||
|
||||
dst += dst_x * blocksize;
|
||||
src += src_x * blocksize;
|
||||
dst += dst_y * dst_stride;
|
||||
src += src_y * src_stride_pos;
|
||||
width *= blocksize;
|
||||
|
||||
if (width == dst_stride && width == src_stride)
|
||||
memcpy(dst, src, height * width);
|
||||
else {
|
||||
for (i = 0; i < height; i++) {
|
||||
memcpy(dst, src, width);
|
||||
dst += dst_stride;
|
||||
src += src_stride;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
util_fill_rect(ubyte * dst,
|
||||
enum pipe_format format,
|
||||
unsigned dst_stride,
|
||||
unsigned dst_x,
|
||||
unsigned dst_y,
|
||||
unsigned width,
|
||||
unsigned height,
|
||||
union util_color *uc)
|
||||
{
|
||||
const struct util_format_description *desc = util_format_description(format);
|
||||
unsigned i, j;
|
||||
unsigned width_size;
|
||||
int blocksize = desc->block.bits / 8;
|
||||
int blockwidth = desc->block.width;
|
||||
int blockheight = desc->block.height;
|
||||
|
||||
assert(blocksize > 0);
|
||||
assert(blockwidth > 0);
|
||||
assert(blockheight > 0);
|
||||
|
||||
dst_x /= blockwidth;
|
||||
dst_y /= blockheight;
|
||||
width = (width + blockwidth - 1)/blockwidth;
|
||||
height = (height + blockheight - 1)/blockheight;
|
||||
|
||||
dst += dst_x * blocksize;
|
||||
dst += dst_y * dst_stride;
|
||||
width_size = width * blocksize;
|
||||
|
||||
switch (blocksize) {
|
||||
case 1:
|
||||
if(dst_stride == width_size)
|
||||
memset(dst, uc->ub, height * width_size);
|
||||
else {
|
||||
for (i = 0; i < height; i++) {
|
||||
memset(dst, uc->ub, width_size);
|
||||
dst += dst_stride;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
for (i = 0; i < height; i++) {
|
||||
uint16_t *row = (uint16_t *)dst;
|
||||
for (j = 0; j < width; j++)
|
||||
*row++ = uc->us;
|
||||
dst += dst_stride;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
for (i = 0; i < height; i++) {
|
||||
uint32_t *row = (uint32_t *)dst;
|
||||
for (j = 0; j < width; j++)
|
||||
*row++ = uc->ui;
|
||||
dst += dst_stride;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
for (i = 0; i < height; i++) {
|
||||
ubyte *row = dst;
|
||||
for (j = 0; j < width; j++) {
|
||||
memcpy(row, uc, blocksize);
|
||||
row += blocksize;
|
||||
}
|
||||
dst += dst_stride;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fallback function for pipe->resource_copy_region().
|
||||
* Note: (X,Y)=(0,0) is always the upper-left corner.
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@
|
|||
#include "pipe/p_compiler.h"
|
||||
#include "pipe/p_state.h"
|
||||
|
||||
#include "util/u_pack_color.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
@ -49,6 +51,18 @@ util_create_rgba_texture(struct pipe_context *ctx,
|
|||
struct pipe_resource **textureOut);
|
||||
|
||||
|
||||
extern void
|
||||
util_copy_rect(ubyte * dst, enum pipe_format format,
|
||||
unsigned dst_stride, unsigned dst_x, unsigned dst_y,
|
||||
unsigned width, unsigned height, const ubyte * src,
|
||||
int src_stride, unsigned src_x, unsigned src_y);
|
||||
|
||||
extern void
|
||||
util_fill_rect(ubyte * dst, enum pipe_format format,
|
||||
unsigned dst_stride, unsigned dst_x, unsigned dst_y,
|
||||
unsigned width, unsigned height, union util_color *uc);
|
||||
|
||||
|
||||
extern void
|
||||
util_resource_copy_region(struct pipe_context *pipe,
|
||||
struct pipe_resource *dst,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue