Define PIPE_FORMAT_ tokens as an enum set, rather than #defines.
[mesa.git] / src / mesa / pipe / p_inlines.h
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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_INLINES_H
29 #define P_INLINES_H
30
31 #include "p_context.h"
32 #include "p_defines.h"
33 #include "p_winsys.h"
34
35
36 static INLINE ubyte *
37 pipe_surface_map(struct pipe_surface *surface)
38 {
39 if (!surface->map_refcount++) {
40 surface->map
41 = (ubyte *) surface->winsys->buffer_map( surface->winsys,
42 surface->buffer,
43 PIPE_BUFFER_FLAG_WRITE |
44 PIPE_BUFFER_FLAG_READ )
45 + surface->offset;
46 }
47
48 return surface->map;
49 }
50
51 static INLINE void
52 pipe_surface_unmap(struct pipe_surface *surface)
53 {
54 if (surface->map_refcount > 0) {
55 assert(surface->map);
56 if (!--surface->map_refcount) {
57 surface->winsys->buffer_unmap( surface->winsys,
58 surface->buffer );
59 surface->map = NULL;
60 }
61 }
62 }
63
64
65 /**
66 * Set 'ptr' to point to 'surf' and update reference counting.
67 * The old thing pointed to, if any, will be unreferenced first.
68 * 'surf' may be NULL.
69 */
70 static INLINE void
71 pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf)
72 {
73 assert(ptr);
74 if (*ptr) {
75 struct pipe_winsys *winsys = (*ptr)->winsys;
76 winsys->surface_release(winsys, ptr);
77 assert(!*ptr);
78 }
79 if (surf) {
80 /* reference the new thing */
81 surf->refcount++;
82 *ptr = surf;
83 }
84 }
85
86
87 /**
88 * \sa pipe_surface_reference
89 */
90 static INLINE void
91 pipe_texture_reference(struct pipe_context *pipe, struct pipe_texture **ptr,
92 struct pipe_texture *pt)
93 {
94 assert(ptr);
95 if (*ptr) {
96 pipe->texture_release(pipe, ptr);
97 assert(!*ptr);
98 }
99 if (pt) {
100 /* reference the new thing */
101 pt->refcount++;
102 *ptr = pt;
103 }
104 }
105
106
107 #endif /* P_INLINES_H */