2 Copyright (c) 2012, Broadcom Europe Ltd
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the copyright holder nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "interface/khronos/common/khrn_int_common.h"
30 #include "interface/khronos/common/khrn_int_util.h"
31 #include "interface/khronos/include/GLES/gl.h"
32 #include "interface/khronos/include/GLES2/gl2.h"
33 #include "interface/khronos/include/GLES2/gl2ext.h"
36 int32_t *min_x0_io, int32_t *l0_io,
37 int32_t min_x1, int32_t l1)
44 vcos_assert((*l0_io >= 0) && (l1 >= 0));
49 max_x0 = _adds(min_x0, l0);
52 if (min_x0 < min_x1) {
55 if (max_x0 > max_x1) {
59 l0 = _max(_subs(max_x0, min_x0), 0);
61 *min_x0_io = (l0 == 0) ? min_x1 : min_x0;
65 void khrn_clip_range2(
66 int32_t *min_ax0_io, int32_t *min_bx0_io, int32_t *l0_io,
67 int32_t min_ax1, int32_t al1,
68 int32_t min_bx1, int32_t bl1)
78 vcos_assert((*l0_io >= 0) && (al1 >= 0) && (bl1 >= 0));
80 min_ax0 = *min_ax0_io;
81 min_bx0 = *min_bx0_io;
84 l0 = _adds(_max(min_ax0, min_bx0), l0) - _max(min_ax0, min_bx0); /* clamp l0 to avoid overflow */
85 max_ax0 = min_ax0 + l0;
86 max_bx0 = min_bx0 + l0;
87 max_ax1 = min_ax1 + al1;
88 max_bx1 = min_bx1 + bl1;
91 if any of the following _adds/_subs overflow, we will get either
92 min_ax0 >= max_ax0 or min_bx0 >= max_bx0, so l0 will be 0
95 if (min_ax0 < min_ax1) {
96 min_bx0 = _adds(min_bx0, _subs(min_ax1, min_ax0));
99 if (max_ax0 > max_ax1) {
100 max_bx0 = _subs(max_bx0, _subs(max_ax0, max_ax1));
104 if (min_bx0 < min_bx1) {
105 min_ax0 = _adds(min_ax0, _subs(min_bx1, min_bx0));
108 if (max_bx0 > max_bx1) {
109 max_ax0 = _subs(max_ax0, _subs(max_bx0, max_bx1));
113 l0 = _max(_subs(max_ax0, min_ax0), 0);
114 vcos_assert(l0 == _max(_subs(max_bx0, min_bx0), 0));
116 *min_ax0_io = (l0 == 0) ? min_ax1 : min_ax0;
117 *min_bx0_io = (l0 == 0) ? min_bx1 : min_bx0;
122 int32_t *x0, int32_t *y0, int32_t *w0, int32_t *h0,
123 int32_t x1, int32_t y1, int32_t w1, int32_t h1)
125 khrn_clip_range(x0, w0, x1, w1);
126 khrn_clip_range(y0, h0, y1, h1);
129 void khrn_clip_rect2(
130 int32_t *ax0, int32_t *ay0, int32_t *bx0, int32_t *by0, int32_t *w0, int32_t *h0,
131 int32_t ax1, int32_t ay1, int32_t aw1, int32_t ah1,
132 int32_t bx1, int32_t by1, int32_t bw1, int32_t bh1)
134 khrn_clip_range2(ax0, bx0, w0, ax1, aw1, bx1, bw1);
135 khrn_clip_range2(ay0, by0, h0, ay1, ah1, by1, bh1);
138 int khrn_get_type_size(int type)
140 switch ((GLenum)type) {
142 case GL_UNSIGNED_BYTE:
145 case GL_UNSIGNED_SHORT:
146 case GL_HALF_FLOAT_OES:
159 void khrn_barrier(void)