1 /**********************************************************
2 * Copyright 2009-2011 VMware, Inc. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 *********************************************************
26 * Zack Rusin <zackr-at-vmware-dot-com>
27 * Thomas Hellstrom <thellstrom-at-vmware-dot-com>
30 #include "xa_context.h"
32 #include "util/u_inlines.h"
33 #include "util/u_sampler.h"
34 #include "util/u_surface.h"
35 #include "cso_cache/cso_context.h"
38 xa_yuv_bind_blend_state(struct xa_context
*r
)
40 struct pipe_blend_state blend
;
42 memset(&blend
, 0, sizeof(struct pipe_blend_state
));
43 blend
.rt
[0].blend_enable
= 0;
44 blend
.rt
[0].colormask
= PIPE_MASK_RGBA
;
47 blend
.rt
[0].rgb_src_factor
= PIPE_BLENDFACTOR_ONE
;
48 blend
.rt
[0].alpha_src_factor
= PIPE_BLENDFACTOR_ONE
;
49 blend
.rt
[0].rgb_dst_factor
= PIPE_BLENDFACTOR_ZERO
;
50 blend
.rt
[0].alpha_dst_factor
= PIPE_BLENDFACTOR_ZERO
;
52 cso_set_blend(r
->cso
, &blend
);
56 xa_yuv_bind_shaders(struct xa_context
*r
)
58 unsigned vs_traits
= 0, fs_traits
= 0;
59 struct xa_shader shader
;
64 shader
= xa_shaders_get(r
->shaders
, vs_traits
, fs_traits
);
65 cso_set_vertex_shader_handle(r
->cso
, shader
.vs
);
66 cso_set_fragment_shader_handle(r
->cso
, shader
.fs
);
70 xa_yuv_bind_samplers(struct xa_context
*r
, struct xa_surface
*yuv
[])
72 struct pipe_sampler_state
*samplers
[3];
73 struct pipe_sampler_state sampler
;
74 struct pipe_sampler_view view_templ
;
77 memset(&sampler
, 0, sizeof(struct pipe_sampler_state
));
79 sampler
.wrap_s
= PIPE_TEX_WRAP_CLAMP
;
80 sampler
.wrap_t
= PIPE_TEX_WRAP_CLAMP
;
81 sampler
.min_img_filter
= PIPE_TEX_FILTER_LINEAR
;
82 sampler
.mag_img_filter
= PIPE_TEX_FILTER_LINEAR
;
83 sampler
.min_mip_filter
= PIPE_TEX_MIPFILTER_NEAREST
;
84 sampler
.normalized_coords
= 1;
86 for (i
= 0; i
< 3; ++i
) {
87 samplers
[i
] = &sampler
;
88 u_sampler_view_default_template(&view_templ
, yuv
[i
]->tex
,
91 r
->bound_sampler_views
[i
] =
92 r
->pipe
->create_sampler_view(r
->pipe
, yuv
[i
]->tex
, &view_templ
);
94 r
->num_bound_samplers
= 3;
95 cso_set_samplers(r
->cso
, PIPE_SHADER_FRAGMENT
, 3, (const struct pipe_sampler_state
**)samplers
);
96 cso_set_sampler_views(r
->cso
, PIPE_SHADER_FRAGMENT
, 3, r
->bound_sampler_views
);
100 xa_yuv_fs_constants(struct xa_context
*r
, const float conversion_matrix
[])
102 const int param_bytes
= 16 * sizeof(float);
104 renderer_set_constants(r
, PIPE_SHADER_FRAGMENT
,
105 conversion_matrix
, param_bytes
);
109 xa_yuv_planar_blit(struct xa_context
*r
,
119 unsigned int num_boxes
,
120 const float conversion_matrix
[],
121 struct xa_surface
*dst
, struct xa_surface
*yuv
[])
127 if (dst_w
== 0 || dst_h
== 0)
130 ret
= xa_ctx_srf_create(r
, dst
);
131 if (ret
!= XA_ERR_NONE
)
132 return -XA_ERR_NORES
;
134 renderer_bind_destination(r
, r
->srf
);
135 xa_yuv_bind_blend_state(r
);
136 xa_yuv_bind_shaders(r
);
137 xa_yuv_bind_samplers(r
, yuv
);
138 xa_yuv_fs_constants(r
, conversion_matrix
);
140 scale_x
= (float)src_w
/ (float)dst_w
;
141 scale_y
= (float)src_h
/ (float)dst_h
;
143 while (num_boxes
--) {
146 int w
= box
->x2
- box
->x1
;
147 int h
= box
->y2
- box
->y1
;
149 xa_scissor_update(r
, x
, y
, box
->x2
, box
->y2
);
151 (float)src_x
+ scale_x
* (x
- dst_x
),
152 (float)src_y
+ scale_y
* (y
- dst_y
),
153 scale_x
* w
, scale_y
* h
, x
, y
, w
, h
, yuv
);
159 xa_ctx_sampler_views_destroy(r
);
160 xa_ctx_srf_destroy(r
);