| 1 | /* |
| 2 | Copyright (c) 2012, Broadcom Europe Ltd |
| 3 | All rights reserved. |
| 4 | |
| 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. |
| 15 | |
| 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. |
| 26 | */ |
| 27 | |
| 28 | #ifndef VG_CLIENT_H |
| 29 | #define VG_CLIENT_H |
| 30 | |
| 31 | #include "interface/khronos/common/khrn_client.h" |
| 32 | #include "interface/khronos/common/khrn_client_platform.h" |
| 33 | #include "interface/khronos/common/khrn_client_pointermap.h" |
| 34 | #include "interface/khronos/common/khrn_client_vector.h" |
| 35 | |
| 36 | #include "interface/khronos/egl/egl_client_context.h" |
| 37 | |
| 38 | #include "interface/khronos/include/EGL/egl.h" |
| 39 | #include "interface/khronos/include/EGL/eglext.h" |
| 40 | #include "interface/khronos/include/VG/openvg.h" |
| 41 | |
| 42 | #include "interface/khronos/vg/vg_int_config.h" |
| 43 | #include "interface/khronos/vg/vg_int.h" |
| 44 | #include "interface/khronos/vg/vg_int_mat3x3.h" |
| 45 | |
| 46 | /* should be after EGL/eglext.h */ |
| 47 | #if EGL_BRCM_global_image && EGL_KHR_image |
| 48 | #include "interface/khronos/common/khrn_client_global_image_map.h" |
| 49 | #endif |
| 50 | |
| 51 | /****************************************************************************** |
| 52 | shared state |
| 53 | ******************************************************************************/ |
| 54 | |
| 55 | #define VG_CLIENT_STEMS_COUNT_MAX 64 |
| 56 | |
| 57 | typedef struct { |
| 58 | VG_CLIENT_OBJECT_TYPE_T object_type; |
| 59 | #if EGL_BRCM_global_image && EGL_KHR_image |
| 60 | KHRN_GLOBAL_IMAGE_MAP_T glyph_global_images; |
| 61 | #endif |
| 62 | } VG_CLIENT_FONT_T; |
| 63 | |
| 64 | typedef struct { |
| 65 | VG_CLIENT_OBJECT_TYPE_T object_type; |
| 66 | VGImageFormat format; |
| 67 | VGint width; |
| 68 | VGint height; |
| 69 | #if EGL_BRCM_global_image && EGL_KHR_image |
| 70 | VGuint global_image_id[2]; |
| 71 | #endif |
| 72 | } VG_CLIENT_IMAGE_T; |
| 73 | |
| 74 | typedef struct { |
| 75 | VG_CLIENT_OBJECT_TYPE_T object_type; |
| 76 | VGint width; |
| 77 | VGint height; |
| 78 | } VG_CLIENT_MASK_LAYER_T; |
| 79 | |
| 80 | typedef struct { |
| 81 | VGfloat linear[4]; |
| 82 | VGfloat radial[5]; |
| 83 | VGColorRampSpreadMode ramp_spread_mode; |
| 84 | bool ramp_pre; |
| 85 | VGfloat *ramp_stops; /* NULL when count is 0 */ |
| 86 | VGuint ramp_stops_count; |
| 87 | } VG_CLIENT_PAINT_GRADIENT_T; |
| 88 | |
| 89 | typedef struct { |
| 90 | VG_CLIENT_OBJECT_TYPE_T object_type; |
| 91 | VGPaintType type; |
| 92 | VGfloat color[4]; |
| 93 | VG_CLIENT_PAINT_GRADIENT_T *gradient; /* allocated when required */ |
| 94 | VGTilingMode pattern_tiling_mode; |
| 95 | VGImage pattern; |
| 96 | #if EGL_BRCM_global_image && EGL_KHR_image |
| 97 | VGuint pattern_global_image_id[2]; |
| 98 | #endif |
| 99 | } VG_CLIENT_PAINT_T; |
| 100 | |
| 101 | typedef struct { |
| 102 | VG_CLIENT_OBJECT_TYPE_T object_type; |
| 103 | VGint format; |
| 104 | VGPathDatatype datatype; |
| 105 | VGfloat scale; |
| 106 | VGfloat bias; |
| 107 | VGbitfield caps; |
| 108 | KHRN_VECTOR_T segments; |
| 109 | } VG_CLIENT_PATH_T; |
| 110 | |
| 111 | typedef struct { |
| 112 | VGuint ref_count; /* we only read/write this when holding the client mutex */ |
| 113 | |
| 114 | PLATFORM_MUTEX_T mutex; /* just one mutex for everything else in here */ |
| 115 | |
| 116 | VGuint stems_count; |
| 117 | VGHandle stems[VG_CLIENT_STEMS_COUNT_MAX]; |
| 118 | |
| 119 | KHRN_POINTER_MAP_T objects; |
| 120 | } VG_CLIENT_SHARED_STATE_T; |
| 121 | |
| 122 | extern VG_CLIENT_SHARED_STATE_T *vg_client_shared_state_alloc(void); |
| 123 | extern void vg_client_shared_state_free(VG_CLIENT_SHARED_STATE_T *shared_state); |
| 124 | |
| 125 | static INLINE void vg_client_shared_state_acquire(VG_CLIENT_SHARED_STATE_T *shared_state) |
| 126 | { |
| 127 | ++shared_state->ref_count; |
| 128 | } |
| 129 | |
| 130 | static INLINE void vg_client_shared_state_release(VG_CLIENT_SHARED_STATE_T *shared_state) |
| 131 | { |
| 132 | if (--shared_state->ref_count == 0) { |
| 133 | vg_client_shared_state_free(shared_state); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | /****************************************************************************** |
| 138 | state |
| 139 | ******************************************************************************/ |
| 140 | |
| 141 | /* |
| 142 | Called just before a rendering command (i.e. anything which could modify |
| 143 | the draw surface) is executed |
| 144 | */ |
| 145 | typedef void (*VG_RENDER_CALLBACK_T)(void); |
| 146 | |
| 147 | /* |
| 148 | Called just after rendering has been compeleted (i.e. flush or finish). |
| 149 | wait should be true for finish-like behaviour, false for flush-like |
| 150 | behaviour |
| 151 | */ |
| 152 | typedef void (*VG_FLUSH_CALLBACK_T)(bool wait); |
| 153 | |
| 154 | typedef struct { |
| 155 | VG_MAT3X3_T client; |
| 156 | VG_MAT3X3_T server; |
| 157 | } VG_MAT3X3_SYNC_T; |
| 158 | |
| 159 | typedef struct { |
| 160 | VG_CLIENT_SHARED_STATE_T *shared_state; |
| 161 | |
| 162 | VG_RENDER_CALLBACK_T render_callback; |
| 163 | VG_FLUSH_CALLBACK_T flush_callback; |
| 164 | |
| 165 | /* |
| 166 | matrices stored on client |
| 167 | updates sent to server as necessary |
| 168 | */ |
| 169 | |
| 170 | VGMatrixMode matrix_mode; |
| 171 | VG_MAT3X3_SYNC_T matrices[5]; |
| 172 | |
| 173 | /* |
| 174 | state cached on client-side to allow dropping of redundant calls |
| 175 | */ |
| 176 | |
| 177 | VGFillRule fill_rule; |
| 178 | VGfloat stroke_line_width; |
| 179 | VGCapStyle stroke_cap_style; |
| 180 | VGJoinStyle stroke_join_style; |
| 181 | VGfloat stroke_miter_limit; |
| 182 | VGfloat stroke_dash_pattern[VG_CONFIG_MAX_DASH_COUNT]; |
| 183 | VGuint stroke_dash_pattern_count; |
| 184 | VGfloat stroke_dash_phase; |
| 185 | bool stroke_dash_phase_reset; |
| 186 | VGImageQuality image_quality; |
| 187 | VGImageMode image_mode; |
| 188 | |
| 189 | bool scissoring; |
| 190 | VGint scissor_rects[VG_CONFIG_MAX_SCISSOR_RECTS * 4]; |
| 191 | VGuint scissor_rects_count; |
| 192 | |
| 193 | VGRenderingQuality rendering_quality; |
| 194 | |
| 195 | VGPaint fill_paint; |
| 196 | VGPaint stroke_paint; |
| 197 | VGfloat tile_fill_color[4]; |
| 198 | VGfloat clear_color[4]; |
| 199 | |
| 200 | bool color_transform; |
| 201 | VGfloat color_transform_values[8]; |
| 202 | |
| 203 | VGBlendMode blend_mode; |
| 204 | bool masking; |
| 205 | |
| 206 | bool filter_format_linear; |
| 207 | bool filter_format_pre; |
| 208 | VGuint filter_channel_mask; |
| 209 | |
| 210 | VGPixelLayout pixel_layout; |
| 211 | } VG_CLIENT_STATE_T; |
| 212 | |
| 213 | extern VG_CLIENT_STATE_T *vg_client_state_alloc(VG_CLIENT_SHARED_STATE_T *shared_state); |
| 214 | extern void vg_client_state_free(VG_CLIENT_STATE_T *state); |
| 215 | |
| 216 | static INLINE VG_CLIENT_STATE_T *vg_get_client_state(CLIENT_THREAD_STATE_T *thread) |
| 217 | { |
| 218 | EGL_CONTEXT_T *context = thread->openvg.context; |
| 219 | if (context) { |
| 220 | vcos_assert(context->type == OPENVG); |
| 221 | return (VG_CLIENT_STATE_T *)context->state; |
| 222 | } else { |
| 223 | return NULL; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | #define VG_GET_CLIENT_STATE(thread) vg_get_client_state(thread) |
| 228 | |
| 229 | #endif |
| 230 | |