1 /* 2 * Copyright (c) 2007 Ivan Leben 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library in the file COPYING; 16 * if not, write to the Free Software Foundation, Inc., 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 * 19 */ 20 21 #ifndef __SHCONTEXT_H 22 #define __SHCONTEXT_H 23 24 #include "shDefs.h" 25 #include "shVectors.h" 26 #include "shArrays.h" 27 #include "shPath.h" 28 #include "shPaint.h" 29 #include "shImage.h" 30 31 /*------------------------------------------------ 32 * VGContext object 33 *------------------------------------------------*/ 34 35 typedef enum 36 { 37 SH_RESOURCE_INVALID = 0, 38 SH_RESOURCE_PATH = 1, 39 SH_RESOURCE_PAINT = 2, 40 SH_RESOURCE_IMAGE = 3 41 } SHResourceType; 42 43 typedef struct 44 { 45 /* Surface info (since no EGL yet) */ 46 SHint surfaceWidth; 47 SHint surfaceHeight; 48 49 /* GetString info */ 50 char vendor[256]; 51 char renderer[256]; 52 char version[256]; 53 char extensions[256]; 54 55 /* Mode settings */ 56 VGMatrixMode matrixMode; 57 VGFillRule fillRule; 58 VGImageQuality imageQuality; 59 VGRenderingQuality renderingQuality; 60 VGBlendMode blendMode; 61 VGImageMode imageMode; 62 63 /* Scissor rectangles */ 64 SHRectArray scissor; 65 VGboolean scissoring; 66 VGboolean masking; 67 68 /* Stroke parameters */ 69 SHfloat strokeLineWidth; 70 VGCapStyle strokeCapStyle; 71 VGJoinStyle strokeJoinStyle; 72 SHfloat strokeMiterLimit; 73 SHFloatArray strokeDashPattern; 74 SHfloat strokeDashPhase; 75 VGboolean strokeDashPhaseReset; 76 77 /* Edge fill color for vgConvolve and pattern paint */ 78 SHColor tileFillColor; 79 80 /* Color for vgClear */ 81 SHColor clearColor; 82 83 /* Color components layout inside pixel */ 84 VGPixelLayout pixelLayout; 85 86 /* Source format for image filters */ 87 VGboolean filterFormatLinear; 88 VGboolean filterFormatPremultiplied; 89 VGbitfield filterChannelMask; 90 91 /* Matrices */ 92 SHMatrix3x3 pathTransform; 93 SHMatrix3x3 imageTransform; 94 SHMatrix3x3 fillTransform; 95 SHMatrix3x3 strokeTransform; 96 97 /* Paints */ 98 SHPaint* fillPaint; 99 SHPaint* strokePaint; 100 SHPaint defaultPaint; 101 102 VGErrorCode error; 103 104 /* Resources */ 105 SHPathArray paths; 106 SHPaintArray paints; 107 SHImageArray images; 108 109 /* Pointers to extensions */ 110 SHint isGLAvailable_ClampToEdge; 111 SHint isGLAvailable_MirroredRepeat; 112 SHint isGLAvailable_Multitexture; 113 SHint isGLAvailable_TextureNonPowerOfTwo; 114 SH_PGLACTIVETEXTURE pglActiveTexture; 115 SH_PGLMULTITEXCOORD1F pglMultiTexCoord1f; 116 SH_PGLMULTITEXCOORD2F pglMultiTexCoord2f; 117 118 } VGContext; 119 120 void VGContext_ctor(VGContext *c); 121 void VGContext_dtor(VGContext *c); 122 void shSetError(VGContext *c, VGErrorCode e); 123 SHint shIsValidPath(VGContext *c, VGHandle h); 124 SHint shIsValidPaint(VGContext *c, VGHandle h); 125 SHint shIsValidImage(VGContext *c, VGHandle h); 126 SHResourceType shGetResourceType(VGContext *c, VGHandle h); 127 VGContext* shGetContext(); 128 129 /*---------------------------------------------------- 130 * TODO: Add mutex locking/unlocking to these macros 131 * to assure sequentiallity in multithreading. 132 *----------------------------------------------------*/ 133 134 #define VG_NO_RETVAL 135 136 #define VG_GETCONTEXT(RETVAL) \ 137 VGContext *context = shGetContext(); \ 138 if (!context) return RETVAL; 139 140 #define VG_RETURN(RETVAL) \ 141 { return RETVAL; } 142 143 #define VG_RETURN_ERR(ERRORCODE, RETVAL) \ 144 { shSetError(context,ERRORCODE); return RETVAL; } 145 146 #define VG_RETURN_ERR_IF(COND, ERRORCODE, RETVAL) \ 147 { if (COND) {shSetError(context,ERRORCODE); return RETVAL;} } 148 149 /*----------------------------------------------------------- 150 * Same macros but no mutex handling - used by sub-functions 151 *-----------------------------------------------------------*/ 152 153 #define SH_NO_RETVAL 154 155 #define SH_GETCONTEXT(RETVAL) \ 156 VGContext *context = shGetContext(); \ 157 if (!context) return RETVAL; 158 159 #define SH_RETURN(RETVAL) \ 160 { return RETVAL; } 161 162 #define SH_RETURN_ERR(ERRORCODE, RETVAL) \ 163 { shSetError(context,ERRORCODE); return RETVAL; } 164 165 #define SH_RETURN_ERR_IF(COND, ERRORCODE, RETVAL) \ 166 { if (COND) {shSetError(context,ERRORCODE); return RETVAL;} } 167 168 169 #endif /* __SHCONTEXT_H */ 170