1 /**************************************************************************
3 * Copyright 2009 Younes Manton.
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 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.
26 **************************************************************************/
28 /* directly referenced from target Makefile, because of X dependencies */
32 #include "pipe/p_state.h"
34 #include "util/u_memory.h"
35 #include "util/u_format.h"
36 #include "util/u_inlines.h"
38 #include "state_tracker/xlib_sw_winsys.h"
39 #include "softpipe/sp_public.h"
41 #include "vl/vl_compositor.h"
42 #include "vl/vl_winsys.h"
46 struct vl_screen base
;
50 struct xlib_drawable xdraw
;
51 struct pipe_resource
*tex
;
52 struct u_rect dirty_area
;
56 vl_screen_texture_from_drawable(struct vl_screen
*vscreen
, Drawable drawable
)
58 struct vl_xsp_screen
*xsp_screen
= (struct vl_xsp_screen
*)vscreen
;
61 unsigned int width
, height
;
62 unsigned int border_width
;
64 struct pipe_resource templat
;
67 assert(drawable
!= None
);
69 if (XGetGeometry(xsp_screen
->display
, drawable
, &root
, &x
, &y
, &width
, &height
, &border_width
, &depth
) == BadDrawable
)
72 xsp_screen
->xdraw
.drawable
= drawable
;
74 if (xsp_screen
->tex
) {
75 if (xsp_screen
->tex
->width0
== width
&& xsp_screen
->tex
->height0
== height
)
76 return xsp_screen
->tex
;
77 pipe_resource_reference(&xsp_screen
->tex
, NULL
);
78 vl_compositor_reset_dirty_area(&xsp_screen
->dirty_area
);
81 memset(&templat
, 0, sizeof(struct pipe_resource
));
82 templat
.target
= PIPE_TEXTURE_2D
;
83 /* XXX: Need to figure out drawable's format */
84 templat
.format
= PIPE_FORMAT_B8G8R8X8_UNORM
;
85 templat
.last_level
= 0;
86 templat
.width0
= width
;
87 templat
.height0
= height
;
89 templat
.usage
= PIPE_USAGE_DEFAULT
;
90 templat
.bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_DISPLAY_TARGET
;
93 xsp_screen
->xdraw
.depth
= 24/*util_format_get_blocksizebits(templat.format) /
94 util_format_get_blockwidth(templat.format)*/;
96 pipe_resource_reference(&xsp_screen
->tex
, vscreen
->pscreen
->resource_create(vscreen
->pscreen
, &templat
));
97 return xsp_screen
->tex
;
101 vl_screen_get_dirty_area(struct vl_screen
*vscreen
)
103 struct vl_xsp_screen
*xsp_screen
= (struct vl_xsp_screen
*)vscreen
;
104 return &xsp_screen
->dirty_area
;
108 vl_screen_get_timestamp(struct vl_screen
*vscreen
, Drawable drawable
)
111 gettimeofday(&tv
, NULL
);
112 return (uint64_t)tv
.tv_sec
* 1000000000LL + (uint64_t)tv
.tv_usec
* 1000LL;
116 vl_screen_set_next_timestamp(struct vl_screen
*vscreen
, uint64_t stamp
)
118 /* not supported on softpipe and so only a dummy */
122 vl_screen_get_private(struct vl_screen
*vscreen
)
124 struct vl_xsp_screen
*xsp_screen
= (struct vl_xsp_screen
*)vscreen
;
125 return &xsp_screen
->xdraw
;
129 vl_screen_create(Display
*display
, int screen
)
131 struct vl_xsp_screen
*xsp_screen
;
132 struct sw_winsys
*winsys
;
136 xsp_screen
= CALLOC_STRUCT(vl_xsp_screen
);
140 winsys
= xlib_create_sw_winsys(display
);
146 xsp_screen
->base
.pscreen
= softpipe_create_screen(winsys
);
147 if (!xsp_screen
->base
.pscreen
) {
148 winsys
->destroy(winsys
);
153 xsp_screen
->display
= display
;
154 xsp_screen
->screen
= screen
;
155 xsp_screen
->xdraw
.visual
= XDefaultVisual(display
, screen
);
156 vl_compositor_reset_dirty_area(&xsp_screen
->dirty_area
);
158 return &xsp_screen
->base
;
161 void vl_screen_destroy(struct vl_screen
*vscreen
)
163 struct vl_xsp_screen
*xsp_screen
= (struct vl_xsp_screen
*)vscreen
;
167 pipe_resource_reference(&xsp_screen
->tex
, NULL
);
168 vscreen
->pscreen
->destroy(vscreen
->pscreen
);