4d12a4efdd627f35eed9f6298d07392f12f83d2c
[profile/ivi/mesa.git] / src / gallium / state_trackers / vega / st_inlines.h
1 /**************************************************************************
2  * 
3  * Copyright 2009 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 /**
29  * Functions for checking if buffers/textures are referenced when we need
30  * to read/write from/to them.  Flush when needed.
31  */
32
33 #ifndef ST_INLINES_H
34 #define ST_INLINES_H
35
36 #include "vg_context.h"
37
38 #include "pipe/p_context.h"
39 #include "pipe/p_screen.h"
40 #include "pipe/p_defines.h"
41 #include "util/u_inlines.h"
42 #include "pipe/p_state.h"
43
44 static INLINE struct pipe_transfer *
45 st_cond_flush_get_tex_transfer(struct vg_context *st,
46                                struct pipe_texture *pt,
47                                unsigned int face,
48                                unsigned int level,
49                                unsigned int zslice,
50                                enum pipe_transfer_usage usage,
51                                unsigned int x, unsigned int y,
52                                unsigned int w, unsigned int h)
53 {
54    struct pipe_context *pipe = st->pipe;
55    unsigned referenced =
56       pipe->is_texture_referenced(pipe, pt, face, level);
57
58    if (referenced && ((referenced & PIPE_REFERENCED_FOR_WRITE) ||
59                       (usage & PIPE_TRANSFER_WRITE)))
60       vgFlush();
61
62    return pipe->get_tex_transfer(pipe, pt, face, level, zslice, usage,
63                                    x, y, w, h);
64 }
65
66 static INLINE struct pipe_transfer *
67 st_no_flush_get_tex_transfer(struct vg_context *st,
68                              struct pipe_texture *pt,
69                              unsigned int face,
70                              unsigned int level,
71                              unsigned int zslice,
72                              enum pipe_transfer_usage usage,
73                              unsigned int x, unsigned int y,
74                              unsigned int w, unsigned int h)
75 {
76    struct pipe_context *pipe = st->pipe;
77
78    return pipe->get_tex_transfer(pipe, pt, face, level,
79                                  zslice, usage, x, y, w, h);
80 }
81
82 static INLINE void *
83 st_cond_flush_pipe_buffer_map(struct vg_context *st,
84                               struct pipe_buffer *buf,
85                               unsigned int map_flags)
86 {
87    struct pipe_context *pipe = st->pipe;
88    unsigned int referenced = pipe->is_buffer_referenced(pipe, buf);
89
90    if (referenced && ((referenced & PIPE_REFERENCED_FOR_WRITE) ||
91                       (map_flags & PIPE_BUFFER_USAGE_CPU_WRITE)))
92       vgFlush();
93
94    return pipe_buffer_map(pipe->screen, buf, map_flags);
95 }
96
97 static INLINE void *
98 st_no_flush_pipe_buffer_map(struct vg_context *st,
99                             struct pipe_buffer *buf,
100                             unsigned int map_flags)
101 {
102    return pipe_buffer_map(st->pipe->screen, buf, map_flags);
103 }
104
105
106 static INLINE void
107 st_cond_flush_pipe_buffer_write(struct vg_context *st,
108                                 struct pipe_buffer *buf,
109                                 unsigned int offset,
110                                 unsigned int size,
111                                 const void * data)
112 {
113    struct pipe_context *pipe = st->pipe;
114
115    if (pipe->is_buffer_referenced(pipe, buf))
116       vgFlush();
117
118    pipe_buffer_write(pipe->screen, buf, offset, size, data);
119 }
120
121 static INLINE void
122 st_no_flush_pipe_buffer_write(struct vg_context *st,
123                               struct pipe_buffer *buf,
124                               unsigned int offset,
125                               unsigned int size,
126                               const void * data)
127 {
128    pipe_buffer_write(st->pipe->screen, buf, offset, size, data);
129 }
130
131 static INLINE void
132 st_cond_flush_pipe_buffer_read(struct vg_context *st,
133                                struct pipe_buffer *buf,
134                                unsigned int offset,
135                                unsigned int size,
136                                void * data)
137 {
138    struct pipe_context *pipe = st->pipe;
139
140    if (pipe->is_buffer_referenced(pipe, buf) & PIPE_REFERENCED_FOR_WRITE)
141       vgFlush();
142
143    pipe_buffer_read(pipe->screen, buf, offset, size, data);
144 }
145
146 static INLINE void
147 st_no_flush_pipe_buffer_read(struct vg_context *st,
148                              struct pipe_buffer *buf,
149                              unsigned int offset,
150                              unsigned int size,
151                              void * data)
152 {
153    pipe_buffer_read(st->pipe->screen, buf, offset, size, data);
154 }
155
156 #endif
157