1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
29 * Functions for checking if buffers/textures are referenced when we need
30 * to read/write from/to them. Flush when needed.
36 #include "vg_context.h"
38 #include "pipe/p_context.h"
39 #include "pipe/p_screen.h"
40 #include "pipe/p_defines.h"
41 #include "pipe/p_inlines.h"
42 #include "pipe/p_state.h"
44 static INLINE
struct pipe_transfer
*
45 st_cond_flush_get_tex_transfer(struct vg_context
*st
,
46 struct pipe_texture
*pt
,
50 enum pipe_transfer_usage usage
,
51 unsigned int x
, unsigned int y
,
52 unsigned int w
, unsigned int h
)
54 struct pipe_screen
*screen
= st
->pipe
->screen
;
55 struct pipe_context
*pipe
= st
->pipe
;
57 pipe
->is_texture_referenced(pipe
, pt
, face
, level
);
59 if (referenced
&& ((referenced
& PIPE_REFERENCED_FOR_WRITE
) ||
60 (usage
& PIPE_TRANSFER_WRITE
)))
63 return screen
->get_tex_transfer(screen
, pt
, face
, level
, zslice
, usage
,
67 static INLINE
struct pipe_transfer
*
68 st_no_flush_get_tex_transfer(struct vg_context
*st
,
69 struct pipe_texture
*pt
,
73 enum pipe_transfer_usage usage
,
74 unsigned int x
, unsigned int y
,
75 unsigned int w
, unsigned int h
)
77 struct pipe_screen
*screen
= st
->pipe
->screen
;
79 return screen
->get_tex_transfer(screen
, pt
, face
, level
,
80 zslice
, usage
, x
, y
, w
, h
);
84 st_cond_flush_pipe_buffer_map(struct vg_context
*st
,
85 struct pipe_buffer
*buf
,
86 unsigned int map_flags
)
88 struct pipe_context
*pipe
= st
->pipe
;
89 unsigned int referenced
= pipe
->is_buffer_referenced(pipe
, buf
);
91 if (referenced
&& ((referenced
& PIPE_REFERENCED_FOR_WRITE
) ||
92 (map_flags
& PIPE_BUFFER_USAGE_CPU_WRITE
)))
95 return pipe_buffer_map(pipe
->screen
, buf
, map_flags
);
99 st_no_flush_pipe_buffer_map(struct vg_context
*st
,
100 struct pipe_buffer
*buf
,
101 unsigned int map_flags
)
103 return pipe_buffer_map(st
->pipe
->screen
, buf
, map_flags
);
108 st_cond_flush_pipe_buffer_write(struct vg_context
*st
,
109 struct pipe_buffer
*buf
,
114 struct pipe_context
*pipe
= st
->pipe
;
116 if (pipe
->is_buffer_referenced(pipe
, buf
))
119 pipe_buffer_write(pipe
->screen
, buf
, offset
, size
, data
);
123 st_no_flush_pipe_buffer_write(struct vg_context
*st
,
124 struct pipe_buffer
*buf
,
129 pipe_buffer_write(st
->pipe
->screen
, buf
, offset
, size
, data
);
133 st_cond_flush_pipe_buffer_read(struct vg_context
*st
,
134 struct pipe_buffer
*buf
,
139 struct pipe_context
*pipe
= st
->pipe
;
141 if (pipe
->is_buffer_referenced(pipe
, buf
) & PIPE_REFERENCED_FOR_WRITE
)
144 pipe_buffer_read(pipe
->screen
, buf
, offset
, size
, data
);
148 st_no_flush_pipe_buffer_read(struct vg_context
*st
,
149 struct pipe_buffer
*buf
,
154 pipe_buffer_read(st
->pipe
->screen
, buf
, offset
, size
, data
);