1 /**************************************************************************
2 *
3 * Copyright 2007 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #ifndef P_TILE_H
29 #define P_TILE_H
30
31 #include "util/compiler.h"
32 #include "util/format/u_formats.h"
33 #include "pipe/p_state.h"
34
35 struct pipe_context;
36 struct pipe_transfer;
37
38 /**
39 * Clip tile against transfer dims.
40 *
41 * XXX: this only clips width and height!
42 *
43 * \return TRUE if tile is totally clipped, FALSE otherwise
44 */
45 static inline bool
u_clip_tile(unsigned x,unsigned y,unsigned * w,unsigned * h,const struct pipe_box * box)46 u_clip_tile(unsigned x, unsigned y, unsigned *w, unsigned *h,
47 const struct pipe_box *box)
48 {
49 if ((int) x >= box->width)
50 return true;
51 if ((int) y >= box->height)
52 return true;
53 if ((int) (x + *w) > box->width)
54 *w = box->width - x;
55 if ((int) (y + *h) > box->height)
56 *h = box->height - y;
57 return false;
58 }
59
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63
64 void
65 pipe_get_tile_raw(struct pipe_transfer *pt,
66 const void *src,
67 unsigned x, unsigned y,
68 unsigned w, unsigned h,
69 void *p, int dst_stride);
70
71 void
72 pipe_put_tile_raw(struct pipe_transfer *pt,
73 void *dst,
74 unsigned x, unsigned y,
75 unsigned w, unsigned h,
76 const void *p, int src_stride);
77
78
79 void
80 pipe_get_tile_rgba(struct pipe_transfer *pt,
81 const void *src,
82 unsigned x, unsigned y,
83 unsigned w, unsigned h,
84 enum pipe_format format,
85 void *dst);
86
87 void
88 pipe_put_tile_rgba(struct pipe_transfer *pt,
89 void *dst,
90 unsigned x, unsigned y,
91 unsigned w, unsigned h,
92 enum pipe_format format,
93 const void *src);
94
95 #ifdef __cplusplus
96 }
97 #endif
98
99 #endif
100