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 **************************************************************************/
28 * Management of pipe objects (surface / pipe / fences) used by DRI1 and DRISW.
30 * Author: Keith Whitwell <keithw@vmware.com>
31 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
34 #include "util/u_inlines.h"
35 #include "pipe/p_context.h"
37 #include "dri_screen.h"
38 #include "dri_context.h"
39 #include "dri_drawable.h"
40 #include "dri1_helper.h"
42 struct pipe_fence_handle
*
43 dri1_swap_fences_pop_front(struct dri_drawable
*draw
)
45 struct pipe_screen
*screen
= dri_screen(draw
->sPriv
)->pipe_screen
;
46 struct pipe_fence_handle
*fence
= NULL
;
48 if (draw
->cur_fences
>= draw
->desired_fences
) {
49 screen
->fence_reference(screen
, &fence
, draw
->swap_fences
[draw
->tail
]);
50 screen
->fence_reference(screen
, &draw
->swap_fences
[draw
->tail
++], NULL
);
52 draw
->tail
&= DRI_SWAP_FENCES_MASK
;
58 dri1_swap_fences_push_back(struct dri_drawable
*draw
,
59 struct pipe_fence_handle
*fence
)
61 struct pipe_screen
*screen
= dri_screen(draw
->sPriv
)->pipe_screen
;
66 if (draw
->cur_fences
< DRI_SWAP_FENCES_MAX
) {
68 screen
->fence_reference(screen
, &draw
->swap_fences
[draw
->head
++],
70 draw
->head
&= DRI_SWAP_FENCES_MASK
;
75 dri1_swap_fences_clear(struct dri_drawable
*drawable
)
77 struct pipe_screen
*screen
= dri_screen(drawable
->sPriv
)->pipe_screen
;
78 struct pipe_fence_handle
*fence
;
80 while (drawable
->cur_fences
) {
81 fence
= dri1_swap_fences_pop_front(drawable
);
82 screen
->fence_reference(screen
, &fence
, NULL
);
87 dri1_get_pipe_surface(struct dri_drawable
*drawable
, struct pipe_resource
*ptex
)
89 struct pipe_screen
*pipe_screen
= dri_screen(drawable
->sPriv
)->pipe_screen
;
90 struct pipe_surface
*psurf
= drawable
->dri1_surface
;
92 if (!psurf
|| psurf
->texture
!= ptex
) {
93 pipe_surface_reference(&drawable
->dri1_surface
, NULL
);
95 drawable
->dri1_surface
= pipe_screen
->get_tex_surface(pipe_screen
,
96 ptex
, 0, 0, 0, PIPE_BIND_BLIT_SOURCE
);
98 psurf
= drawable
->dri1_surface
;
105 dri1_destroy_pipe_surface(struct dri_drawable
*drawable
)
107 pipe_surface_reference(&drawable
->dri1_surface
, NULL
);
110 struct pipe_context
*
111 dri1_get_pipe_context(struct dri_screen
*screen
)
113 struct pipe_context
*pipe
= screen
->dri1_pipe
;
117 screen
->pipe_screen
->context_create(screen
->pipe_screen
, NULL
);
118 pipe
= screen
->dri1_pipe
;
125 dri1_destroy_pipe_context(struct dri_screen
*screen
)
127 if (screen
->dri1_pipe
)
128 screen
->dri1_pipe
->destroy(screen
->dri1_pipe
);