1 /* 2 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 /** 27 * \file PiscesRenderer.h 28 * Renderer struct declaration. This file is the main PISCES include. I.e. all 29 * PISCES wrappers, should include this file. It provides C - high level API. 30 */ 31 32 #ifndef PISCES_RENDERER_H 33 #define PISCES_RENDERER_H 34 35 #ifdef ANDROID_NDK 36 #include <sys/types.h> 37 #endif 38 #include <PiscesDefs.h> 39 #include <PiscesSurface.h> 40 #include <PiscesTransform.h> 41 42 #include "com_sun_pisces_RendererBase.h" 43 44 /** 45 * @defgroup CompositingRules Compositing rules supported by PISCES 46 * When drawing two objects to one pixel area, there are several possibilities 47 * how composite color is made of source and destination contributions. 48 * Objects can overlap pixel fully and/or partialy. One object could be above 49 * the second one and they both can be partialy or fully transparent (alpha). 50 * The way, we count composite color and alpha from theirs contributions is 51 * called composite rule (Porter-Duff). 52 * @def COMPOSITE_CLEAR 53 * @ingroup CompositingRules 54 * Compositing rule COMPOSITE_CLEAR. This rule applied to destination pixel sets 55 * its color to 0x00000000 - transparent black - regardless to source color. 56 * @see renderer_setCompositeRule(Renderer *, jint), 57 * renderer_setComposite(Renderer *, jint, jfloat) 58 * @def COMPOSITE_SRC 59 * @ingroup CompositingRules 60 * Compositing rule COMPOSITE_SRC. This rule applied to destination pixel sets 61 * its color to source color - regardless to previous color of destination 62 * pixel. 63 * @see renderer_setCompositeRule(Renderer *, jint), 64 * renderer_setComposite(Renderer *, jint, jfloat) 65 * @def COMPOSITE_SRC_OVER 66 * @ingroup CompositingRules 67 * Compositing rule COMPOSITE_SRC_OVER. This rule is kind of intuitive. When we 68 * look through transparent green glass bottle at some object, we can see 69 * mixture of glass and objects colors. Composite color is alpha-weigth average 70 * of source and destination. 71 * @see renderer_setCompositeRule(Renderer *, jint), 72 * renderer_setComposite(Renderer *, jint, jfloat) 73 */ 74 //Compositing rules 75 #define COMPOSITE_CLEAR com_sun_pisces_RendererBase_COMPOSITE_CLEAR 76 #define COMPOSITE_SRC com_sun_pisces_RendererBase_COMPOSITE_SRC 77 #define COMPOSITE_SRC_OVER com_sun_pisces_RendererBase_COMPOSITE_SRC_OVER 78 79 /** 80 * @defgroup WindingRules Winding rules - shape interior 81 * Winding rule determines what part of shape is determined as interior. This is 82 * important to determine what part of shape to fill. 83 * @def WIND_EVEN_ODD 84 * @ingroup WindingRules 85 * This define represents the even-odd winding rule. To see how this winding 86 * rule works, draw any closed shape and draw a line through the entire shape. 87 * Each time the line crosses the shape's border, increment a counter. When the 88 * counter is even, the line is outside the shape. When the counter is odd, 89 * the line is in the interior of the shape. 90 * @def WIND_NON_ZERO 91 * @ingroup WindingRules 92 * This define represents the non-zero winding rule. Similar to even-odd. 93 * We draw line through the entire shape. If intersecting edge is drawn from 94 * left-to-right, we add 1 to counter. If it goes from right to left we add -1. 95 * Everytime the counter is not zero, we assume it's interior part of shape. 96 */ 97 #define WIND_NON_ZERO 1 98 #define WIND_EVEN_ODD 0 99 100 //Paint methods 101 /** 102 * @defgroup PaintMethods Paint methods in PISCES 103 * Paint method says what source color should be used while filling shapes. We 104 * can use solid color for every touched pixel, or we can use gradient-fills or 105 * textures. Setting paint method you can draw any primitive (even line or oval) 106 * filled with gradient or texture. 107 * @see setColor 108 * @see setFill 109 * @def PAINT_FLAT_COLOR 110 * @ingroup PaintMethods 111 * Paint method uses flat color. Source color set by setColor() is used. 112 * @see setColor 113 * @def PAINT_LINEAR_GRADIENT 114 * @ingroup PaintMethods 115 * Paint method. Source color value is precalculated linear gradients color. 116 * @see setLinearGradient 117 * @def PAINT_RADIAL_GRADIENT 118 * @ingroup PaintMethods 119 * Paint method. Source color value is precalculated radial gradients color. 120 * @see setRadialGradient 121 * @def PAINT_TEXTURE8888 122 * @def PAINT_TEXTURE565ALPHA 123 * @def PAINT_TEXTURE565NOALPHA 124 * @ingroup PaintMethods 125 * Paint method. Source color value is texture. 126 * @see setTexture 127 */ 128 #define PAINT_FLAT_COLOR 0 129 #define PAINT_LINEAR_GRADIENT 1 130 #define PAINT_RADIAL_GRADIENT 2 131 #define PAINT_TEXTURE8888 4 132 #define PAINT_TEXTURE8888_MULTIPLY 5 133 134 #define IMAGE_MODE_NORMAL com_sun_pisces_RendererBase_IMAGE_MODE_NORMAL 135 #define IMAGE_MODE_MULTIPLY com_sun_pisces_RendererBase_IMAGE_MODE_MULTIPLY 136 137 #define IMAGE_FRAC_EDGE_KEEP com_sun_pisces_RendererBase_IMAGE_FRAC_EDGE_KEEP 138 #define IMAGE_FRAC_EDGE_PAD com_sun_pisces_RendererBase_IMAGE_FRAC_EDGE_PAD 139 #define IMAGE_FRAC_EDGE_TRIM com_sun_pisces_RendererBase_IMAGE_FRAC_EDGE_TRIM 140 141 #define LG_GRADIENT_MAP_SIZE 8 142 #define GRADIENT_MAP_SIZE (1 << LG_GRADIENT_MAP_SIZE) 143 144 #define DEFAULT_INDICES_SIZE (8*292) 145 #define DEFAULT_CROSSINGS_SIZE (8*292*4) 146 #define NUM_ALPHA_ROWS 8 147 #define MIN_QUAD_OPT_WIDTH (100 << 16) 148 149 #define INVALID_RENDERER_SURFACE 16 150 151 /** 152 * @defgroup CycleMethods Gradient cycle methods 153 * Gradient cycle methods. Specifies wheteher to repeat gradient fill in cycle 154 * or not. We will explain possible methods on linear gradient behaviour. 155 * @see setLinearGradient, setRadialGradient 156 * @def CYCLE_NONE 157 * @ingroup CycleMethods 158 * Gradient without repetition. Imagine linear gradient from blue to red color. 159 * Color of start point (line perpendicular to vector(start,end)) will be blue. 160 * Color of end point (line) will be red. Between these two points (lines), 161 * there will be smooth color gradient. Outside gradient area everything will be 162 * blue or red when CYCLE_NONE used. It works similar way with radial gradient. 163 * @def CYCLE_REPEAT 164 * @ingroup CycleMethods 165 * Gradient with repetition. Gradient fill is repeated with period given by 166 * start,end distance. 167 * @def CYCLE_REFLECT 168 * @ingroup CycleMethods 169 * Gradient is repeated. Start and end color in new cycle are swaped. Gradient 170 * fill is repeated with period given by start,end distance. You can imagine 171 * this as if you'd put mirror to end point (line). 172 */ 173 #define CYCLE_NONE 0 174 #define CYCLE_REPEAT 1 175 #define CYCLE_REFLECT 2 176 177 #define NO_MASK 0 178 #define ALPHA_MASK 1 179 #define LCD_ALPHA_MASK 2 180 181 #define TEXTURE_TRANSFORM_IDENTITY 1 182 #define TEXTURE_TRANSFORM_TRANSLATE 2 183 #define TEXTURE_TRANSFORM_SCALE_TRANSLATE 3 184 #define TEXTURE_TRANSFORM_GENERIC 4 185 186 /** 187 * \struct _Renderer 188 * Structure _Renderer encapsulates rendering-state information. Colors, 189 * textures, counted gradient-fills, transformation-matrices, compositing rule, 190 * antialiasing, paint method, surface (destination of our drawing) and much 191 * more is tracked by Renderer. Simply, we can say, Renderer knows HOW AND 192 * WHERE TO DRAW. It is also typedefed as Renderer. 193 * \typedef Renderer 194 * Typedef to struct _Renderer. 195 */ 196 typedef struct _Renderer { 197 198 // Flat color or (Java2D) linear gradient 199 jint _paintMode; 200 jint _prevPaintMode; 201 202 // Current (user set) color 203 jint _ured, _ugreen, _ublue, _ualpha; 204 // Current (internal) color 205 jint _cred, _cgreen, _cblue, _calpha; 206 207 /* 208 * Color and alpha for gradient value g is located in 209 * color map at index (int)(g*scale + bias) 210 */ 211 jint _lgradient_color_888[GRADIENT_MAP_SIZE]; 212 213 jint _colorAlphaMap[16*16 + 1]; 214 jint _paintAlphaMap[256]; 215 216 /** 217 * Switches antialiasing support ON/OFF. 218 * @see To switch antialising ON/OFF, use 219 * renderer_setAntialiasing(Renderer*, antialiasingOn). 220 */ 221 jboolean _antialiasingOn; 222 /** 223 * Current compositing rule. Renderers internal variable. To change it use 224 * renderer_setCompositeRule(Renderer *, jint) or 225 * renderer_setComposite(Renderer *, jint, jfloat). 226 * @see See CompositingRules, renderer_setCompositeRule(Renderer *, jint), 227 * renderer_setComposite(Renderer *, jint, jfloat) 228 */ 229 jint _compositeRule; 230 231 Surface* _surface; 232 233 // Image layout 234 void *_data; 235 jint _width, _height; 236 jint _imageOffset; 237 jint _imageScanlineStride; 238 jint _imagePixelStride; 239 jint _imageType; 240 241 void (*_bl_SourceOverMask)(struct _Renderer *rdr, jint height); 242 void (*_bl_PT_SourceOverMask)(struct _Renderer *rdr, jint height); 243 void (*_bl_SourceMask)(struct _Renderer *rdr, jint height); 244 void (*_bl_PT_SourceMask)(struct _Renderer *rdr, jint height); 245 246 void (*_bl_SourceOverLCDMask)(struct _Renderer *rdr, jint height); 247 void (*_bl_PT_SourceOverLCDMask)(struct _Renderer *rdr, jint height); 248 void (*_bl_SourceLCDMask)(struct _Renderer *rdr, jint height); 249 void (*_bl_PT_SourceLCDMask)(struct _Renderer *rdr, jint height); 250 251 void (*_bl_SourceOverNoMask)(struct _Renderer *rdr, jint height); 252 void (*_bl_PT_SourceOverNoMask)(struct _Renderer *rdr, jint height); 253 void (*_bl_SourceNoMask)(struct _Renderer *rdr, jint height); 254 void (*_bl_PT_SourceNoMask)(struct _Renderer *rdr, jint height); 255 256 void (*_bl_SourceOver)(struct _Renderer *rdr, jint height); 257 void (*_bl_PT_SourceOver)(struct _Renderer *rdr, jint height); 258 void (*_bl_Source)(struct _Renderer *rdr, jint height); 259 void (*_bl_PT_Source)(struct _Renderer *rdr, jint height); 260 261 void (*_el_Source)(struct _Renderer *rdr, jint height, jint frac); 262 void (*_el_SourceOver)(struct _Renderer *rdr, jint height, jint frac); 263 void (*_el_PT_Source)(struct _Renderer *rdr, jint height, jint frac); 264 void (*_el_PT_SourceOver)(struct _Renderer *rdr, jint height, jint frac); 265 266 /** 267 * Pointer to function which clears rectangle - ie. sets rectangle data to 268 * transparent black. Implementations are optimized for concrete surface 269 * types. 270 * @param height height of blitting area 271 * @see renderer_setCompositeRule() 272 */ 273 void (*_bl_Clear)(struct _Renderer *rdr, jint height); 274 void (*_bl_PT_Clear)(struct _Renderer *rdr, jint height); 275 276 /** 277 * Pointer to bliting function. Bliting function is set due to 278 * composite rule and surface type to appropriate optimized function. _bl_SO 279 * is called in paint mode PAINT_FLAT_COLOR - when filling with solid color. 280 * @param height height of blitting area 281 * @see renderer_setCompositeRule() 282 */ 283 void (*_bl)(struct _Renderer *rdr, jint height); 284 /** Pointer to paint bliting function. Bliting function is set due to 285 * composite rule and surface type to appropriate optimized function. 286 * _bl_PT_SO is called in paint mode different from PAINT_FLAT_COLOR, ie. 287 * anytime when filling with gradients or textures. 288 * @param height height of blitting area 289 * @see renderer_setCompositeRule() 290 */ 291 void (*_bl_PT)(struct _Renderer *rdr, jint height); 292 293 void (*_el)(struct _Renderer *rdr, jint height, jint frac); 294 void (*_el_PT)(struct _Renderer *rdr, jint height, jint frac); 295 296 void (*_clearRect)(struct _Renderer *rdr, jint x, jint y, jint w, jint h); 297 void (*_emitRows)(struct _Renderer *rdr, jint height); 298 void (*_emitLine)(struct _Renderer *rdr, jint height, jint frac); 299 void (*_genPaint)(struct _Renderer *rdr, jint height); 300 301 jint _rowNum; 302 jint _alphaWidth; 303 jint _minTouched; 304 jint _maxTouched; 305 jint _currX, _currY; 306 jint _currImageOffset; 307 308 jbyte* alphaMap; 309 jint* _rowAAInt; 310 311 // used for fillRect call - contains original rectangle's X,Y values 312 jint _rectX, _rectY; 313 314 // Mask 315 jboolean _mask_free; 316 317 // Mask data 318 jint _maskType; 319 jbyte* _mask_byteData; 320 jint _maskOffset; 321 jint _mask_width; 322 jint _mask_height; 323 324 // Paint buffer 325 jint *_paint; 326 size_t _paint_length; 327 328 // Paint transform 329 Transform6 _paint_transform; 330 331 // Gradient transform 332 Transform6 _gradient_transform; 333 Transform6 _gradient_inverse_transform; 334 335 // New-style linear gradient geometry 336 jfloat _lg_mx, _lg_my, _lg_b; // g(x, y) = x*mx + y*my + b 337 338 // Radial gradient geometry 339 jfloat _rg_a00, _rg_a01, _rg_a02, _rg_a10, _rg_a11, _rg_a12; 340 jfloat _rg_cx, _rg_cy, _rg_fx, _rg_fy, _rg_r, _rg_rsq; 341 jfloat _rg_a00a00, _rg_a10a10, _rg_a00a10; 342 343 // Gradient color map 344 jint _gradient_colors[GRADIENT_MAP_SIZE]; 345 jint _gradient_cycleMethod; 346 347 // Texture paint 348 jint* _texture_intData; 349 350 //hint to image rendering 351 jboolean _texture_hasAlpha; 352 353 // 565 convenience alternative to _texture_intData 354 jbyte* _texture_byteData; 355 jbyte* _texture_alphaData; 356 357 jint _texture_renderMode; 358 jint _texture_imageWidth; 359 jint _texture_imageHeight; 360 jint _texture_stride; 361 jint _texture_txMin, _texture_tyMin; 362 jint _texture_txMax, _texture_tyMax; 363 jboolean _texture_repeat; 364 jlong _texture_m00, _texture_m01, _texture_m02; 365 jlong _texture_m10, _texture_m11, _texture_m12; 366 // if XNI_TRUE, then we use linear interpolation for result pixel value calc. 367 // otherwise nearest neighbour value is used 368 jboolean _texture_interpolate; 369 jint _texture_transformType; 370 371 jboolean _texture_free; 372 373 // Current bounding box for all primitives 374 jint _clip_bbMinX; 375 jint _clip_bbMinY; 376 jint _clip_bbMaxX; 377 jint _clip_bbMaxY; 378 379 jint _el_lfrac, _el_rfrac; 380 381 jint _rendererState; 382 383 } 384 Renderer; 385 386 #define INVALIDATE_RENDERER_SURFACE(rdr) \ 387 (rdr)->_rendererState |= INVALID_RENDERER_SURFACE; 388 389 #endif